public async Task Execute(ulong param, bool queueNext = false)
        {
            var dbArtist = await _dataRepository.GetArtist(param);

            if (dbArtist == null)
            {
                var apiArtist = await _deezerApiService.GetDeezerApi().Artists.GetById(param, CancellationToken.None);

                await _dataRepository.CreateArtist(_mapper.Map <Artist>(apiArtist));

                dbArtist = await _dataRepository.GetArtist(apiArtist.Id);

                await Task.Delay(_delayConfiguration.CheckArtistForUpdatesBackgroundJob_ExecuteDelay);
            }

            if (dbArtist != null)
            {
                var apiArtist = await _deezerApiService.GetDeezerApi().Artists.GetById(param, CancellationToken.None);

                var numberOfTracks = await GetTrackCount(apiArtist);

                if (dbArtist.NumberOfAlbums != apiArtist.NumberOfAlbums ||
                    dbArtist.NumberOfTracks != numberOfTracks)
                {
                    _deemixService.DownloadArtist(dbArtist);

                    dbArtist.NumberOfTracks = numberOfTracks;
                    dbArtist.NumberOfAlbums = apiArtist.NumberOfAlbums;

                    await _dataRepository.UpdateArtist(dbArtist);
                }
            }
        }
        public async Task Execute(ulong param, PerformContext context)
        {
            var dbPlaylist = await _dataRepository.GetPlaylist(param);

            if (dbPlaylist == null)
            {
                var apiPlaylist = await _deezerApiService.GetDeezerApi().Playlists.GetById(param, CancellationToken.None);

                await _dataRepository.CreatePlaylist(_mapper.Map <Playlist>(apiPlaylist));

                dbPlaylist = await _dataRepository.GetPlaylist(apiPlaylist.Id);

                await Task.Delay(_delayConfiguration.CheckPlaylistForUpdatesBackgroundJob_ExecuteDelay);
            }

            if (dbPlaylist != null)
            {
                var apiPlaylist = await _deezerApiService.GetDeezerApi().Playlists.GetById(param, CancellationToken.None);

                if (dbPlaylist.NumberOfTracks != apiPlaylist.NumberOfTracks)
                {
                    _deemixService.DownloadPlaylist(dbPlaylist);

                    dbPlaylist.NumberOfTracks = apiPlaylist.NumberOfTracks;

                    await _dataRepository.UpdatePlaylist(dbPlaylist);
                }
            }
        }
Esempio n. 3
0
        public async Task Execute()
        {
            var updates = await _deezerApiService.GetDeezerApi().Genre.GetNewReleasesForGenre(0, CancellationToken.None, 0, 200);

            if (updates != null)
            {
                var updatesList  = updates.ToList();
                var latestAlbum  = updatesList.FirstOrDefault();
                var lastChangeId = await _configurationService.Get <ulong>("LastChangeId");

                if (latestAlbum != null)
                {
                    if (latestAlbum.Id != lastChangeId)
                    {
                        foreach (var album in updatesList)
                        {
                            if (latestAlbum.Id == lastChangeId)
                            {
                                break;
                            }

                            var dbArtist = await _dataRepository.GetArtist(album.Artist.Id);

                            if (dbArtist != null)
                            {
                                _deemixService.Download($"https://www.deezer.com/en/album/{album.Id}", dbArtist.Folder);
                            }
                        }
                    }

                    await _configurationService.Set("LastChangeId", latestAlbum.Id);
                }
            }
        }
