Esempio n. 1
0
        public void LoadCameraRollFromDatabase()
        {
            CameraRoll.Clear();
            var camVideos = LoadVideos(x => x.IsCameraRoll);
            var newVideos = camVideos.OrderBy(x => x.Name);

            foreach (var item in newVideos)
            {
                CameraRoll.Add(item);
            }
        }
Esempio n. 2
0
        async Task <bool> ParseMediaFile(StorageFile item, bool isCameraRoll)
        {
            try
            {
                if (VLCFileExtensions.AudioExtensions.Contains(item.FileType.ToLower()))
                {
                    if (musicDatabase.ContainsTrack(item.Path))
                    {
                        return(true);
                    }

                    // Groove Music puts its cache into this folder in Music.
                    // If the file is in this folder or subfolder, don't add it to the collection,
                    // since we can't play it anyway because of the DRM.
                    if (item.Path.Contains("Music Cache") || item.Path.Contains("Podcast"))
                    {
                        return(false);
                    }

                    var media = await Locator.VLCService.GetMediaFromPath(item.Path);

                    var mP = await Locator.VLCService.GetMusicProperties(media);

                    if (mP == null || (string.IsNullOrEmpty(mP.Artist) && string.IsNullOrEmpty(mP.Album) && (string.IsNullOrEmpty(mP.Title) || mP.Title == item.Name)))
                    {
                        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?.Trim();
                        var        albumArtistName = mP.AlbumArtist?.Trim();
                        ArtistItem artist          = LoadViaArtistName(string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName);
                        if (artist == null)
                        {
                            artist           = new ArtistItem();
                            artist.Name      = string.IsNullOrEmpty(albumArtistName) ? artistName : albumArtistName;
                            artist.PlayCount = 0;
                            musicDatabase.Add(artist);
                            Artists.Add(artist);
                        }

                        var       albumName = mP.Album?.Trim();
                        var       albumYear = mP.Year;
                        AlbumItem album     = musicDatabase.LoadAlbumFromName(artist.Id, albumName);
                        if (album == null)
                        {
                            string albumSimplifiedUrl = null;
                            if (!string.IsNullOrEmpty(mP.AlbumArt) && mP.AlbumArt.StartsWith("file://"))
                            {
                                // The Uri will be like
                                // ms-appdata:///local/vlc/art/artistalbum/30 Seconds To Mars/B-sides & Rarities/art.jpg
                                var indexStart = mP.AlbumArt.IndexOf("vlc/art/artistalbum/", StringComparison.Ordinal);
                                if (indexStart != -1)
                                {
                                    albumSimplifiedUrl = mP.AlbumArt.Substring(indexStart, mP.AlbumArt.Length - indexStart);
                                    Debug.WriteLine("VLC : found album cover with TagLib - " + albumName);
                                }
                            }

                            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,
                                AlbumCoverUri = albumSimplifiedUrl
                            };
                            musicDatabase.Add(album);
                            Albums.Add(album);
                        }

                        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,
                            Genre           = mP.Genre,
                            IsAvailable     = true,
                        };
                        musicDatabase.Add(track);
                        Tracks.Add(track);
                    }
                }
                else if (VLCFileExtensions.VideoExtensions.Contains(item.FileType.ToLower()))
                {
                    if (videoDatabase.DoesMediaExist(item.Path))
                    {
                        return(true);
                    }

                    var video = await MediaLibraryHelper.GetVideoItem(item);

                    if (video.IsTvShow)
                    {
                        await AddTvShow(video);
                    }
                    else if (isCameraRoll)
                    {
                        video.IsCameraRoll = true;
                        CameraRoll.Add(video);
                    }
                    else
                    {
                        Videos.Add(video);
                    }
                    videoDatabase.Insert(video);
                }
                else
                {
                    Debug.WriteLine($"{item.Path} is not a media file");
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(true);
        }