コード例 #1
0
        private void RevertPath(int artistId, string path)
        {
            var artist = _artistService.GetArtist(artistId);

            artist.Path = path;
            _artistService.UpdateArtist(artist);
        }
コード例 #2
0
ファイル: TrackFileModule.cs プロジェクト: tjman92/Lidarr
        private List <TrackFileResource> GetTrackFiles()
        {
            var artistIdQuery     = Request.Query.ArtistId;
            var trackFileIdsQuery = Request.Query.TrackFileIds;
            var albumIdQuery      = Request.Query.AlbumId;
            var unmappedQuery     = Request.Query.Unmapped;

            if (!artistIdQuery.HasValue && !trackFileIdsQuery.HasValue && !albumIdQuery.HasValue && !unmappedQuery.HasValue)
            {
                throw new Lidarr.Http.REST.BadRequestException("artistId, albumId, trackFileIds or unmapped must be provided");
            }

            if (unmappedQuery.HasValue && Convert.ToBoolean(unmappedQuery.Value))
            {
                var files = _mediaFileService.GetUnmappedFiles();
                return(files.ConvertAll(f => MapToResource(f)));
            }

            if (artistIdQuery.HasValue && !albumIdQuery.HasValue)
            {
                int artistId = Convert.ToInt32(artistIdQuery.Value);
                var artist   = _artistService.GetArtist(artistId);

                return(_mediaFileService.GetFilesByArtist(artistId).ConvertAll(f => f.ToResource(artist, _upgradableSpecification)));
            }

            if (albumIdQuery.HasValue)
            {
                string albumIdValue = albumIdQuery.Value.ToString();

                var albumIds = albumIdValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(e => Convert.ToInt32(e))
                               .ToList();

                var result = new List <TrackFileResource>();
                foreach (var albumId in albumIds)
                {
                    var album       = _albumService.GetAlbum(albumId);
                    var albumArtist = _artistService.GetArtist(album.ArtistId);
                    result.AddRange(_mediaFileService.GetFilesByAlbum(album.Id).ConvertAll(f => f.ToResource(albumArtist, _upgradableSpecification)));
                }

                return(result);
            }

            else
            {
                string trackFileIdsValue = trackFileIdsQuery.Value.ToString();

                var trackFileIds = trackFileIdsValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                   .Select(e => Convert.ToInt32(e))
                                   .ToList();

                // trackfiles will come back with the artist already populated
                var trackFiles = _mediaFileService.Get(trackFileIds);
                return(trackFiles.ConvertAll(e => MapToResource(e)));
            }
        }
コード例 #3
0
        public List <RenameTrackFilePreview> GetRenamePreviews(int artistId)
        {
            var artist = _artistService.GetArtist(artistId);
            var tracks = _trackService.GetTracksByArtist(artistId);
            var files  = _mediaFileService.GetFilesByArtist(artistId);

            return(GetPreviews(artist, tracks, files)
                   .OrderByDescending(e => e.AlbumId)
                   .ThenByDescending(e => e.TrackNumbers.First())
                   .ToList());
        }
コード例 #4
0
        public ActionResult Detail(Guid id)
        {
            var response = _artistService.GetArtist(new GetArtistRequest {
                Id = id
            });

            var model = new DetailArtistViewModel {
                Artist = response.Artist
            };

            return(View(model));
        }
コード例 #5
0
ファイル: ArtistController.cs プロジェクト: JoeAB/MusicSite
        public IActionResult View(int id)
        {
            ViewArtistViewModel model = new ViewArtistViewModel();

            model.artist = _mapper.Map <ArtistModel>(_artistService.GetArtist(id));
            return(View(model));
        }
