Exemplo n.º 1
0
 public static async Task<List<ArtistItem>> GetFollowingArtistViaSimilarity(ArtistItem currentArtist)
 {
     await App.MusicMetaService.GetSimilarArtists(currentArtist);
     if (currentArtist.OnlineRelatedArtists == null || !currentArtist.OnlineRelatedArtists.Any())
         return null; // no more similar artists
     var artistsInCollection = InCollection(currentArtist.OnlineRelatedArtists.Select(x => x.Name).ToList());
     return artistsInCollection;
 }
Exemplo n.º 2
0
 private async Task<ArtistItem> GetFollowingArtist(ArtistItem currentArtist)
 {
     // similarity
     var t = await GetFollowingArtistViaSimilarity(currentArtist);
     // music genre
     //var artistItems = await GetFollowingArtistViaGenre(currentArtist);
     // years, decades
     return null;
 }
Exemplo n.º 3
0
 public async Task GetArtistBiography(ArtistItem artist)
 {
     var bio = await musicMdFetcher.GetArtistBiography(artist.Name);
     if (bio == null) return;
     await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         artist.Biography = bio;
     });
 }
Exemplo n.º 4
0
 public async Task GetPopularAlbums(ArtistItem artist)
 {
     var albums = await musicMdFetcher.GetArtistTopAlbums(artist.Name);
     if (albums == null) return;
     await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         artist.IsOnlinePopularAlbumItemsLoaded = true;
         artist.OnlinePopularAlbumItems = albums;
     });
 }
Exemplo n.º 5
0
 public async Task GetSimilarArtists(ArtistItem artist)
 {
     var artists = await musicMdFetcher.GetArtistSimilarsArtist(artist.Name);
     if (artists == null) return;
     await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         artist.IsOnlineRelatedArtistsLoaded = true;
         artist.OnlineRelatedArtists = artists;
     });
 }
Exemplo n.º 6
0
 public static async Task FetchArtistPicOrWaitAsync(ArtistItem artistItem)
 {
     await ArtistPicFetcherSemaphoreSlim.WaitAsync();
     try
     {
         await artistItem.LoadPicture();
     }
     finally
     {
         ArtistPicFetcherSemaphoreSlim.Release();
     }
 }
Exemplo n.º 7
0
 private async Task<List<ArtistItem>> GetFollowingArtistViaGenre(ArtistItem currentArtist)
 {
     //            if (currentArtist.Genre == null)
     //#if DEBUG
     //                currentArtist.Genre = "Rock";
     //#else 
     return null;
     //#endif
     //            var artists = await App.MusicMetaService.GetTopArtistGenre(currentArtist.Genre);
     //            if (artists == null || !artists.Any()) return null;
     //            var artistsInCollection = InCollection(artists.Select(x => x.Name).ToList());
     //            return artistsInCollection;
 }
Exemplo n.º 8
0
 public async Task<bool> GetArtistPicture(ArtistItem artist)
 {
     if (Locator.MainVM.IsInternet && !string.IsNullOrEmpty(artist.Name))
     {
         var bytes = await musicMdFetcher.GetArtistPicture(artist.Name);
         if (bytes == null)
         {
             // TODO: Add a TriedWithNoSuccess flag in DB
         }
         var success = bytes != null && await SaveArtistImageAsync(artist, bytes);
         if (success)
         {
             await Locator.MusicLibraryVM._artistDatabase.Update(artist);
             return true;
         }
     }
     return false;
 }
        public static async Task LoadImageToMemory(ArtistItem item)
        {
            /*
            Normally, We would need more tight calls to try and make sure that the file
            exists in our database. However, since this is on the UI thread, we can't do that.
            Since binding images directly through XAML leads to blocked files when we
            need to delete them, we have to load them up manually. This should be enough
            of a check, for now, to make sure images load correctly.
            */
            bool fileExists = item.IsPictureLoaded;
            try
            {
                if (fileExists)
                {
                    var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(item.Picture));
                    using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            var image = new BitmapImage();
                            image.SetSource(stream);
                            item.ArtistImage = image;
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log("Error getting artist picture : " + item.Name);
            }

            // Failed to get the artist image or no cover image. So go online and check
            // for a new one.
            if (!fileExists)
                await MusicLibraryManagement.FetchArtistPicOrWaitAsync(item);
        }
Exemplo n.º 10
0
 public Task Remove(ArtistItem artist)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.DeleteAsync(artist);
 }
Exemplo n.º 11
0
 public Task Add(ArtistItem artist)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.InsertAsync(artist);
 }
Exemplo n.º 12
0
 public Task Update(ArtistItem artist)
 {
     var connection = new SQLiteAsyncConnection(DbPath);
     return connection.UpdateAsync(artist);
 }
