예제 #1
0
        public static TrackVM FromTrack(Track t, AppService app, bool withLyrics = false)
        {
            var vm = new TrackVM {
                id          = t.id,
                name        = t.name,
                artist      = t.artist,
                album       = t.album,
                albumArtist = t.albumArtist,
                url         = t.url,
                size        = t.size,
                length      = t.length,
                owner       = t.owner,
                visibility  = t.visibility,
                lyrics      = string.IsNullOrEmpty(t.lyrics) ? "" : withLyrics ? t.lyrics : null,
                groupId     = t.groupId,
                version     = t.version
            };

            if (app.Config.Converters?.Count > 0 || t.files?.Count > 0)
            {
                var origBitrate = (int)(t.length > 0 ? t.size / t.length / 128 : 0);
                vm.files = new List <TrackFileVM>();
                if (t.files != null)
                {
                    foreach (var item in t.files)
                    {
                        vm.files.Add(new TrackFileVM(item));
                    }
                }
                if (app.Config.Converters != null)
                {
                    foreach (var item in app.Config.Converters)
                    {
                        if (origBitrate / 2 < item.Bitrate)
                        {
                            continue;
                        }
                        if (t.files?.Any(x => x.ConvName == item.Name) == true)
                        {
                            continue;
                        }
                        vm.files.Add(new TrackFileVM {
                            bitrate = item.Bitrate,
                            format  = item.Format,
                            profile = item.Name,
                            size    = -1
                        });
                    }
                }
            }
            return(vm);
        }
예제 #2
0
 public IEnumerable <TrackVM> GetTrackVMs(IEnumerable <int> trackids)
 {
     return(GetTracks(trackids).Select(x => TrackVM.FromTrack(x, App, false)));
 }