public void should_use_file_name_for_source_title_if_scene_name_is_null() { var artist = Builder <Artist> .CreateNew().Build(); var tracks = Builder <Track> .CreateListOfSize(1).Build().ToList(); var trackFile = Builder <TrackFile> .CreateNew() .With(f => f.SceneName = null) .With(f => f.Artist = artist) .Build(); var localTrack = new LocalTrack { Artist = artist, Album = new Album(), Tracks = tracks, Path = @"C:\Test\Unsorted\Artist.01.Hymn.mp3" }; var downloadClientItem = new DownloadClientItem { DownloadClientInfo = new DownloadClientItemClientInfo { Protocol = DownloadProtocol.Usenet, Id = 1, Name = "sab" }, DownloadId = "abcd" }; Subject.Handle(new TrackImportedEvent(localTrack, trackFile, new List <TrackFile>(), true, downloadClientItem)); Mocker.GetMock <IHistoryRepository>() .Verify(v => v.Insert(It.Is <History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path)))); }
private SearchResponse GetTrackSearchResults(LocalTrack local_, int limitResultAmout) { SearchResponse searchResponse = new SearchResponse(); if (local_.SearchType == LocalSearchType.FULL_TAGS) { searchResponse = SearchSpotifyForTrack(local_, limitResultAmout); } if (local_.SearchType == LocalSearchType.FILENAME_ONLY) { searchResponse = SearchSpotifyForTrack(local_, limitResultAmout); } if (Properties.Settings.Default.UseFingerprint && local_.SearchType == LocalSearchType.AUDIO_SEARCH) { local_ = GetTagsByFingerprint(local_); if (local_.FingerprintStatus == FingerprintStatus.GOT_RESULT) { local_.SearchType = LocalSearchType.FULL_TAGS; searchResponse = SearchSpotifyForTrack(local_, limitResultAmout); } else if (local_.FingerprintStatus == FingerprintStatus.WEBSERVICE_ERROR) { MessageBox.Show("Something went wrong with the webservice. Are you sure the AcoustID API Key is correct?"); } } return(searchResponse); }
public void should_not_delete_if_there_is_large_rar_file() { GivenValidArtist(); var localTrack = new LocalTrack(); var imported = new List <ImportDecision <LocalTrack> >(); imported.Add(new ImportDecision <LocalTrack>(localTrack)); Mocker.GetMock <IMakeImportDecision>() .Setup(s => s.GetImportDecisions(It.IsAny <List <IFileInfo> >(), It.IsAny <Artist>(), null)) .Returns(imported); Mocker.GetMock <IImportApprovedTracks>() .Setup(s => s.Import(It.IsAny <List <ImportDecision <LocalTrack> > >(), true, null, ImportMode.Auto)) .Returns(imported.Select(i => new ImportResult(i)).ToList()); GivenAudioFiles(new [] { _audioFiles.First().Replace(".ext", ".rar") }, 15.Megabytes()); Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory)); DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue(); ExceptionVerification.ExpectedWarns(1); }
public void should_not_delete_if_no_files_were_imported() { GivenValidArtist(); var localTrack = new LocalTrack(); var imported = new List <ImportDecision <LocalTrack> >(); imported.Add(new ImportDecision <LocalTrack>(localTrack)); Mocker.GetMock <IMakeImportDecision>() .Setup(s => s.GetImportDecisions(It.IsAny <List <IFileInfo> >(), It.IsAny <Artist>(), null)) .Returns(imported); Mocker.GetMock <IImportApprovedTracks>() .Setup(s => s.Import(It.IsAny <List <ImportDecision <LocalTrack> > >(), true, null, ImportMode.Auto)) .Returns(new List <ImportResult>()); Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory)); DiskProvider.FolderExists(_subFolders[0]).Should().BeTrue(); Mocker.GetMock <IDiskProvider>() .Verify(v => v.DeleteFolder(It.IsAny <string>(), true), Times.Never()); }
private ImportDecision <LocalTrack> GetDecision(LocalTrack localTrack, DownloadClientItem downloadClientItem) { ImportDecision <LocalTrack> decision = null; if (localTrack.Tracks.Empty()) { decision = localTrack.Album != null ? new ImportDecision <LocalTrack>(localTrack, new Rejection($"Couldn't parse track from: {localTrack.FileTrackInfo}")) : new ImportDecision <LocalTrack>(localTrack, new Rejection($"Couldn't parse album from: {localTrack.FileTrackInfo}")); } else { var reasons = _trackSpecifications.Select(c => EvaluateSpec(c, localTrack, downloadClientItem)) .Where(c => c != null); decision = new ImportDecision <LocalTrack>(localTrack, reasons.ToArray()); } if (decision == null) { _logger.Error("Unable to make a decision on {0}", localTrack.Path); } else if (decision.Rejections.Any()) { _logger.Debug("File rejected for the following reasons: {0}", string.Join(", ", decision.Rejections)); } else { _logger.Debug("File accepted"); } return(decision); }
public void should_not_delete_folder_if_files_were_imported_and_audio_files_remain() { GivenValidArtist(); var localTrack = new LocalTrack(); var imported = new List <ImportDecision <LocalTrack> >(); imported.Add(new ImportDecision <LocalTrack>(localTrack)); Mocker.GetMock <IMakeImportDecision>() .Setup(s => s.GetImportDecisions(It.IsAny <List <IFileInfo> >(), It.IsAny <Artist>(), null)) .Returns(imported); Mocker.GetMock <IImportApprovedTracks>() .Setup(s => s.Import(It.IsAny <List <ImportDecision <LocalTrack> > >(), true, null, ImportMode.Auto)) .Returns(imported.Select(i => new ImportResult(i)).ToList()); Subject.ProcessRootFolder(DiskProvider.GetDirectoryInfo(_droneFactory)); Mocker.GetMock <IDiskProvider>() .Verify(v => v.DeleteFolder(It.IsAny <string>(), true), Times.Never()); ExceptionVerification.ExpectedWarns(1); }
public async Task AddFiles(EventHandler <TrackImportProgressChangedEventArgs> progresschanged, IEnumerable <string> paths) { var index = 0; var filePaths = paths as IList <string> ?? paths.ToList(); var count = filePaths.Count(); foreach (var fi in filePaths.Select(path => new FileInfo(path))) { if (fi.Exists) { try { progresschanged?.Invoke(this, new TrackImportProgressChangedEventArgs(index, count, fi.Name)); var t = new LocalTrack { Path = fi.FullName }; if (!await t.LoadInformation()) { continue; } t.TimeAdded = DateTime.Now; t.IsChecked = false; AddTrack(t); } catch (Exception) { continue; } } ++index; } AsyncTrackLoader.Instance.RunAsync(this); }
public static bool IsSupported(StreamReader reader) { var line = reader.ReadLine(); if (line == null) { return(false); } line = line.Trim(); if (line == "#EXTM3U") { return(true); } if (line.StartsWith("http")) { return(true); } if (LocalTrack.IsSupported(new FileInfo(line))) { return(true); } return(false); }
public async Task AddFiles(EventHandler <TrackImportProgressChangedEventArgs> progresschanged, IEnumerable <string> paths) { int index = 0; var count = paths.Count(); foreach (FileInfo fi in paths.Select(path => new FileInfo(path))) { if (fi.Exists) { if (progresschanged != null) { progresschanged(this, new TrackImportProgressChangedEventArgs(index, count, fi.Name)); } var t = new LocalTrack() { Path = fi.FullName }; if (!await t.LoadInformation()) { continue; } t.TimeAdded = DateTime.Now; AddTrack(t); } ++index; } AsyncTrackLoader.Instance.RunAsync(new List <NormalPlaylist> { this }); }
public void Setup() { _artist = Builder <Artist> .CreateNew() .With(s => s.Path = @"C:\Test\Music\Artist".AsOsAgnostic()) .Build(); _trackFile = Builder <TrackFile> .CreateNew() .With(f => f.Path = null) .With(f => f.Path = Path.Combine(_artist.Path, @"Album\File.mp3")) .Build(); _localtrack = Builder <LocalTrack> .CreateNew() .With(l => l.Artist = _artist) .With(l => l.Tracks = Builder <Track> .CreateListOfSize(1).Build().ToList()) .Build(); Mocker.GetMock <IBuildFileNames>() .Setup(s => s.BuildTrackFileName(It.IsAny <List <Track> >(), It.IsAny <Artist>(), It.IsAny <Album>(), It.IsAny <TrackFile>(), null, null)) .Returns("Album\\File Name"); Mocker.GetMock <IBuildFileNames>() .Setup(s => s.BuildTrackFilePath(It.IsAny <Artist>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(@"C:\Test\Music\Artist\Album\File Name.mp3".AsOsAgnostic()); var rootFolder = @"C:\Test\Music\".AsOsAgnostic(); Mocker.GetMock <IDiskProvider>() .Setup(s => s.FolderExists(rootFolder)) .Returns(true); Mocker.GetMock <IDiskProvider>() .Setup(s => s.FileExists(It.IsAny <string>())) .Returns(true); }
public void Setup() { _localTrack = new LocalTrack(); _localTrack.Artist = new Artist { Path = rootPath }; _trackFile = Builder <TrackFile> .CreateNew() .Build(); Mocker.GetMock <IDiskProvider>() .Setup(c => c.FileExists(It.IsAny <string>())) .Returns(true); Mocker.GetMock <IDiskProvider>() .Setup(c => c.FolderExists(It.IsAny <string>())) .Returns(true); Mocker.GetMock <IDiskProvider>() .Setup(c => c.GetParentFolder(It.IsAny <string>())) .Returns <string>(c => Path.GetDirectoryName(c)); }
private void VerifyData(LocalTrack track, string artist, string title, int trackNum, int disc) { track.FileTrackInfo.ArtistTitle.Should().Be(artist); track.FileTrackInfo.Title.Should().Be(title); track.FileTrackInfo.TrackNumbers[0].Should().Be(trackNum); track.FileTrackInfo.DiscNumber.Should().Be(disc); }
public LocalTrack Augment(LocalTrack localTrack, bool otherFiles) { if (localTrack.DownloadClientAlbumInfo == null && localTrack.FolderTrackInfo == null && localTrack.FileTrackInfo == null) { if (MediaFileExtensions.Extensions.Contains(Path.GetExtension(localTrack.Path))) { throw new AugmentingFailedException("Unable to parse track info from path: {0}", localTrack.Path); } } localTrack.Size = _diskProvider.GetFileSize(localTrack.Path); foreach (var augmenter in _trackAugmenters) { try { augmenter.Aggregate(localTrack, otherFiles); } catch (Exception ex) { _logger.Warn(ex, ex.Message); } } return(localTrack); }
private void OnPlayFoundTrack(object sender, RoutedEventArgs e) { LocalTrack track = FoundTracks[m_foundDataGrid.SelectedIndex]; m_streamingSystemManager = m_streamingSystemManagers[(int)StreamingSystemType.Spotify]; m_streamingSystemManager.Play(track); CurrentTrack = track; }
/// <summary> /// permet de jouer une piste de Deezer /// </summary> /// <param name="track"></param> /// <returns></returns> public override async Task Play(LocalTrack track) { await Task.Run(() => { var stream = PlayingRoot + track.Id; m_player.LoadStream(stream); m_player.Play(); }); }
private void OnPlayFoundTrack(object sender, RoutedEventArgs e) { LocalTrack track = FoundTracks[m_foundDataGrid.SelectedIndex]; m_streamingSystemManager.Play(track); IsPlaying = true; CurrentTrack = track; }
private void Find_Button_Click(object sender, RoutedEventArgs e) { if (IsFoundListNotEmptyOrProcessed()) { LocalTrack local_ = ListOfLocalTracks.Find(x => x.SpotifyUri == ((FullTrack)found_list.SelectedItem).Id); local_list.SelectedItem = local_; local_list.ScrollIntoView(local_); } }
public TagEditorWindow(LocalTrack track) { this.TagFile = File.Create(track.Path); this.CurrentTrack = track; InitializeComponent(); List <Genre> genres = Genres.Audio.Select(item => new Genre(item, TagFile.Tag.Genres.Contains(item))).ToList(); lstGenre.ItemsSource = genres; }
//search for song in spotify, considers tag state of file// private static void SearchFor(LocalTrack local_, ref SearchItem search_results, int limit) { if (local_.TagState == TagState.FULL_TAGS) { search_results = _spotify.SearchItems(local_.Author + "+" + local_.Title, SpotifyAPI.Web.Enums.SearchType.Track, limit); } else if (local_.TagState == TagState.MISSING_TAG || local_.TagState == TagState.MISSING_TITLE) { search_results = _spotify.SearchItems(local_.File_name, SpotifyAPI.Web.Enums.SearchType.Track, limit); } }
public TrackFile MoveTrackFile(TrackFile trackFile, LocalTrack localTrack) { var newFileName = _buildFileNames.BuildTrackFileName(localTrack.Tracks, localTrack.Artist, localTrack.Album, trackFile); var filePath = _buildFileNames.BuildTrackFilePath(localTrack.Artist, localTrack.Album, newFileName, Path.GetExtension(localTrack.Path)); EnsureTrackFolder(trackFile, localTrack, filePath); _logger.Debug("Moving track file: {0} to {1}", trackFile.Path, filePath); return(TransferFile(trackFile, localTrack.Artist, localTrack.Tracks, filePath, TransferMode.Move)); }
public TrackImportFailedEvent(Exception exception, LocalTrack trackInfo, bool newDownload, DownloadClientItem downloadClientItem) { Exception = exception; TrackInfo = trackInfo; NewDownload = newDownload; if (downloadClientItem != null) { DownloadClient = downloadClientItem.DownloadClientInfo.Name; DownloadId = downloadClientItem.DownloadId; } }
private LocalTrack GetTagsByFingerprint(LocalTrack local_) { try { local_ = Fingerprinting.Fingerprint.LookUp(local_); } catch (InvalidOperationException) { } return(local_); }
public void should_return_permissions_error_on_track_import_failed_event_if_file_exists() { var localTrack = new LocalTrack { Path = Path.Combine(downloadItemPath, "file.mp3") }; GivenFileExists(localTrack.Path); var importEvent = new TrackImportFailedEvent(new Exception(), localTrack, true, new DownloadClientItem()); Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error"); }
private LocalTrack ToLocalTrack(BasicTrack basicTrack) { LocalTrack track = new LocalTrack(); track.Name = basicTrack.Name; track.Album = basicTrack.AlbumName; track.Artist = basicTrack.ArtistName; track.Id = basicTrack.Id.ToString(); track.Duration = (basicTrack.Duration * 10 / 6) / 100.0; track.Type = StreamingSystemType.Jamendo; track.Image = basicTrack.Image; return(track); }
private LocalTrack ToLocalTrack(FullTrack fullTrack) { LocalTrack track = new LocalTrack(); track.Name = fullTrack.Name; track.Album = fullTrack.Album.Name; track.Artist = fullTrack.Artists.FirstOrDefault().Name; track.Id = fullTrack.ExternUrls["spotify"]; track.Duration = (fullTrack.DurationMs / (10 * 60)) / 100.0; track.Type = StreamingSystemType.Spotify; track.Image = fullTrack.Album.Images.Count > 0 ? fullTrack.Album.Images[0].Url : null; return(track); }
private LocalTrack ToLocalTrack(ITrack deezerTrack) { LocalTrack track = new LocalTrack(); track.Name = deezerTrack.Title; track.Album = deezerTrack.Album.Title; track.Artist = deezerTrack.Artist.Name; track.Id = deezerTrack.Id.ToString(); track.Duration = (deezerTrack.Duration * 10 / 6) / 100.0; track.Type = StreamingSystemType.Deezer; track.Image = deezerTrack.Album.GetPicture(PictureSize.Medium); return(track); }
public void Setup() { Mocker.GetMock <IConfigService>() .SetupGet(s => s.DownloadClientWorkingFolders) .Returns("_UNPACK_|_FAILED_"); _localTrack = new LocalTrack { Path = @"C:\Test\Unsorted Music\Kid.Rock\Kid.Rock.Cowboy.mp3".AsOsAgnostic(), Size = 100, Artist = Builder <Artist> .CreateNew().Build() }; }
public TagEditorViewModel(LocalTrack track, Window baseWindow) { TagFile = File.Create(track.Path); Track = track; baseWindow.Closed += (s, e) => TagFile.Dispose(); _baseWindow = baseWindow; AllGenres = Genres.Audio.ToList(); AllGenres.AddRange(Enum.GetValues(typeof(Genre)).Cast <Genre>().Select(PlayableBase.GenreToString).Where(x => !AllGenres.Contains(x))); AllGenres.Sort(); SelectedGenres = track.Genres.Select(PlayableBase.GenreToString).ToList(); }
private void DecreaseSearchCriteria(LocalTrack local_) { switch (local_.SearchType) { case LocalSearchType.FULL_TAGS: local_.SearchType = LocalSearchType.FILENAME_ONLY; break; case LocalSearchType.FILENAME_ONLY: local_.SearchType = LocalSearchType.AUDIO_SEARCH; break; } }
public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, List <TrackFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem) { TrackInfo = trackInfo; ImportedTrack = importedTrack; OldFiles = oldFiles; NewDownload = newDownload; if (downloadClientItem != null) { DownloadClient = downloadClientItem.DownloadClientInfo.Name; DownloadId = downloadClientItem.DownloadId; } }