コード例 #6
0
ファイル: ManualImportModule.cs プロジェクト: zobe123/Lidarr
        private List <ManualImportResource> UpdateImportItems(List <ManualImportResource> resources)
        {
            var items = new List <ManualImportItem>();

            foreach (var resource in resources)
            {
                items.Add(new ManualImportItem {
                    Id                      = resource.Id,
                    Path                    = resource.Path,
                    RelativePath            = resource.RelativePath,
                    Name                    = resource.Name,
                    Size                    = resource.Size,
                    Artist                  = resource.Artist == null ? null : _artistService.GetArtist(resource.Artist.Id),
                    Album                   = resource.Album == null ? null : _albumService.GetAlbum(resource.Album.Id),
                    Release                 = resource.AlbumReleaseId == 0 ? null : _releaseService.GetRelease(resource.AlbumReleaseId),
                    Quality                 = resource.Quality,
                    DownloadId              = resource.DownloadId,
                    AdditionalFile          = resource.AdditionalFile,
                    ReplaceExistingFiles    = resource.ReplaceExistingFiles,
                    DisableReleaseSwitching = resource.DisableReleaseSwitching
                });
            }

            return(_manualImportService.UpdateItems(items).Select(x => x.ToResource()).ToList());
        }
コード例 #7
0
        public async Task <IActionResult> update(int artistId, ArtistUpdateModel artistUpdateModel)
        {
            try
            {
                var isExists = await _artistService.isExists(x => x.Id == artistId);

                if (isExists)
                {
                    if (ModelState.IsValid)
                    {
                        var artist = await _artistService.GetArtist(artistId);

                        artist.Result.Name   = artistUpdateModel.Name;
                        artist.Result.Info   = artistUpdateModel.Info;
                        artist.Result.Gender = artistUpdateModel.Gender;
                        var updateArtist = await _artistService.Update(artist.Result);

                        InfoLog($"{ControllerContext.ActionDescriptor.DisplayName} ArtistUpdated Name : {updateArtist.Result.Name} and Id : {updateArtist.Result.Id}");
                        return(Ok(updateArtist));
                    }
                    return(BadRequest());
                }
                else
                {
                    return(CustomNotFound(artistId));
                }
            }
            catch (Exception exception)
            {
                return(ErrorInternal(exception, $"{ControllerContext.ActionDescriptor.DisplayName} Exception Message : {exception.Message} - {exception.InnerException}"));
            }
        }
コード例 #8
0
ファイル: TrackService.cs プロジェクト: mpxx24/SpotifyHelper
        public Artist GetArtistBasedOnTrack(string trackId)
        {
            var trackAsJson = requestHelper.GetData(string.Format(ApiAdresses.Track, trackId));
            var track       = GetTrackFromJson(trackAsJson);
            var artistId    = track?.Artists[0]?.Id;

            return(artistService.GetArtist(artistId));
        }
コード例 #9
0
 public RemoteAlbum Map(ParsedAlbumInfo parsedAlbumInfo, int artistId, IEnumerable <int> albumIds)
 {
     return(new RemoteAlbum
     {
         ParsedAlbumInfo = parsedAlbumInfo,
         Artist = _artistService.GetArtist(artistId),
         Albums = _albumService.GetAlbums(albumIds)
     });
 }
コード例 #10
0
        public async Task <ActionResult <Artist> > Get(int id, [FromHeader] bool include_relations = false)
        {
            var artist = await artistService.GetArtist(id, include_relations, false);

            if (artist == null)
            {
                return(NotFound());
            }
            return(Ok(artist));
        }
コード例 #11
0
        public IActionResult View(int id)
        {
            ViewSongViewModel model = new ViewSongViewModel();

            model.song       = _mapper.Map <SongModel>(_songService.GetSong(id));
            model.songArtist = _mapper.Map <ArtistModel>(_artistService.GetArtist(model.song.songArtistID));
            model.songGenre  = _mapper.Map <GenreModel>(_genreService.GetGenre(model.song.songGenreID));

            return(View(model));
        }
コード例 #12
0
 public IActionResult Index(string name)
 {
     if (ModelState.IsValid)
     {
         var artist = _artistService.GetArtist(name);
         artist.Events = _artistService.GetArtistEvents(name);
         return(View(new ArtistSearchModel(artist)));
     }
     return(View());
 }
