示例#1
0
        private async void HandleFileConversion(string filepath)
        {
            //Path.get
            string filename = Path.GetFileNameWithoutExtension(filepath);

            var job = new ConversionItem
            {
                Title = filename,
            };

            ConversionJobs.Add(job);
            ConversionJobsListView.ScrollIntoView(job);

            // Convert
            job.Status = ConversionJobStatus.Converting;
            filename   = MediaConverter.RemoveInvalidFilenameCharacters(filename);
            string dstFilepath = MediaConverter.EnsureUniqueFilepath($"{Settings.OutputFolder}\\{filename}.wav");
            await MediaConverter.FFmpegConvertToWavAsync(filepath, dstFilepath, Settings.OutputFrequency, Settings.OutputVolumeMultiplier);

            // Finish
            job.Status = ConversionJobStatus.Done;
        }
示例#2
0
        public void ShouldReturnValidFilename()
        {
            var testCases = new[]
            {
                new { ValidFilename = "Touhou PV MariAliCANDY", Filename = "【Touhou PV】 MariAli☆CANDY 【東方音遊戯】" },
                new { ValidFilename = "Hatsune Miku - Unfragment [P]", Filename = "Hatsune Miku - Unfragment [鼻そうめんP]" },
                new { ValidFilename = "[Remake] Chameleon washing his hands", Filename = "[Remake] Chameleon washing his hands  Хамелеон моет лапки" },
                new { ValidFilename = "YG - My N***a (Explicit) ft. Jeezy, Rich Homie Quan", Filename = "YG - My N***a (Explicit) ft. Jeezy, Rich Homie Quan" },
                new { ValidFilename = "Dance. ParagonX9___HyperioxX", Filename = "Dance. ParagonX9___HyperioxX" },
                new { ValidFilename = "#IllyaDance DANCE  ILLYA", Filename = "#IllyaDance DANCE ☆ ILLYA ☆☆☆" },
                new { ValidFilename = "kannkore Kantai Collection", Filename = "こんごうぱーく kannkore Kantai Collection" },
                new { ValidFilename = "MV Full ver.", Filename = "임창정-문을 여시오 M/V Full ver." },
                new { ValidFilename = "I'm Gonna Build A Base", Filename = "♪ I'm Gonna Build A Base" },
                new { ValidFilename = "(HD)TV    Tamako Market ED", Filename = "(HD)【TV アニメ】 たまこまーけっと / Tamako Market ED" },
                new { ValidFilename = "MW3 xXLeGiTqUiCkSCOPEzzXx [[MLG]] ~360~ ..", Filename = "MW3 xXLeGiTqUiCkSCOPEzzXx [[MLG]] ~360~ .::." },
            };

            foreach (var test in testCases)
            {
                Assert.AreEqual(test.ValidFilename, MediaConverter.RemoveInvalidFilenameCharacters(test.Filename));
            }
        }
示例#3
0
        private async void HandleYoutubeConversion(string videoUrl)
        {
            var job = new ConversionItem
            {
                Title = videoUrl
            };

            ConversionJobs.Add(job);
            ConversionJobsListView.ScrollIntoView(job);

            #region New libvideo code.
            //// Resolve
            //job.Status = ConversionJobStatus.Resolving;
            //var queryResult = await YoutubeDownloader.QueryYoutubeVideo(link);
            //if(queryResult.IsError)
            //{
            //    job.Status = ConversionJobStatus.Error;
            //    job.StatusDetails = queryResult.Error;
            //}
            //else
            //{
            //    var video = queryResult.Value;

            //    // Download
            //    job.Status = ConversionJobStatus.Downloading;
            //    job.Title = $"{video.Title} ({video.Resolution.ToString()}p)";

            //    var downloadResult = await YoutubeDownloader.DownloadYoutubeVideo(video);
            //    if(downloadResult.IsError)
            //    {
            //        job.Status = ConversionJobStatus.Error;
            //        job.StatusDetails = downloadResult.Error;
            //    }
            //    else
            //    {
            //        var download = downloadResult.Value;

            //        // Convert
            //        job.Status = ConversionJobStatus.Converting;
            //        string filename = MediaConverter.RemoveInvalidFilenameCharacters(download.Video.Title);
            //        await MediaConverter.FFmpegConvertToWavAsync(download.Filepath, $"{Settings.OutputFolder}\\{filename}.wav", Settings.OutputBitrate, Settings.OutputVolume);

            //        // Finish
            //        job.Status = ConversionJobStatus.Done;
            //        File.Delete(download.Filepath);
            //    }
            //}
            #endregion

            // Resolve
            job.Status = ConversionJobStatus.Resolving;
            var queryResult = await YoutubeDownloader.GetYoutubeVideoInfo(videoUrl);

            if (queryResult.IsError)
            {
                job.Status        = ConversionJobStatus.Error;
                job.StatusDetails = queryResult.Error;
            }
            else
            {
                // Download
                job.Status = ConversionJobStatus.Downloading;
                var video = queryResult.Value;
                var highestQualityVersion = video.Formats
                                            .Where(v => v.AudioCodec != AudioCodec.Unkown)
                                            .OrderByDescending(info => info.Resolution)
                                            .First();
                job.Title = $"YouTube - {video.Title}";

                var downloadResult = await YoutubeDownloader.DownloadYoutubeVideo(highestQualityVersion);

                if (downloadResult.IsError)
                {
                    job.Status        = ConversionJobStatus.Error;
                    job.StatusDetails = downloadResult.Error;
                }
                else
                {
                    // Convert
                    job.Status = ConversionJobStatus.Converting;
                    var    download    = downloadResult.Value;
                    string filename    = MediaConverter.RemoveInvalidFilenameCharacters(video.Title);
                    string dstFilepath = MediaConverter.EnsureUniqueFilepath($"{Settings.OutputFolder}\\{filename}.wav");
                    await MediaConverter.FFmpegConvertToWavAsync(download.Filepath, dstFilepath, Settings.OutputFrequency, Settings.OutputVolumeMultiplier);

                    // Finish
                    job.Status = ConversionJobStatus.Done;
                    File.Delete(download.Filepath);
                }
            }
        }