Esempio n. 4
0
        public async Task Execute()
        {
            var updates = await _deezerApiService.GetDeezerApi().Genre.GetNewReleasesForGenre(0, CancellationToken.None, 0, 200);

            if (updates != null)
            {
                var updatesList  = updates.ToList();
                var latestAlbum  = updatesList.FirstOrDefault();
                var lastChangeId = await _configurationService.Get <ulong>("LastChangeId");

                if (latestAlbum != null)
                {
                    if (latestAlbum.Id != lastChangeId)
                    {
                        foreach (var album in updatesList)
                        {
                            if (latestAlbum.Id == lastChangeId)
                            {
                                break;
                            }

                            var dbArtist = await _dataRepository.GetArtist(album.Artist.Id);

                            if (dbArtist != null)
                            {
                                var apiAlbum = await _deezerApiService.GetDeezerApi().Albums.GetById(album.Id, CancellationToken.None);

                                album.Link.Deemix();

                                dbArtist.NumberOfAlbums += 1;
                                dbArtist.NumberOfTracks += apiAlbum.TrackCount;

                                await _dataRepository.UpdateArtist(dbArtist);
                            }
                        }
                    }

                    await _configurationService.Set("LastChangeId", latestAlbum.Id);
                }
            }
        }
Esempio n. 5
0
        public async Task Execute(string param, bool queueNext = false)
        {
            var folder = await _dataRepository.GetFolder(param);

            if (folder != null)
            {
                try
                {
                    folder.State = Enums.ProcessingState.Processing;
                    await _dataRepository.UpdateFolder(folder);

                    var dirs = Directory.GetDirectories(folder.Path);

                    foreach (var dir in dirs)
                    {
                        var dirName      = Path.GetFileName(dir);
                        var foundArtists = await _deezerApiService.GetDeezerApi().Search.FindArtists(dirName, CancellationToken.None, 0, 1);

                        var firstArtist = foundArtists.FirstOrDefault();

                        if (firstArtist != null)
                        {
                            var dbArtist = await _dataRepository.GetArtist(firstArtist.Id);

                            if (dbArtist == null)
                            {
                                BackgroundJob.Enqueue <CreateArtistBackgroundJob>(
                                    x => x.Execute(
                                        new CreateArtistBackgroundJobData()
                                {
                                    ArtistDeezerId = firstArtist.Id,
                                    FolderId       = folder.Id
                                }, false)
                                    );
                            }
                        }

                        await Task.Delay(_delayConfiguration.ImportArtistsBackgroundJob_ExecuteDelay);
                    }

                    folder.State = Enums.ProcessingState.None;
                }
                catch (Exception e)
                {
                    folder.State = Enums.ProcessingState.Failed;

                    throw e;
                }

                await _dataRepository.UpdateFolder(folder);
            }
        }
Esempio n. 6
0
        public async Task Execute()
        {
            var genres = await _deezerApiService.GetDeezerApi().Genre.GetCommonGenre(CancellationToken.None);

            foreach (var genre in genres)
            {
                var dbGenre = await _dataRepository.GetGenre(genre.Id);

                if (dbGenre == null)
                {
                    await _dataRepository.CreateGenre(_mapper.Map <Genre>(genre));
                }
            }
        }
        public async Task Execute(PerformContext context)
        {
            var overallProgressbar = context.WriteProgressBar();
            var updates            = await _deezerApiService.GetDeezerApi().Genre.GetNewReleasesForGenre(0, CancellationToken.None, 0, 200);

            if (updates != null)
            {
                var updatesList  = updates.ToList();
                var latestAlbum  = updatesList.FirstOrDefault();
                var lastChangeId = await _configurationService.Get <ulong>("LastChangeId");

                if (latestAlbum != null)
                {
                    if (latestAlbum.Id != lastChangeId)
                    {
                        foreach (var album in updatesList.WithProgress(overallProgressbar))
                        {
                            if (latestAlbum.Id == lastChangeId)
                            {
                                break;
                            }

                            var dbArtist = await _dataRepository.GetArtist(album.Artist.Id);

                            if (dbArtist != null)
                            {
                                _deemixService.Download($"https://www.deezer.com/en/album/{album.Id}", dbArtist.Folder);

                                dbArtist.Updated = DateTime.UtcNow;

                                await _dataRepository.UpdateArtist(dbArtist);
                            }
                        }
                    }

                    await _configurationService.Set("LastChangeId", latestAlbum.Id);
                }
            }
        }
 private async Task FromPlaylist(ulong playlistId, Folder folder)
 {
     await CheckAndCreatePlaylist(await _deezerApiService.GetDeezerApi().Playlists.GetById(playlistId, CancellationToken.None), folder);
 }