void btn_remove_complete_Click(object sender, RoutedEventArgs e)
        {
            var list = SelectedSongs.ToArray();

            Task.Run(() =>
            {
                SongViewModel.CanSave = false;
                foreach (var item in list)
                {
                    try
                    {
                        File.Delete(item.Song.FilePath);
                        File.Delete(Path.Combine(Global.BasePath, "cache", item.Id + ".mp3"));
                    }
                    catch
                    {
                    }
                    Remove(item);
                    SongViewModel.Remove(item.Id);
                }
                try
                {
                    PersistHelper.Delete(list.Select(x => x.Song).ToArray());
                }
                catch (Exception ex)
                {
                    Jean_Doe.Common.Logger.Error(ex);
                }
                SongViewModel.CanSave = true;
            });
        }
示例#2
0
 public virtual void Remove(SongViewModel song)
 {
     UIHelper.RunOnUI(() =>
     {
         items.Remove(song);
     });
 }
 public void Remove(SongViewModel song)
 {
     UIHelper.RunOnUI(() =>
     {
         items.Remove(song);
     });
 }
示例#4
0
 public virtual void Add(SongViewModel song)
 {
     UIHelper.RunOnUI(new Action(() =>
     {
         items.Add(song);
     }));
 }
        private MusicViewModel createViewModel(IMusic music, bool toFront)
        {
            MusicViewModel s = null;

            switch (music.Type)
            {
            case EnumMusicType.album:
                s = new AlbumViewModel(music as Album);
                break;

            case EnumMusicType.artist:
                s = new ArtistViewModel(music as Artist);
                break;

            case EnumMusicType.collect:
                s = new CollectViewModel(music as Collection);
                break;

            default:
                s = SongViewModel.Get(music as Song);
                break;
            }

            return(s);
        }
 public void Remove(SongViewModel song)
 {
     Dispatcher.Invoke(new Action(() =>
     {
         items.Remove(song);
     }));
 }
 public virtual void Add(SongViewModel song)
 {
     Dispatcher.Invoke(new Action(() =>
     {
         items.Add(song);
     }));
 }
示例#8
0
 public virtual void Insert(int index, SongViewModel song)
 {
     UIHelper.RunOnUI(new Action(() =>
     {
         items.Insert(index, song);
     }));
 }
 public virtual void Add(SongViewModel song)
 {
     Dispatcher.Invoke(new Action(() =>
     {
         items.Add(song);
     }));
 }
 public void Remove(SongViewModel song)
 {
     Dispatcher.Invoke(new Action(() =>
     {
         items.Remove(song);
     }));
 }
 public virtual void Add(SongViewModel song)
 {
     UIHelper.RunOnUI(new Action(() =>
     {
         items.Add(song);
     }));
 }
 public virtual void Insert(int index, SongViewModel song)
 {
     UIHelper.RunOnUI(new Action(() =>
     {
         items.Insert(index, song);
     }));
 }
示例#13
0
        public static void PrepareDownload(SongViewModel item)
        {
            var nameBase = System.IO.Path.Combine(Global.BasePath, "cache", item.Id);

            if (!item.HasMp3)
            {
                var mp3 = nameBase + ".mp3";
                var d   = new DownloaderMp3
                {
                    Info = new DownloaderInfo
                    {
                        Id       = "mp3" + item.Id,
                        FileName = mp3,
                        Entity   = item,
                        Tag      = item.Id,
                    }
                };
                DownloadManager.Instance.Add(d);
            }
            if (!item.HasLrc)
            {
                var lrc = nameBase + ".lrc";
                var d   = new DownloaderLrc
                {
                    Info = new DownloaderInfo
                    {
                        Id       = "lrc" + item.Id,
                        FileName = lrc,
                        Tag      = item.Id,
                        Entity   = item
                    }
                };
                DownloadManager.Instance.Add(d);
            }
            if (!item.HasArt)
            {
                var art = System.IO.Path.Combine(
                    Global.BasePath, "cache",
                    item.AlbumId + ".art");
                var d = new DownloaderArt
                {
                    Info = new DownloaderInfo
                    {
                        Id       = "art" + item.AlbumId,
                        FileName = art,
                        Entity   = item,
                        Tag      = item.Id,
                    }
                };
                var first = DownloadManager.Instance.GetDownloader(d.Info.Id) as DownloaderArt;
                if (first == null)
                {
                    DownloadManager.Instance.Add(d);
                }
                else
                {
                    first.ArtDownloaded += d.HandleDownloaded;
                }
            }
        }
