Ejemplo n.º 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.OutputBitrate, Settings.OutputVolume);

            // Finish
            job.Status = ConversionJobStatus.Done;
        }
Ejemplo n.º 2
0
        private async void HandleYoutubeConversion(string link)
        {
            var job = new ConversionItem
            {
                Title = link
            };

            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.QueryYoutubeVideoOld(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.DownloadYoutubeVideoOld(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(video.Title);
                    string dstFilepath = MediaConverter.EnsureUniqueFilepath($"{Settings.OutputFolder}\\{filename}.wav");
                    await MediaConverter.FFmpegConvertToWavAsync(download.Filepath, dstFilepath, Settings.OutputBitrate, Settings.OutputVolume);

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