コード例 #13
0
        private List <ManualImportResource> GetMediaFiles()
        {
            var folder     = (string)Request.Query.folder;
            var downloadId = (string)Request.Query.downloadId;

            NzbDrone.Core.Music.Artist artist = null;

            var artistIdQuery = Request.GetNullableIntegerQueryParameter("artistId", null);

            if (artistIdQuery.HasValue && artistIdQuery.Value > 0)
            {
                artist = _artistService.GetArtist(Convert.ToInt32(artistIdQuery.Value));
            }

            var filter = Request.GetBooleanQueryParameter("filterExistingFiles", true) ? FilterFilesType.Matched : FilterFilesType.None;
            var replaceExistingFiles = Request.GetBooleanQueryParameter("replaceExistingFiles", true);

            return(_manualImportService.GetMediaFiles(folder, downloadId, artist, filter, replaceExistingFiles).ToResource().Select(AddQualityWeight).ToList());
        }
コード例 #14
0
            public IActionResult GetMusician(int id)
            {
                var musician = _service.GetArtist(id);

                if (musician == null)
                {
                    return(NotFound());
                }
                return(Ok(musician));
            }
コード例 #15
0
        public IActionResult GetArtist(string name)
        {
            if (_artistService.GetAll().Where(a => a.Name == name).Count() != 0)
            {
                return(View(_artistService.GetAll().FirstOrDefault(a => a.Name == name)));
            }
            Artist artist = _artistService.GetArtist(name);

            _artistService.Create(artist);
            return(View(artist));
        }
コード例 #16
0
        public void Execute(RetagFilesCommand message)
        {
            var artist     = _artistService.GetArtist(message.ArtistId);
            var trackFiles = _mediaFileService.Get(message.Files);

            _logger.ProgressInfo("Re-tagging {0} files for {1}", trackFiles.Count, artist.Name);
            foreach (var file in trackFiles)
            {
                WriteTags(file, false, force: true);
            }
            _logger.ProgressInfo("Selected track files re-tagged for {0}", artist.Name);
        }
コード例 #17
0
        public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false)
        {
            if (trackedDownload.DownloadItem.Status != DownloadItemStatus.Completed ||
                trackedDownload.RemoteAlbum == null)
            {
                return;
            }

            if (!ignoreWarnings)
            {
                var historyItem = _historyService.MostRecentForDownloadId(trackedDownload.DownloadItem.DownloadId);

                if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace())
                {
                    trackedDownload.Warn("Download wasn't grabbed by Lidarr and not in a category, Skipping.");
                    return;
                }

                var downloadItemOutputPath = trackedDownload.DownloadItem.OutputPath;

                if (downloadItemOutputPath.IsEmpty)
                {
                    trackedDownload.Warn("Download doesn't contain intermediate path, Skipping.");
                    return;
                }

                if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) ||
                    (OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath))
                {
                    trackedDownload.Warn("[{0}] is not a valid local path. You may need a Remote Path Mapping.", downloadItemOutputPath);
                    return;
                }

                var artist = trackedDownload.RemoteAlbum.Artist;

                if (artist == null)
                {
                    if (historyItem != null)
                    {
                        artist = _artistService.GetArtist(historyItem.ArtistId);
                    }

                    if (artist == null)
                    {
                        trackedDownload.Warn("Artist name mismatch, automatic import is not possible.");
                        return;
                    }
                }
            }

            Import(trackedDownload);
        }