示例#14
0
 public static bool Contains(SongViewModel s)
 {
     if (s == null || string.IsNullOrEmpty(s.Id))
     {
         return(false);
     }
     return(instance.playlist.Any(x => x.Id == s.Id));
 }
示例#15
0
 public static void RequestSave(SongViewModel s)
 {
     if (!isLoaded)
     {
         return;
     }
     PersistHelper.Save(new[] { s.Song });
 }
 public static void PrepareDownload(SongViewModel item)
 {
     var nameBase = System.IO.Path.Combine(Global.BasePath, "cache", item.Id);
     if (!item.HasMp3)
     {
         var mp3 = nameBase + ".mp3";
         var d = new DownloaderMp3
         {
             Info = new DownloaderInfo
             {
                 Id = "mp3" + item.Id,
                 FileName = mp3,
                 Entity = item,
                 Tag = item.Id,
             }
         };
         DownloadManager.Instance.Add(d);
     }
     if (!item.HasLrc)
     {
         var lrc = nameBase + ".lrc";
         var d = new DownloaderLrc
         {
             Info = new DownloaderInfo
             {
                 Id = "lrc" + item.Id,
                 FileName = lrc,
                 Tag = item.Id,
                 Entity = item
             }
         };
         DownloadManager.Instance.Add(d);
     }
     if (!item.HasArt)
     {
         var art = System.IO.Path.Combine(
             Global.BasePath, "cache",
             item.AlbumId + ".art");
         var d = new DownloaderArt
         {
             Info = new DownloaderInfo
             {
                 Id = "art" + item.AlbumId,
                 FileName = art,
                 Entity = item,
                 Tag = item.Id,
             }
         };
         var first = DownloadManager.Instance.GetDownloader(d.Info.Id) as DownloaderArt;
         if (first == null)
             DownloadManager.Instance.Add(d);
         else
         {
             first.ArtDownloaded += d.HandleDownloaded;
         }
     }
 }
示例#17
0
        public void Handle(MsgSetDescription message)
        {
            var svm = SongViewModel.GetId(message.Id);

            if (svm == null)
            {
                return;
            }
            svm.Description = message.Description;
        }
示例#18
0
        void OnMp3PlayerSongChanged(object sender, SongChangedEventArgs e)
        {
            source.Clear();
            SongViewModel svm = SongViewModel.GetId(e.Id);

            if (svm == null)
            {
                return;
            }
            var lrcPath = Path.Combine(Global.AppSettings["DownloadFolder"], svm.FileNameBase + ".lrc");

            if (!File.Exists(lrcPath))
            {
                lrcPath = Path.Combine(Global.BasePath, "cache", e.Id + ".lrc");
            }
            if (!File.Exists(lrcPath))
            {
                Task.Run(async() =>
                {
                    var url = svm.Song.UrlLrc;
                    if (string.IsNullOrEmpty(url))
                    {
                        var json = await NetAccess.Json(XiamiUrl.url_song, "id", svm.Id);
                        if (json.song != null)
                        {
                            json = json.song;
                        }
                        url = MusicHelper.Get(json, "lyric", "song_lrc");
                        if (string.IsNullOrEmpty(url))
                        {
                            return;
                        }
                    }
                    string lrcText = await Http.Get(url, null);
                    File.WriteAllText(lrcPath, lrcText);
                    var f = LyricViewModel.LoadLrcFile(lrcPath);
                    UIHelper.RunOnUI(() =>
                    {
                        foreach (var item in f)
                        {
                            source.Add(item);
                        }
                        timelist = source.Select(x => x.Time.TotalMilliseconds).ToArray();
                    });
                });
                return;
            }
            var s = LyricViewModel.LoadLrcFile(lrcPath);

            foreach (var item in s)
            {
                source.Add(item);
            }
            timelist = source.Select(x => x.Time.TotalMilliseconds).ToArray();
        }
