コード例 #1
0
ファイル: FileService.cs プロジェクト: accuratecopy/Dopamine
        private async Task ImportFiles()
        {
            var tracks = new List <TrackInfo>();

            await Task.Run(() =>
            {
                lock (this.lockObject)
                {
                    // Sort the files alphabetically
                    this.files.Sort();

                    // Convert the files to tracks
                    foreach (string path in this.files)
                    {
                        if (FileFormats.IsSupportedAudioFile(path))
                        {
                            // The file is a supported audio format: add it directly.
                            tracks.Add(IndexerUtils.Path2TrackInfo(path, "file-" + this.instanceGuid));
                        }
                        else if (FileFormats.IsSupportedPlaylistFile(path))
                        {
                            // The file is a supported playlist format: process the contents of the playlist file.
                            List <string> audioFilePaths = this.ProcessPlaylistFile(path);

                            foreach (string audioFilePath in audioFilePaths)
                            {
                                tracks.Add(IndexerUtils.Path2TrackInfo(audioFilePath, "file-" + this.instanceGuid));
                            }
                        }
                        else if (Directory.Exists(path))
                        {
                            // The file is a directory: get the audio files in that directory.
                            List <string> audioFilePaths = this.ProcessDirectory(path);

                            foreach (string audioFilePath in audioFilePaths)
                            {
                                tracks.Add(IndexerUtils.Path2TrackInfo(audioFilePath, "file-" + this.instanceGuid));
                            }
                        }
                        else
                        {
                            // The file is unknown: do not process it.
                        }
                    }

                    // When done importing files, clear the list.
                    this.files.Clear();
                }
            });

            LogClient.Instance.Logger.Info("Number of tracks to play = {0}", tracks.Count);

            if (tracks.Count > 0)
            {
                LogClient.Instance.Logger.Info("Enqueuing {0} tracks.", tracks.Count);
                await this.playbackService.Enqueue(tracks);
            }
        }