コード例 #18
0
        public void Execute(RefreshArtistCommand message)
        {
            var trigger = message.Trigger;
            var isNew   = message.IsNewArtist;

            if (message.ArtistId.HasValue)
            {
                var  artist  = _artistService.GetArtist(message.ArtistId.Value);
                bool updated = false;
                try
                {
                    updated = RefreshEntityInfo(artist, null, true, false);
                    _logger.Trace($"Artist {artist} updated: {updated}");
                    RescanArtist(artist, isNew, trigger, updated);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't refresh info for {0}", artist);
                    RescanArtist(artist, isNew, trigger, updated);
                    throw;
                }
            }
            else
            {
                var allArtists = _artistService.GetAllArtists().OrderBy(c => c.Name).ToList();

                foreach (var artist in allArtists)
                {
                    var manualTrigger = message.Trigger == CommandTrigger.Manual;

                    if (manualTrigger || _checkIfArtistShouldBeRefreshed.ShouldRefresh(artist))
                    {
                        bool updated = false;
                        try
                        {
                            updated = RefreshEntityInfo(artist, null, manualTrigger, false);
                        }
                        catch (Exception e)
                        {
                            _logger.Error(e, "Couldn't refresh info for {0}", artist);
                        }

                        RescanArtist(artist, false, trigger, updated);
                    }
                    else
                    {
                        _logger.Info("Skipping refresh of artist: {0}", artist.Name);
                        RescanArtist(artist, false, trigger, false);
                    }
                }
            }
        }
コード例 #19
0
        public void Check(TrackedDownload trackedDownload)
        {
            if (trackedDownload.DownloadItem.Status != DownloadItemStatus.Completed ||
                trackedDownload.RemoteAlbum == null)
            {
                return;
            }

            SetImportItem(trackedDownload);

            // Only process tracked downloads that are still downloading
            if (trackedDownload.State != TrackedDownloadState.Downloading)
            {
                return;
            }

            var historyItem = _historyService.MostRecentForDownloadId(trackedDownload.DownloadItem.DownloadId);

            if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace())
            {
                trackedDownload.Warn("Download wasn't grabbed by Lidarr and not in a category, Skipping.");
                return;
            }

            if (!ValidatePath(trackedDownload))
            {
                return;
            }

            var artist = trackedDownload.RemoteAlbum.Artist;

            if (artist == null)
            {
                if (historyItem != null)
                {
                    artist = _artistService.GetArtist(historyItem.ArtistId);
                }

                if (artist == null)
                {
                    trackedDownload.Warn("Artist name mismatch, automatic import is not possible.");
                    return;
                }
            }

            trackedDownload.State = TrackedDownloadState.ImportPending;
        }
コード例 #20
0
        public async Task <DataRespone <GetArtistDTO> > getArtist(int id)
        {
            if (id == 0)
            {
                throw new MyBadRequestException(HttpStatusCode.BadRequest, "ArtistID must be not null.");
            }
            GetArtistDTO artist = await _artistService.GetArtist(id);

            if (artist == null)
            {
                throw new MyNotFoundException(HttpStatusCode.NotFound, "Artist have not found.");
            }
            return(new DataRespone <GetArtistDTO>()
            {
                Ok = true, data = artist, error = ""
            });
        }
コード例 #21
0
        public void Execute(RescanArtistCommand message)
        {
            if (message.ArtistId.HasValue)
            {
                var artist = _artistService.GetArtist(message.ArtistId.Value);
                Scan(artist, message.Filter);
            }

            else
            {
                var allArtists = _artistService.GetAllArtists();

                foreach (var artist in allArtists)
                {
                    Scan(artist, message.Filter);
                }
            }
        }