Exemplo n.º 13
0
 public async Task<bool> SaveArtistImageAsync(ArtistItem artist, byte[] img)
 {
     if (await SaveImage(artist.Id, "artistPic", img))
     {
         await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => artist.IsPictureLoaded = true);
         await artist.ResetArtistHeader();
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 public static void AddArtist(ArtistItem artist)
 {
     Locator.MusicLibraryVM.Artists.Add(artist);
 }
Exemplo n.º 15
0
        private static async Task CreateDatabaseFromMusicFile(StorageFile item)
        {
            try
            {
                if (!VLCFileExtensions.AudioExtensions.Contains(item.FileType.ToLower())) return;
                var media = Locator.VLCService.GetMediaFromPath(item.Path);
                MediaProperties mP = Locator.VLCService.GetMusicProperties(media);
                if(mP == null)
                {
                    var props = await item.Properties.GetMusicPropertiesAsync();
                    mP = new MediaProperties()
                    {
                        Album = props.Album,
                        AlbumArtist = props.AlbumArtist,
                        Artist = props.Artist,
                        Title = props.Title,
                        Tracknumber = props.TrackNumber,
                        Genre = (props.Genre != null && props.Genre.Any()) ? props.Genre[0] : null,
                    };
                }
                if (mP != null)
                {
                    var artistName = mP.Artist;
                    var albumArtistName = mP.AlbumArtist;
                    ArtistItem artist = Locator.MusicLibraryVM._artistDatabase.LoadViaArtistName(string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName);
                    if (artist == null)
                    {
                        artist = new ArtistItem();
                        artist.Name = string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName;
                        await Locator.MusicLibraryVM._artistDatabase.Add(artist);
                        await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            AddArtist(artist);
                        });
                    }

                    var albumName = mP.Album;
                    var albumYear = mP.Year;
                    AlbumItem album = await Locator.MusicLibraryVM._albumDatabase.LoadAlbumViaName(artist.Id, albumName);
                    if (album == null)
                    {
                        var albumUrl = Locator.VLCService.GetAlbumUrl(media);
                        var hasVLCFoundCover = false;
                        if (!string.IsNullOrEmpty(albumUrl) && albumUrl.StartsWith("file://"))
                        {
                            // The Uri will be like
                            // ms-appdata:///local/vlc/art/artistalbum/30 Seconds To Mars/B-sides & Rarities/art.jpg
                            hasVLCFoundCover = true;
                        }

                        album = new AlbumItem
                        {
                            Name = string.IsNullOrEmpty(albumName) ? string.Empty : albumName,
                            AlbumArtist = albumArtistName,
                            Artist = string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName,
                            ArtistId = artist.Id,
                            Favorite = false,
                            Year = albumYear,
                            IsPictureLoaded = hasVLCFoundCover,
                            IsVLCCover = hasVLCFoundCover,
                        };
                        await Locator.MusicLibraryVM._albumDatabase.Add(album);
                        await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                        {
                            var artistFromCollection = Locator.MusicLibraryVM.Artists.FirstOrDefault(x => x.Id == album.ArtistId);
                            AddAlbum(album, artistFromCollection);
                            Locator.MainVM.InformationText = string.Format(Strings.AlbumsFound, Locator.MusicLibraryVM.Albums.Count);
                        });
                    }

                    TrackItem track = new TrackItem
                    {
                        AlbumId = album.Id,
                        AlbumName = album.Name,
                        ArtistId = artist.Id,
                        ArtistName = artistName,
                        CurrentPosition = 0,
                        Duration = mP.Duration,
                        Favorite = false,
                        Name = string.IsNullOrEmpty(mP.Title) ? item.DisplayName : mP.Title,
                        Path = item.Path,
                        Index = mP.Tracknumber,
                        DiscNumber = mP.DiscNumber,
                    };
                    await Locator.MusicLibraryVM._trackDatabase.Add(track);
                    await App.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => AddTrack(track));
                }
            }
            catch (Exception e)
            {
                ExceptionHelper.CreateMemorizedException("MusicLibraryManagement.CreateDatabaseFromMusicFile", e);
            }
        }
Exemplo n.º 16
0
 public async Task GetArtistEvents(ArtistItem artist)
 {
     var shows = await musicMdFetcher.GetArtistEvents(artist.Name);
     await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         artist.IsUpcomingShowsLoading = false;
         if (shows == null) return; 
         artist.UpcomingShows = shows;
     });
 }
Exemplo n.º 17
0
 public static void AddAlbum(AlbumItem album, ArtistItem artist)
 {
     artist?.Albums.Add(album);
     if (Locator.NavigationService.CurrentPage == VLCPage.MainPageMusic && Locator.MusicLibraryVM.MusicView == MusicView.Albums)
     {
         Task.Run(() => InsertIntoGroupAlbum(album));
     }
     Locator.MusicLibraryVM.Albums.Add(album);
 }
Exemplo n.º 18
0
 public static async void AddArtist(ArtistItem artist)
 {
     Locator.MusicLibraryVM.Artists.Add(artist);
     if (Locator.MusicLibraryVM.Artists.Count < 3)
     {
         await artist.LoadPicture();
         if (artist.IsPictureLoaded)
         {
             Locator.Slideshow.AddImg(artist.Picture);
         }
     }
 }