コード例 #2
0
        public async Task <List <PlayableTrack> > ProcessFilesAsync(List <string> filenames)
        {
            var tracks = new List <PlayableTrack>();

            await Task.Run(async() =>
            {
                if (filenames == null)
                {
                    return;
                }

                // Convert the files to tracks
                foreach (string path in filenames)
                {
                    if (FileFormats.IsSupportedAudioFile(path))
                    {
                        // The file is a supported audio format: add it directly.
                        tracks.Add(await this.CreateTrackAsync(path));
                    }
                    else if (FileFormats.IsSupportedPlaylistFile(path))
                    {
                        // The file is a supported playlist format: process the contents of the playlist file.
                        List <string> audioFilePaths = this.ProcessPlaylistFile(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else if (Directory.Exists(path))
                    {
                        // The file is a directory: get the audio files in that directory.
                        List <string> audioFilePaths = this.ProcessDirectory(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else
                    {
                        // The file is unknown: do not process it.
                    }
                }
            });

            return(tracks);
        }
コード例 #3
0
        private async Task AddDroppedFilesToPlaylists(IDropInfo dropInfo)
        {
            // 3 possibilities
            if (dropInfo.TargetItem is PlaylistViewModel)
            {
                // 1. Drop audio and playlist files on a playlist name: add all files
                // (including those in the dropped playlist files) to that playlist.
                try
                {
                    PlaylistViewModel      hoveredPlaylist = (PlaylistViewModel)dropInfo.TargetItem;
                    IList <string>         filenames       = dropInfo.GetDroppedFilenames();
                    IList <TrackViewModel> tracks          = await this.fileService.ProcessFilesAsync(filenames);

                    if (hoveredPlaylist != null && tracks != null)
                    {
                        await this.playlistService.AddTracksToPlaylistAsync(tracks, hoveredPlaylist.Name);
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not add dropped files to hovered playlist. Exception: {0}", ex.Message);
                }
            }
            else if (dropInfo.TargetItem == null)
            {
                string uniquePlaylistName = await this.playlistService.GetUniquePlaylistAsync(ResourceUtils.GetString("Language_New_Playlist"));

                IList <string> allFilenames      = dropInfo.GetDroppedFilenames();
                IList <string> audioFileNames    = allFilenames.Select(f => f).Where(f => FileFormats.IsSupportedAudioFile(f)).ToList();
                IList <string> playlistFileNames = allFilenames.Select(f => f).Where(f => FileFormats.IsSupportedPlaylistFile(f)).ToList();

                // 2. Drop audio files in empty part of list: add these files to a new unique playlist
                IList <TrackViewModel> audiofileTracks = await this.fileService.ProcessFilesAsync(audioFileNames);

                if (audiofileTracks != null && audiofileTracks.Count > 0)
                {
                    await this.playlistService.AddPlaylistAsync(uniquePlaylistName);

                    await this.playlistService.AddTracksToPlaylistAsync(audiofileTracks, uniquePlaylistName);
                }

                // 3. Drop playlist files in empty part of list: add the playlist with a unique name
                foreach (string playlistFileName in playlistFileNames)
                {
                    uniquePlaylistName = await this.playlistService.GetUniquePlaylistAsync(System.IO.Path.GetFileNameWithoutExtension(playlistFileName));

                    IList <TrackViewModel> playlistFileTracks = await this.fileService.ProcessFilesAsync(new string[] { playlistFileName }.ToList());

                    await this.playlistService.AddPlaylistAsync(uniquePlaylistName);

                    await this.playlistService.AddTracksToPlaylistAsync(playlistFileTracks, uniquePlaylistName);
                }
            }
        }
コード例 #4
0
        public async Task <List <PlayableTrack> > ProcessFilesAsync(List <string> filenames)
        {
            var tracks = new List <PlayableTrack>();

            await Task.Run(async() =>
            {
                if (filenames == null)
                {
                    return;
                }

                // Convert the files to tracks
                foreach (string path in filenames)
                {
                    if (FileFormats.IsSupportedAudioFile(path))
                    {
                        // The file is a supported audio format: add it directly.
                        tracks.Add(await this.CreateTrackAsync(path));

                        if (SettingsClient.Get <bool>("Behaviour", "EnqueueOtherFilesInFolder"))
                        {
                            // Get all files in that directory
                            List <string> audioFilePaths = this.ProcessDirectory(Path.GetDirectoryName(path));

                            // Add all files from that directory
                            foreach (string audioFilePath in audioFilePaths)
                            {
                                if (!audioFilePath.Equals(path))
                                {
                                    tracks.Add(await this.CreateTrackAsync(audioFilePath));
                                }
                            }
                        }
                    }
                    else if (FileFormats.IsSupportedPlaylistFile(path))
                    {
                        // The file is a supported playlist format: process the contents of the playlist file.
                        List <string> audioFilePaths = this.ProcessPlaylistFile(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else if (Directory.Exists(path))
                    {
                        // The file is a directory: get the audio files in that directory.
                        List <string> audioFilePaths = this.ProcessDirectory(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else
                    {
                        // The file is unknown: do not process it.
                    }
                }
            });

            return(tracks);
        }
コード例 #5
0
ファイル: FileService.cs プロジェクト: DJJonnyFeeke/Dopamine
        private async Task ImportFilesAsync()
        {
            var tracks = new List <PlayableTrack>();

            await Task.Run(async() =>
            {
                List <string> tempFiles = null;

                lock (this.lockObject)
                {
                    tempFiles = (List <string>) this.files.Clone();
                    this.files.Clear(); // Clear the list
                }

                tempFiles.Sort(); // Sort the files alphabetically

                if (tempFiles == null)
                {
                    return;
                }

                // Convert the files to tracks
                foreach (string path in tempFiles)
                {
                    if (FileFormats.IsSupportedAudioFile(path))
                    {
                        // The file is a supported audio format: add it directly.
                        tracks.Add(await this.CreateTrackAsync(path));
                    }
                    else if (FileFormats.IsSupportedPlaylistFile(path))
                    {
                        // The file is a supported playlist format: process the contents of the playlist file.
                        List <string> audioFilePaths = this.ProcessPlaylistFile(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else if (Directory.Exists(path))
                    {
                        // The file is a directory: get the audio files in that directory.
                        List <string> audioFilePaths = this.ProcessDirectory(path);

                        foreach (string audioFilePath in audioFilePaths)
                        {
                            tracks.Add(await this.CreateTrackAsync(audioFilePath));
                        }
                    }
                    else
                    {
                        // The file is unknown: do not process it.
                    }
                }
            });

            LogClient.Info("Number of tracks to play = {0}", tracks.Count.ToString());

            if (tracks.Count > 0)
            {
                LogClient.Info("Enqueuing {0} tracks.", tracks.Count.ToString());
                this.TracksImported(tracks);
            }
        }