コード例 #22
0
ファイル: CalendarFeedModule.cs プロジェクト: zobe123/Lidarr
        private Response GetCalendarFeed()
        {
            var pastDays    = 7;
            var futureDays  = 28;
            var start       = DateTime.Today.AddDays(-pastDays);
            var end         = DateTime.Today.AddDays(futureDays);
            var unmonitored = Request.GetBooleanQueryParameter("unmonitored");
            var tags        = new List <int>();

            var queryPastDays   = Request.Query.PastDays;
            var queryFutureDays = Request.Query.FutureDays;
            var queryTags       = Request.Query.Tags;

            if (queryPastDays.HasValue)
            {
                pastDays = int.Parse(queryPastDays.Value);
                start    = DateTime.Today.AddDays(-pastDays);
            }

            if (queryFutureDays.HasValue)
            {
                futureDays = int.Parse(queryFutureDays.Value);
                end        = DateTime.Today.AddDays(futureDays);
            }

            if (queryTags.HasValue)
            {
                var tagInput = (string)queryTags.Value.ToString();
                tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id));
            }

            var albums   = _albumService.AlbumsBetweenDates(start, end, unmonitored);
            var calendar = new Ical.Net.Calendar
            {
                ProductId = "-//lidarr.audio//Lidarr//EN"
            };

            var calendarName = "Lidarr Music Schedule";

            calendar.AddProperty(new CalendarProperty("NAME", calendarName));
            calendar.AddProperty(new CalendarProperty("X-WR-CALNAME", calendarName));

            foreach (var album in albums.OrderBy(v => v.ReleaseDate.Value))
            {
                var artist = _artistService.GetArtist(album.ArtistId); // Temp fix TODO: Figure out why Album.Artist is not populated during AlbumsBetweenDates Query

                if (tags.Any() && tags.None(artist.Tags.Contains))
                {
                    continue;
                }

                var occurrence = calendar.Create <Event>();
                occurrence.Uid = "NzbDrone_album_" + album.Id;
                //occurrence.Status = album.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
                //occurrence.Description = album.Overview;
                //occurrence.Categories = new List<string>() { album.Series.Network };

                occurrence.Start = new CalDateTime(album.ReleaseDate.Value.ToLocalTime())
                {
                    HasTime = false
                };

                occurrence.Summary = $"{artist.Name} - {album.Title}";
            }

            var serializer = (IStringSerializer) new SerializerFactory().Build(calendar.GetType(), new SerializationContext());
            var icalendar  = serializer.SerializeToString(calendar);

            return(new TextResponse(icalendar, "text/calendar"));
        }