示例#19
0
        public void AddAndStart(SongViewModel song)
        {
            Items.Add(song);
            var hasWork = DownloadManager.Instance.StartByTag(new string[] { song.Id });

            if (!hasWork)
            {
                MessageBus.Instance.Publish(new MsgDownloadStateChanged {
                    Id = song.Id, Item = song, State = EnumDownloadState.Success
                });
            }
        }
        public void Handle(MsgDownloadStateChanged message)
        {
            var item = message.Item as SongViewModel;

            if (item == null || !item.HasMp3)
            {
                return;
            }
            item.Song.DownloadState = "complete";
            SongViewModel.RequestSave(item);
            Items.AddItems(new List <IMusic> {
                item.Song
            }, true);
        }
示例#21
0
        public void Handle(MsgRequestNextSong message)
        {
            if (SongViewModel.All.Count() == 0)
            {
                return;
            }
            if (playlist.Count == 0)
            {
                Refresh(SongViewModel.All.Where(x => x.Song.DownloadState == "complete"));
            }
            SongViewModel item = null;
            var           now  = SongViewModel.NowPlaying ?? SongViewModel.All.FirstOrDefault();
            var           mode = EnumPlayNextMode.Random;

            Enum.TryParse(Global.AppSettings["PlayNextMode"], out mode);
            switch (mode)
            {
            case EnumPlayNextMode.Sequential:
            case EnumPlayNextMode.Random:
                int i = playlist.IndexOf(now);
                if (i == -1)
                {
                    i = playlist.Count - 1;
                }
                i    = i == playlist.Count - 1 ? 0 : i + 1;
                item = playlist.ElementAt(i);
                break;

            case EnumPlayNextMode.Repeat:
                item = now;
                Mp3Player.CurrentTime = 0.0;
                break;

            default:
                break;
            }
            if (item == null)
            {
                return;
            }
            message.Next = item.Song.DownloadState == "complete" ? item.Song.FilePath : item.Song.UrlMp3;
            message.Id   = item.Id;
        }
示例#22
0
        public static SongViewModel Get(Song song)
        {
            var id = song.Id;

            if (!cache.ContainsKey(id))
            {
                cache[id] = new SongViewModel(song);
                isDirty   = true;
            }
            if (song.InFav)
            {
                cache[id].InFav = true;
            }
            if (!string.IsNullOrEmpty(song.Description))
            {
                cache[id].Description = song.Description;
            }
            return(cache[id]);
        }
示例#23
0
 public static SongViewModel Get(Song song)
 {
     var id = song.Id;
     if (!cache.ContainsKey(id))
     {
         cache[id] = new SongViewModel(song);
         isDirty = true;
     }
     if (song.InFav)
     {
         cache[id].InFav = true;
     }
     if (!string.IsNullOrEmpty(song.Description))
     {
         cache[id].Description = song.Description;
     }
     return cache[id];
 }
 public override void Add(SongViewModel song)
 {
     base.Add(song);
     PrepareDownload(song);
 }
