Ejemplo n.º 1
0
        public async Task <ActionResult <PodcastEntryViewModel> > PreProcess(PodcastEntryViewModel item)
        {
            var entry = await _repository.GetAsync(item.Id);

            entry.ProcessingStatus = ProcessingStatus.Accepted;
            var response = _processor.GetInformation(item.Id, this.UserId);

            entry.ProcessingStatus = ProcessingStatus.Processing;
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry);

            return(result);
        }
Ejemplo n.º 2
0
        // [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);
        }