コード例 #23
0
        //
        // GET: /Artist/Details/5
        public ActionResult Details(int id)
        {
            var artist = _artist.GetArtist(id);

            return(View(artist));
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: LindaHa/MusicLibrary
        private static void TestArtistService()
        {
            List <int> list = new List <int>();

            artistService = Container.Resolve <IArtistService>();
            clientService = Container.Resolve <IClientService>();

            //Create
            artistService.CreateArtist(new ArtistDTO
            {
                Name       = "Bullet For My Valentine",
                Info       = "Bullet for My Valentine are a Welsh heavy metal band from Bridgend, formed in 1998.The band is composed of Matthew Tuck(lead vocals, rhythm guitar), Michael Paget(lead guitar, backing vocals), Michael Thomas(drums) and Jamie Mathias(bass guitar).",
                IsOfficial = true,
                CreatorID  = clientID
            });
            artistService.CreateArtist(new ArtistDTO
            {
                Name       = "Viola Martinsson",
                Info       = "Viola Martinsson is a Swedish singer and musician born in 1991 in Söråker, Sweden. Her version of “Made Of” was recorded specifically to become the music theme for the Volvo campaign “Made of Sweden”, and is a cover of the 2012 track of the same name from Nause.",
                IsOfficial = true,
                CreatorID  = clientID
            });

            //GetArtistIdByName
            artistID = artistService.GetArtistIdByName("Bullet For My Valentine");
            int violaID = artistService.GetArtistIdByName("Viola Martinsson");

            list.Add(artistID);
            list.Add(violaID);
            Console.WriteLine(list.Count() == 2 ? "ClientService - GetArtistIdByName - OK" : "ClientService - GetArtistIdByName - FAIL");



            //GetArtisById
            ArtistDTO bfmv = artistService.GetArtist(artistID);

            Console.WriteLine(bfmv.Name == "Bullet For My Valentine" ? "ArtistService - TestGetArtisById - OK" : "ArtistService - TestGetArtisById - FAIL");

            //ListAllArtists01
            // var artists = artistService.ListAllArtists(new ArtistFilter { Name = "Viola Martinsson" }, 1);
            // Console.WriteLine(artists.TotalResultCount == 1 ? "ArtistService - TestListAllArtists01 - OK" : "ArtistService - TestListAllArtists01 - FAIL");

            //ListAllArtists02
            var artists2 = artistService.ListAllArtists();

            Console.WriteLine(list.Count() == 2 ? "ClientService - ListAllArtists02 - OK" : "ClientService - ListAllArtists02 - FAIL");


            //EditArtist
            bfmv.Name = "BFMV";
            artistService.EditArtist(bfmv, bfmv.AlbumIDs);
            ArtistDTO bfmvFromDB = artistService.GetArtist(bfmv.ID);

            Console.WriteLine(bfmvFromDB.Name == "BFMV" ? "ArtistService - TestEditArtist - OK" : "ArtistService - TestEditArtist - FAIL");

            //DeleteArtist
            artistService.DeleteArtist(violaID);
            int violaIDFromDB = artistService.GetArtistIdByName("Viola Martinsson");

            Console.WriteLine(violaIDFromDB < 1 ? "ArtistService - TestDeleteArtist - OK" : "ArtistService - TestDeleteArtist - FAIL");

            //GetCreator
            ClientDTO creator = artistService.GetCreator(bfmv.ID);

            Console.WriteLine(creator.ID == clientID ? "ArtistService - GetCreator - OK" : "ArtistService - GetCreator - FAIL");
        }
コード例 #25
0
        public void AddArtistToDb(string name)
        {
            Artist artist = artistService.GetArtist(name);

            artistService.Create(artist);
        }
コード例 #26
0
        public List <DownloadDecision> ArtistSearch(int artistId, bool missingOnly, bool userInvokedSearch, bool interactiveSearch)
        {
            var artist = _artistService.GetArtist(artistId);

            return(ArtistSearch(artist, missingOnly, userInvokedSearch, interactiveSearch));
        }
コード例 #27
0
        public void Execute(ManualImportCommand message)
        {
            _logger.ProgressTrace("Manually importing {0} files using mode {1}", message.Files.Count, message.ImportMode);

            var imported = new List <ImportResult>();
            var importedTrackedDownload = new List <ManuallyImportedFile>();
            var albumIds  = message.Files.GroupBy(e => e.AlbumId).ToList();
            var fileCount = 0;

            foreach (var importAlbumId in albumIds)
            {
                var albumImportDecisions = new List <ImportDecision <LocalTrack> >();

                // turn off anyReleaseOk if specified
                if (importAlbumId.First().DisableReleaseSwitching)
                {
                    var album = _albumService.GetAlbum(importAlbumId.First().AlbumId);
                    album.AnyReleaseOk = false;
                    _albumService.UpdateAlbum(album);
                }

                foreach (var file in importAlbumId)
                {
                    _logger.ProgressTrace("Processing file {0} of {1}", fileCount + 1, message.Files.Count);

                    var artist        = _artistService.GetArtist(file.ArtistId);
                    var album         = _albumService.GetAlbum(file.AlbumId);
                    var release       = _releaseService.GetRelease(file.AlbumReleaseId);
                    var tracks        = _trackService.GetTracks(file.TrackIds);
                    var fileTrackInfo = _audioTagService.ReadTags(file.Path) ?? new ParsedTrackInfo();
                    var fileInfo      = _diskProvider.GetFileInfo(file.Path);

                    var localTrack = new LocalTrack
                    {
                        ExistingFile  = artist.Path.IsParentPath(file.Path),
                        Tracks        = tracks,
                        FileTrackInfo = fileTrackInfo,
                        Path          = file.Path,
                        Size          = fileInfo.Length,
                        Modified      = fileInfo.LastWriteTimeUtc,
                        Quality       = file.Quality,
                        Artist        = artist,
                        Album         = album,
                        Release       = release
                    };

                    albumImportDecisions.Add(new ImportDecision <LocalTrack>(localTrack));
                    fileCount += 1;
                }

                var downloadId = importAlbumId.Select(x => x.DownloadId).FirstOrDefault(x => x.IsNotNullOrWhiteSpace());
                if (downloadId.IsNullOrWhiteSpace())
                {
                    imported.AddRange(_importApprovedTracks.Import(albumImportDecisions, message.ReplaceExistingFiles, null, message.ImportMode));
                }
                else
                {
                    var trackedDownload = _trackedDownloadService.Find(downloadId);
                    var importResults   = _importApprovedTracks.Import(albumImportDecisions, message.ReplaceExistingFiles, trackedDownload.DownloadItem, message.ImportMode);

                    imported.AddRange(importResults);

                    foreach (var importResult in importResults)
                    {
                        importedTrackedDownload.Add(new ManuallyImportedFile
                        {
                            TrackedDownload = trackedDownload,
                            ImportResult    = importResult
                        });
                    }
                }
            }

            _logger.ProgressTrace("Manually imported {0} files", imported.Count);

            foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
            {
                var trackedDownload = groupedTrackedDownload.First().TrackedDownload;

                if (_diskProvider.FolderExists(trackedDownload.DownloadItem.OutputPath.FullPath))
                {
                    if (_downloadedTracksImportService.ShouldDeleteFolder(
                            _diskProvider.GetDirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath),
                            trackedDownload.RemoteAlbum.Artist) && trackedDownload.DownloadItem.CanMoveFiles)
                    {
                        _diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, true);
                    }
                }

                if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteAlbum.Albums.Count))
                {
                    trackedDownload.State = TrackedDownloadStage.Imported;
                    _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
                }
            }
        }