示例#25
0
        public static void PrepareDownload(this SongViewModel item)
        {
            var nameBase = Path.Combine(Global.BasePath, "cache", item.Id);

            //if (!item.HasArt)
            //{
            //    var art = Path.Combine(
            //           Global.BasePath, "cache",
            //           item.AlbumId + ".art");
            //    if (File.Exists(art))
            //    {
            //        item.ImageSource = art;
            //        item.HasArt = true;
            //    }
            //    else
            //    {
            //        AfterDownloadManager.Register("art" + item.AlbumId, x =>
            //        {
            //            item.ImageSource = x;
            //            item.HasArt = true;
            //        });
            //        if (DownloadManager.Instance.GetById("art" + item.AlbumId) == null)
            //        {

            //            var d = new DownloaderArt
            //            {
            //                Info = new DownloaderInfo
            //                {
            //                    Id = "art" + item.AlbumId,
            //                    FileName = art,
            //                    Entity = item,
            //                    Tag = item.Id,
            //                    Priority = 2,
            //                    Url = item.UrlArt.Replace("_1.jpg",".jpg")
            //                }
            //            };
            //            DownloadManager.Instance.Add(d);
            //        }
            //    }
            //}
            if (!item.HasMp3)
            {
                var mp3 = nameBase + ".mp3";
                var d   = new DownloaderMp3
                {
                    Info = new DownloaderInfo
                    {
                        Id       = "mp3" + item.Id,
                        FileName = mp3,
                        Entity   = item,
                        Tag      = item.Id,
                        Priority = 1,
                        Url      = item.UrlMp3,
                    }
                };
                DownloadManager.Instance.Add(d);
            }
            if (!item.HasLrc)
            {
                var lrc = nameBase + ".lrc";
                var d   = new DownloaderLrc
                {
                    Info = new DownloaderInfo
                    {
                        Id       = "lrc" + item.Id,
                        FileName = lrc,
                        Tag      = item.Id,
                        Entity   = item,
                        Url      = item.UrlLrc,
                        Priority = 0,
                    }
                };
                DownloadManager.Instance.Add(d);
            }
        }
        void btn_import_click(object sender, RoutedEventArgs e)
        {
            var dir = Global.AppSettings["DownloadFolder"];

            Task.Run(async() =>
            {
                var buffer       = new List <IMusic>();
                int bufferLength = 10;
                var mp3s         = Directory.EnumerateFiles(dir, "*.mp3").ToArray();
                foreach (var item in mp3s)
                {
                    try
                    {
                        var mp3  = TagLib.File.Create(item);
                        var tags = mp3.Tag;
                        if (tags.Comment == null)
                        {
                            continue;
                        }
                        var id       = "";
                        var artistid = "";
                        var albumid  = "";
                        var logo     = "";
                        var m        = reg_ids.Match(tags.Comment);
                        if (!m.Success)
                        {
                            m = reg.Match(tags.Comment);
                            if (!m.Success)
                            {
                                continue;
                            }
                            id           = m.Groups[1].Value;
                            var obj      = await NetAccess.Json(XiamiUrl.url_song, "id", id);
                            artistid     = MusicHelper.Get(obj["song"], "artist_id");
                            albumid      = MusicHelper.Get(obj["song"], "album_id");
                            logo         = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo"));
                            tags.Comment = string.Join(" ", new[] { id, artistid, albumid });
                            mp3.Save();
                        }
                        else
                        {
                            id       = m.Groups[1].Value;
                            artistid = m.Groups[2].Value;
                            albumid  = m.Groups[3].Value;
                        }
                        var art = System.IO.Path.Combine(Global.BasePath, "cache", albumid + ".art");
                        if (!File.Exists(art))
                        {
                            if (string.IsNullOrEmpty(logo))
                            {
                                var obj = await NetAccess.Json(XiamiUrl.url_song, "id", id);
                                logo    = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo"));
                            }
                            await new System.Net.WebClient().DownloadFileTaskAsync(logo, art);
                        }
                        var song = new Song
                        {
                            Id         = id,
                            ArtistId   = artistid,
                            AlbumId    = albumid,
                            Name       = tags.Title,
                            ArtistName = tags.FirstPerformer,
                            AlbumName  = tags.Album,
                            FilePath   = item,
                            Logo       = logo,
                        };
                        buffer.Add(song);
                    }
                    catch
                    {
                    }
                    if (buffer.Count == bufferLength)
                    {
                        var songs = new List <IMusic>();
                        foreach (var s in buffer.OfType <Song>())
                        {
                            SongViewModel.Get(s).HasMp3 = true;
                        }
                        songs.AddRange(buffer);
                        Items.AddItems(songs);
                        buffer.Clear();
                    }
                }
                if (buffer.Count > 0)
                {
                    foreach (var s in buffer.OfType <Song>())
                    {
                        SongViewModel.Get(s).HasMp3 = true;
                    }
                    Items.AddItems(buffer);
                }
            });
        }
示例#27
0
 public static void RequestSave(SongViewModel s)
 {
     if (!isLoaded) return;
     PersistHelper.Save(new[] { s.Song });
 }
示例#28
0
 public override void Add(SongViewModel song)
 {
     base.Add(song);
     PrepareDownload(song);
 }