Пример #1
0
        public string ConvertTubeToTune([FromBody] List <string> youtubeVideoLinks)
        {
            if (!youtubeVideoLinks.Any())
            {
                throw new AudioExtractionException("Please enter a YouTube link.");
            }

            List <string> convertedAudioFilenames = new List <string>();

            try
            {
                foreach (string youtubeVideoLink in youtubeVideoLinks)
                {
                    IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(youtubeVideoLink, false);

                    VideoInfo video = videoInfos
                                      .Where(info => info.CanExtractAudio)
                                      .OrderByDescending(info => info.AudioBitrate)
                                      .First();

                    string convertedAudioFileName = FileNameGenerationHelper.RemoveIllegalPathCharacters(video.Title) + video.AudioExtension;
                    convertedAudioFilenames.Add(convertedAudioFileName);

                    if (video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(video);
                    }

                    new AudioDownloader(video, Path.Combine(
                                            HttpContext.Current.Server.MapPath("~/App_Data"),
                                            convertedAudioFileName)).Execute();
                }
            }
            catch (Exception e)
            {
                throw new AudioExtractionException(e.Message);
            }

            return(convertedAudioFilenames.Count() == 1 ?
                   convertedAudioFilenames.FirstOrDefault() :
                   FileZippingHelper.ZipConvertedAudioFiles(convertedAudioFilenames));
        }
Пример #2
0
        public ConversionResponse ConvertTubeToTune(ConversionRequest ConversionRequest)
        {
            if (ConversionRequest == null)
            {
                throw new AudioExtractionException("Please enter a YouTube link.");
            }

            IList <VideoConversionErrorDetailsDto> conversionErrors = new List <VideoConversionErrorDetailsDto>();
            IList <string> convertedVideoLinks = new List <string>();

            foreach (VideoConversionDetailsDto videoConversionDetail in ConversionRequest.VideoConversionDetails)
            {
                try
                {
                    IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(videoConversionDetail.VideoLink, false);

                    VideoInfo video = videoInfos
                                      .Where(info => info.CanExtractAudio)
                                      .OrderByDescending(info => info.AudioBitrate)
                                      .First();

                    string convertedAudioFileName = FileNameGenerationHelper.RemoveIllegalPathCharacters(video.Title) + video.AudioExtension;
                    convertedVideoLinks.Add(convertedAudioFileName);

                    if (video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(video);
                    }

                    new AudioDownloader(video, Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), convertedAudioFileName)).Execute();
                }
                catch (Exception e) { conversionErrors.Add(BuildVideoConversionError(e.Message, videoConversionDetail.VideoId)); }
            }

            return(BuildConversionResponse(convertedVideoLinks, conversionErrors, ConversionRequest.VideoConversionDetails.Count()));
        }