コード例 #28
0
        public List <Album> SearchForNewAlbum(string title, string artist)
        {
            try
            {
                var lowerTitle = title.ToLowerInvariant();

                if (lowerTitle.StartsWith("gamearr:") || lowerTitle.StartsWith("gamearrid:") || lowerTitle.StartsWith("mbid:"))
                {
                    var slug = lowerTitle.Split(':')[1].Trim();

                    Guid searchGuid;

                    bool isValid = Guid.TryParse(slug, out searchGuid);

                    if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || isValid == false)
                    {
                        return(new List <Album>());
                    }

                    try
                    {
                        var existingAlbum = _albumService.FindById(searchGuid.ToString());

                        if (existingAlbum == null)
                        {
                            var data  = GetAlbumInfo(searchGuid.ToString());
                            var album = data.Item2;
                            album.Artist = _artistService.FindById(data.Item1) ?? new Artist {
                                Metadata = data.Item3.Single(x => x.ForeignArtistId == data.Item1)
                            };

                            return(new List <Album> {
                                album
                            });
                        }

                        existingAlbum.Artist = _artistService.GetArtist(existingAlbum.ArtistId);
                        return(new List <Album> {
                            existingAlbum
                        });
                    }
                    catch (ArtistNotFoundException)
                    {
                        return(new List <Album>());
                    }
                }

                var httpRequest = _requestBuilder.GetRequestBuilder().Create()
                                  .SetSegment("route", "search")
                                  .AddQueryParam("type", "album")
                                  .AddQueryParam("query", title.ToLower().Trim())
                                  .AddQueryParam("artist", artist.IsNotNullOrWhiteSpace() ? artist.ToLower().Trim() : string.Empty)
                                  .Build();



                var httpResponse = _httpClient.Get <List <AlbumResource> >(httpRequest);

                return(httpResponse.Resource.SelectList(MapSearchResult));
            }
            catch (HttpException)
            {
                throw new SkyHookException("Search for '{0}' failed. Unable to communicate with GamearrAPI.", title);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, ex.Message);
                throw new SkyHookException("Search for '{0}' failed. Invalid response received from GamearrAPI.", title);
            }
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: LindaHa/MusicLibrary
        private static void TestAlbumService()
        {
            List <int> list = new List <int>();

            albumService  = Container.Resolve <IAlbumService>();
            clientService = Container.Resolve <IClientService>();

            //Create
            albumService.CreateAlbum(new AlbumDTO
            {
                Name       = "The Poison",
                ArtistID   = artistID,
                IsOfficial = true,
                CreatorID  = clientID,
            });
            albumService.CreateAlbum(new AlbumDTO
            {
                Name       = "Venom",
                ArtistID   = artistID,
                IsOfficial = true,
                CreatorID  = clientID
            });


            //GetAlbumIdByName
            albumID = albumService.GetAlbumIdByName("The Poison");
            int venomID = albumService.GetAlbumIdByName("Venom");

            list.Add(albumID);
            list.Add(venomID);
            Console.WriteLine(list.Count() == 2 ? "ClientService - GetAlbumIdByName - OK" : "ClientService - GetAlbumIdByName - FAIL");

            //GetAlbumById
            AlbumDTO poison = albumService.GetAlbum(albumID);
            AlbumDTO venom  = albumService.GetAlbum(venomID);

            Console.WriteLine(poison.Name == "The Poison" ? "AlbumService - GetAlbumById - OK" : "AlbumService - GetAlbumById - FAIL");

            artistService = Container.Resolve <IArtistService>();

            //AddAlbum
            albumService.AddAlbum(poison);
            albumService.AddAlbum(venom);
            ArtistDTO artist = artistService.GetArtist(artistID);

            Console.WriteLine(artist.AlbumIDs.Contains(albumID) ?
                              "AlbumService - AddAlbum - OK" : "AlbumService - AddAlbum - FAIL");

            //GetArtistOfAlbum
            ArtistDTO artist2 = albumService.GetArtistOfAlbum(albumID);

            Console.WriteLine(artist2.ID == artistID ?
                              "AlbumService - GetArtistOfAlbum - OK" : "AlbumService - GetArtistOfAlbum - FAIL");

            //TestArtistServisGetAllAlbums
            Console.WriteLine(artist.AlbumIDs.Count() == 2 ?
                              "ArtistService - TestArtistServisGetAllAlbums - OK" : "ArtistService - TestArtistServisGetAllAlbums - FAIL");

            //ListAllAlbums
            var albums = albumService.ListAllAlbums(new AlbumFilter {
                Name = "The Poison"
            }, 1);

            Console.WriteLine(albums.TotalResultCount == 2 ? "AlbumService - TestListAllAlbums - OK" : "AlbumService - TestListAllAlbums - FAIL");

            //ListAllAlbumss02
            var albums2 = albumService.ListAllAlbums();

            Console.WriteLine(albums2.Count() == 2 ? "AlbumService - ListAllAlbumss02 - OK" : "AlbumService - ListAllAlbumss02 - FAIL");

            //EditAlbum
            poison.Name = "The Poisonous Poison";
            albumService.EditAlbum(poison, artistID, null, null);
            AlbumDTO poisonFromDB = albumService.GetAlbum(poison.ID);

            Console.WriteLine(poisonFromDB.Name == "The Poisonous Poison" ? "AlbumService - TestEditAlbum - OK" : "AlbumService - TestEditAlbum - FAIL");

            //DeleteAlbum
            albumService.DeleteAlbum(venomID);
            try
            {
                AlbumDTO venomFromDB = albumService.GetAlbum(venomID);
                Console.WriteLine("AlbumService - TestDeleteAlbum - FAIL");
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("AlbumService - TestDeleteAlbum - OK");
            }


            //GetCreator
            ClientDTO creator = genreService.GetCreator(poison.ID);

            Console.WriteLine(creator.ID == clientID ? "AlbumService - GetCreator - OK" : "AlbumService - GetCreator - FAIL");
        }
コード例 #30
0
ファイル: ArtistModule.cs プロジェクト: debbielobo1/Lidarr
        private ArtistResource GetArtist(int id)
        {
            var artist = _artistService.GetArtist(id);

            return(GetArtistResource(artist));
        }