public async Task <ActionResult <PlaylistViewModel> > Post([FromBody] PodcastEntryViewModel entry) { var podcast = await _podcastRepository.GetAsync(entry.PodcastId); if (podcast == null) { return(NotFound()); } if (string.IsNullOrEmpty(entry.SourceUrl)) { return(BadRequest("SourceUrl is empty")); } var sourceUrl = await _youTubeParser.ConvertUserToChannel(entry.SourceUrl, podcast.AppUserId); var playlist = new Playlist { Podcast = podcast, SourceUrl = sourceUrl }; _playlistRepository.AddOrUpdate(playlist); try { await _unitOfWork.CompleteAsync(); } catch (DbUpdateException ex) { if (ex.InnerException != null && ex.InnerException.Message.Contains("IX_Playlists_SourceUrl")) { return(Conflict("This podcast is already monitoring this playlist")); } return(BadRequest("There was an error adding this playlist")); } BackgroundJob.Enqueue <ProcessPlaylistsJob>(job => job.Execute(playlist.Id, null)); return(_mapper.Map <Playlist, PlaylistViewModel>(playlist)); }
public async Task <ActionResult <PodcastEntryViewModel> > GetFeaturedEpisode(string podcastId) { //TODO: This should definitely have its own ViewModel var podcast = await _podcastRepository.GetAsync(podcastId); if (podcast is null) { return(NotFound()); } var result = await _entryRepository.GetFeaturedEpisode(podcast); if (result is null) { return(NotFound()); } return(_mapper.Map <PodcastEntry, PodcastEntryViewModel>(result)); }
public async Task <ActionResult <string> > UploadPodcastImage(string id, IFormFile image) { _logger.LogDebug("Uploading new image"); var podcast = await _podcastRepository.GetAsync(_applicationUser.Id, Guid.Parse(id)); if (podcast is null) { return(NotFound()); } try { var imageFile = await _commitImage(id, image, "podcast"); _podcastRepository.AddOrUpdate(podcast); await _unitOfWork.CompleteAsync(); return(Ok($"\"{_mapper.Map<Podcast, PodcastViewModel>(podcast).ImageUrl}\"")); } catch (InvalidOperationException ex) { return(BadRequest(ex.Message)); } }
// [MaximumConcurrentExecutions(1)] // [DisableConcurrentExecution(timeoutInSeconds: 60 * 60 * 2)] public async Task <bool> Execute(ParsedItemResult item, Guid playlistId, PerformContext context) { _setContext(context); if (item is null || string.IsNullOrEmpty(item.VideoType)) { return(false); } Log($"Starting process item:\n\t{item.Id}\n\t{item.Title}\n\thttps://www.youtube.com/watch?v={item.Id}"); var playlist = await _playlistRepository.GetAsync(playlistId); var url = item.VideoType.ToLower().Equals("youtube") ? $"https://www.youtube.com/watch?v={item.Id}" : item.VideoType.Equals("mixcloud") ? $"https://mixcloud.com/{item.Id}" : string.Empty; if (string.IsNullOrEmpty(url)) { LogError($"Unknown video type for ParsedItem: {item.Id} - {playlist.Id}"); } else { Log($"Getting info"); var info = await _audioDownloader.GetInfo(url, playlist.Podcast.AppUserId); if (info != RemoteUrlType.Invalid) { Log($"URL is valid"); var podcast = await _podcastRepository.GetAsync(playlist.PodcastId); var uid = Guid.NewGuid(); Log($"Downloading audio"); var localFile = Path.Combine(Path.GetTempPath(), $"{System.Guid.NewGuid()}.mp3"); try { var entry = new PodcastEntry { SourceUrl = url, ProcessingStatus = ProcessingStatus.Uploading, Playlist = playlist, Podcast = podcast }; await _processor.GetInformation(entry, podcast.AppUserId); podcast.PodcastEntries.Add(entry); await _unitOfWork.CompleteAsync(); var result = await _preProcessor.PreProcessEntry(podcast.AppUser, entry); return(result == EntryProcessResult.Succeeded); } catch (AudioDownloadException e) { //TODO: we should mark this as failed //so we don't continuously process it LogError(e.Message); } } else { LogError($"Processing playlist item {item.Id} failed"); return(false); } } return(true); }
public Podcast Resolve(PodcastEntryViewModel source, PodcastEntry destination, Podcast destMember, ResolutionContext context) { return(Task.Run(async() => await _sourceRepository.GetAsync(source.PodcastId)).Result); }