Ejemplo n.º 1
0
        private void LoadFrame(int frame)
        {
            double pos     = (double)frame / totalFrame * video.Metadata.Duration.TotalSeconds;
            var    options = new MediaToolkit.Options.ConversionOptions {
                Seek = TimeSpan.FromSeconds(pos)
            };

            if (image != null)
            {
                image.Dispose();
                System.IO.File.Delete("temp.jpg");
            }
            try
            {
                var outputFile = new MediaToolkit.Model.MediaFile {
                    Filename = "temp.jpg"
                };
                engine.GetThumbnail(video, outputFile, options);
                LoadImage("temp.jpg");
                toolStripStatusLabel3.Text = frame.ToString() + "/" + maxFrame.ToString();
                curFrame = frame;
                int percent = (int)(100 * (double)frame / maxFrame);
                trackBar3.Value = percent;
                label6.Text     = percent.ToString() + "%";
            }
            catch (Exception)
            {
                // TODO:
            }
        }
Ejemplo n.º 2
0
        private async void button1_Click_1(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fdb = new FolderBrowserDialog()
            {
                Description = "Lütfen Kaydetmek istediğiniz klasörü seçin."
            })
            {
                if (fdb.ShowDialog() == DialogResult.OK)
                {
                    labelVideoAd.Visible = true;

                    GetVideoTitle();
                    labelStatus.Text      = "İndirme işlemi başladı. Lütfen bekleyiniz...";
                    labelStatus.ForeColor = Color.Red;
                    var yt    = YouTube.Default;
                    var video = await yt.GetVideoAsync(textBox1.Text);

                    File.WriteAllBytes(fdb.SelectedPath + @"\" + video.FullName, await video.GetBytesAsync());



                    var inputFile = new MediaToolkit.Model.MediaFile {
                        Filename = fdb.SelectedPath + @"\" + video.FullName
                    };

                    var outputFile = new MediaToolkit.Model.MediaFile {
                        Filename = $"{fdb.SelectedPath + @"\" + video.FullName}.mp3"
                    };

                    using (var enging = new Engine())
                    {
                        enging.GetMetadata(inputFile);
                        enging.Convert(inputFile, outputFile);
                    }

                    if (FormatDurum == true)
                    {
                        File.Delete(fdb.SelectedPath + @"\" + video.FullName);
                    }
                    else
                    {
                        File.Delete($"{fdb.SelectedPath + @"\" + video.FullName}.mp3");
                    }

                    labelStatus.Text      = "İndirme işlemi başarıyla tamamlandı.";
                    labelStatus.ForeColor = Color.Green;
                }
                else
                {
                    MessageBox.Show("Lütfen geçerli bir dosya yolu seçin", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 3
0
        private async void button1_Click(object sender, EventArgs e)

        //await
        {
            using (FolderBrowserDialog fdb = new FolderBrowserDialog()
            {
                Description = "Kayıt Klasörü Seç"
            })
            {
                if (fdb.ShowDialog() == DialogResult.OK)
                {
                    GetTitle();
                    labelDurum.Text      = "İndirme İşlemi Başlatıldı, Bekleyiniz.";
                    labelDurum.ForeColor = Color.Orange;
                    var youtube = YouTube.Default;
                    var video   = await youtube.GetVideoAsync(textBox1.Text);

                    File.WriteAllBytes(fdb.SelectedPath + @"\" + video.FullName, await video.GetBytesAsync());


                    var inputFile = new MediaToolkit.Model.MediaFile
                    {
                        Filename = fdb.SelectedPath + @"\" + video.FullName
                    };
                    var outputFile = new MediaToolkit.Model.MediaFile
                    {
                        Filename = $"{fdb.SelectedPath + @"\" + video.FullName}.mp3"
                    };

                    using (var enging = new Engine())
                    {
                        enging.GetMetadata(inputFile);
                        enging.Convert(inputFile, outputFile);
                    }

                    if (FormatDurum == true)
                    {
                        File.Delete(fdb.SelectedPath + @"\" + video.FullName);
                    }
                    else
                    {
                        File.Delete($"{fdb.SelectedPath + @"\" + video.FullName}.mp3");
                    }

                    labelDurum.Text      = "İndirme İşlemi Başarıyla Tamamlandı sinan !";
                    labelDurum.ForeColor = Color.Green;
                }
                else
                {
                    MessageBox.Show("Dosya Yolunu Seçin", "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 4
0
        private void button_download_Click(object sender, EventArgs e)
        {
            var source  = @"download\";
            var youtube = YouTube.Default;

            if (richTextBox_urlDownload.Text != "")
            {
                try
                {
                    var vid = youtube.GetVideo(richTextBox_urlDownload.Text);
                    File.WriteAllBytes(source + vid.FullName, vid.GetBytes());

                    var inputFile = new MediaToolkit.Model.MediaFile {
                        Filename = source + vid.FullName
                    };
                    var outputFile = new MediaToolkit.Model.MediaFile {
                        Filename = $"{source + vid.FullName}.mp3"
                    };

                    using (var engine = new Engine())
                    {
                        engine.GetMetadata(inputFile);

                        engine.Convert(inputFile, outputFile);
                    }

                    // add dtb
                    // dduongwf daanx $"{source + vid.FullName}.mp3"
                    string   path      = $"{source + vid.FullName}.mp3";
                    string[] pathSplit = path.Split('\\');
                    string   title     = pathSplit[pathSplit.Length - 1].Split('#')[0];
                    string   singer    = "youtube";
                    string   query     = "insert into dbo.song (song_path,lyric_path, image_path, name, singer, name_album, id_album ) values (N'" + path + @"',N'nonelyric.txt',N'pll_and_al_image\playlist.png', N'"
                                         + title + "',N'" + singer + "', N'Other', 6);";
                    //Console.WriteLine(query);
                    string    connectionSTR = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\nghegihomnay.mdf;Integrated Security=True";
                    DataTable data          = new DataTable();
                    using (SqlConnection connection = new SqlConnection(connectionSTR))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand(query, connection);
                        command.ExecuteNonQuery();
                        //Console.WriteLine("success");
                        connection.Close();
                    }
                    MessageBox.Show("Hoàn tất!!!", "Thông báo", MessageBoxButtons.OK);
                }
                catch (Exception)
                {
                    //MessageBox.Show("Đường dẫn không tồn tại", "Lỗi", MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 5
0
 private void LoadVideo(string path)
 {
     if (engine == null)
     {
         engine = new Engine();
     }
     video = new MediaToolkit.Model.MediaFile {
         Filename = path
     };
     engine.GetMetadata(video);
     totalFrame = (int)(video.Metadata.Duration.TotalSeconds * video.Metadata.VideoData.Fps);
     maxFrame   = totalFrame - 1;
 }
        private async void button1_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog()
            {
                Description = "Please Select Folder"
            })
            {
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    GetTitle();
                    MessageBox.Show("Download Started Please Wait.", "İnformation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    var yt    = YouTube.Default;
                    var video = await yt.GetVideoAsync(link.Text);

                    File.WriteAllBytes(fbd.SelectedPath + @"\" + video.FullName, await video.GetBytesAsync());

                    var inputfile = new MediaToolkit.Model.MediaFile {
                        Filename = fbd.SelectedPath + @"\" + video.FullName
                    };                                                                                                        //Input
                    var outputfile = new MediaToolkit.Model.MediaFile {
                        Filename = $"{fbd.SelectedPath + @"\" + video.FullName }.mp3"
                    };                                                                                                                   //Output

                    using (var enging = new Engine())
                    {
                        enging.GetMetadata(inputfile);
                        enging.Convert(inputfile, outputfile);
                    }

                    if (format == true)
                    {
                        File.Delete(fbd.SelectedPath + @"\" + video.FullName);
                    }

                    else
                    {
                        File.Delete($"{fbd.SelectedPath + @"\" + video.FullName}.mp3");
                    }

                    progressBar1.Value = 100;

                    MessageBox.Show("Download Complete.", "İnformation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Select File Path Please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Ejemplo n.º 7
0
        public string GetDuration(String file)
        {
            var inputFile = new MediaToolkit.Model.MediaFile {
                Filename = file
            };

            using (var engine = new MediaToolkit.Engine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_data/ffmpeg/ffmpeg.exe")))
            {
                engine.GetMetadata(inputFile);
            }

            TimeSpan ts = new TimeSpan(inputFile.Metadata.Duration.Ticks);

            return(ts.ToString(@"hh\:mm\:ss"));
        }
Ejemplo n.º 8
0
        private double GetDuration(Series series)
        {
            var inputFile = new MediaToolkit.Model.MediaFile {
                Filename = series.GetFullFilePathOfCurrentEpisode()
            };

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);
            }

            if (inputFile.Metadata == null)
            {
                return(0);
            }
            return(inputFile.Metadata.Duration.TotalSeconds);
        }
Ejemplo n.º 9
0
        public void laconversion2(string titulo)
        {
            if (cancelado == false)
            {
                this.Invoke((MethodInvoker) delegate
                {
                    this.pictureBox2.Visible = false;
                });

                var inputfile = new MediaToolkit.Model.MediaFile {
                    Filename = Path.Combine(direccion, titulo.Replace(".mp3", ".mp4"))
                };
                var outputfile = new MediaToolkit.Model.MediaFile {
                    Filename = Path.Combine(direccion, titulo)
                };
                MediaToolkit.Options.ConversionOptions prro = new MediaToolkit.Options.ConversionOptions();
                prro.VideoFps         = 0;
                prro.CustomHeight     = 0;
                prro.CustomWidth      = 0;
                prro.VideoAspectRatio = MediaToolkit.Options.VideoAspectRatio.R3_2;
                using (var engine = new MediaToolkit.Engine())
                {
                    engine.CustomCommand("-threads 1");
                    engine.GetMetadata(inputfile);
                    engine.Convert(inputfile, outputfile);
                }
                File.Delete(Path.Combine(direccion, titulo.Replace(".mp3", ".mp4")));
                //  var aaa = new NReco.VideoConverter.FFMpegConverter();
                //   aaa.ConvertMedia(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp3", Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp33", "mp3");

                //   File.Delete(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title) ) + ".mp3");
                // File.Move(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp33", Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp3");

                //    File.Delete(Path.Combine(direccion, RemoveIllegalPathCharacters(videox.Title)) + ".mp33");


                this.Invoke((MethodInvoker) delegate
                {
                    this.pictureBox2.Visible  = true;
                    this.pictureBox2.Location = new Point(37, 114);
                    this.pictureBox3.Visible  = true;
                    this.pictureBox3.Location = new Point(7, 114);
                });
            }
        }
Ejemplo n.º 10
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (link.Text == "")
            {
                MessageBox.Show("Link giriniz!!!", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                progress.Value          = 0;
                download_button.Enabled = false;


                var fileLoc = textBox1.Text;
                var yt      = YouTube.Default;
                var video   = await yt.GetVideoAsync(link.Text);

                progress.Value = 30;

                File.WriteAllBytes(fileLoc + video.FullName, await video.GetBytesAsync());

                progress.Value = 60;

                var mp4 = new MediaToolkit.Model.MediaFile {
                    Filename = fileLoc + video.FullName
                };
                var mp3 = new MediaToolkit.Model.MediaFile {
                    Filename = fileLoc + video.FullName + ".mp3"
                };

                using (var enging = new Engine())
                {
                    enging.GetMetadata(mp4);
                    enging.Convert(mp4, mp3);
                }

                progress.Value = 90;
                File.Delete(fileLoc + video.FullName);

                progress.Value = 100;

                MessageBox.Show($"{video.FullName}.mp3, {fileLoc} konumuna indirildi", "İşlem Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);

                download_button.Enabled = true;
            }
        }
        public static Tuple <int, int, long> GetVideoInfo(string fileName)
        {
            var inputFile = new MediaToolkit.Model.MediaFile {
                Filename = fileName
            };

            using (var engine = new Engine())
            {
                engine.GetMetadata(inputFile);
            }

            // FrameSize is returned as '1280x768' string.
            var size = inputFile.Metadata.VideoData
                       .FrameSize.Split(new[] { 'x' })
                       .Select(o => int.Parse(o)).ToArray();

            return(new Tuple <int, int, long>(size[0], size[1], inputFile.Metadata.Duration.Ticks));
        }
        public ActionResult Index(string v)  //default one id video youtube = r_aT7oYfnU8 --> mp3 file
        {
            if (!string.IsNullOrEmpty(v))
            {
                //Get video youtube from  VideoLibrary

                string pathLocal = HttpContext.Server.MapPath("~/App_Data") + "\\";  //path to save file

                var youtubeClient = YouTube.Default;
                var video         = youtubeClient.GetVideo("https://www.youtube.com/watch?v=" + v);

                //Save video to local
                System.IO.File.WriteAllBytes(pathLocal + video.FullName, video.GetBytes());


                //Convert video to mp3 use MediaToolkit

                var inputFile = new MediaToolkit.Model.MediaFile {
                    Filename = pathLocal + video.FullName
                };
                var outputFile = new MediaToolkit.Model.MediaFile {
                    Filename = $"{pathLocal + video.FullName}.mp3"
                };

                using (var engine = new Engine())
                {
                    engine.GetMetadata(inputFile);
                    engine.Convert(inputFile, outputFile);
                }

                System.IO.File.Delete(inputFile.Filename);

                //Create action to dowload file mp3
                ViewBag.FileNameDownload = video.FullName + ".mp3";
            }

            return(View());
        }
Ejemplo n.º 13
0
		public static void Remux( string targetName, string sourceName, string tempName ) {
			Directory.CreateDirectory( Path.GetDirectoryName( targetName ) );
			Console.WriteLine( "Remuxing to " + targetName + "..." );
			var inputFile = new MediaToolkit.Model.MediaFile( sourceName );
			var outputFile = new MediaToolkit.Model.MediaFile( tempName );
			using ( var engine = new MediaToolkit.Engine( "ffmpeg.exe" ) ) {
				MediaToolkit.Options.ConversionOptions options = new MediaToolkit.Options.ConversionOptions();
				options.AdditionalOptions = "-codec copy -bsf:a aac_adtstoasc";
				engine.Convert( inputFile, outputFile, options );
			}
			Util.MoveFileOverwrite( tempName, targetName );
			Console.WriteLine( "Created " + targetName + "!" );
		}
Ejemplo n.º 14
0
        public async Task FileDataToGrid(string[] FilePathList)
        {
            await Task.Run(() =>
            {
                int itemCount          = 0;
                TimeSpan timeLeft      = new TimeSpan();
                Engine mediaInfoEngine = new Engine();

                foreach (string item in FilePathList)
                {
                    if (ListOfPathsFilsInGrid.Contains(item) || !File.Exists(item))
                    {
                        continue;
                    }
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    Dispatcher.Invoke(() =>
                    {
                        Helper.ChangeStatusControl($"Przetwarzanie pliku {++itemCount} / {FilePathList.Length} ({timeLeft.Seconds}s {timeLeft.Milliseconds}ms)", true);
                    });



                    FileInfo fi = new FileInfo(item);
                    MediaToolkit.Model.MediaFile mf = new MediaToolkit.Model.MediaFile()
                    {
                        Filename = item
                    };

                    using (mediaInfoEngine)
                        mediaInfoEngine.GetMetadata(mf);

                    MediaFile mf2 = new MediaFile();

                    try
                    {
                        mf2.Bitrate    = Helper.GetBitrateFromFFMPEG(item);
                        mf2.Name       = fi.Name;
                        mf2.Path       = fi.FullName;
                        mf2.Extension  = fi.Extension;
                        mf2.Size       = Helper.DecorateBytes(fi.Length);
                        mf2.Format     = mf.Metadata.VideoData.Format;
                        mf2.ColorGamut = mf.Metadata.VideoData.ColorModel;
                        mf2.FPS        = mf.Metadata.VideoData.Fps;
                        mf2.FrameSize  = mf.Metadata.VideoData.FrameSize;
                        mf2.Duration   = mf.Metadata.Duration.ToString($"hh\\:mm\\:ss");

                        Dispatcher.Invoke(new Action(() =>
                        {
                            DG_Main.Items.Add(mf2);
                        }));
                    }
                    catch (Exception exc)
                    {
                        continue;
                    }
                    finally
                    {
                        sw.Stop();
                        timeLeft += sw.Elapsed;
                    }
                }
            });

            Helper.ResetStatusControl();
        }
Ejemplo n.º 15
0
        private async void btnDownload_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fdb = new FolderBrowserDialog()
            {
                Description = "Select Folder Please"
            })
            {
                if (fdb.ShowDialog() == DialogResult.OK)
                {
                    MessageBox.Show("Folder Selected", "Selection", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    progressBar1.Value = 10;
                    var yt = YouTube.Default;
                    progressBar1.Value += 10;
                    YouTubeVideo video;
                    try
                    {
                        video = await yt.GetVideoAsync(txtAddress.Text);

                        progressBar1.Value += 10;
                        File.WriteAllBytes(fdb.SelectedPath + @"\" + video.FullName, await video.GetBytesAsync());
                        progressBar1.Value += 10;
                        var inputFile  = new MediaToolkit.Model.MediaFile(filename: fdb.SelectedPath + @"\" + video.FullName);
                        var outputfile = new MediaToolkit.Model.MediaFile(filename: $"{ fdb.SelectedPath + @"\" + video.FullName}.mp3");
                        progressBar1.Value += 20;
                        using (var engine = new Engine())
                        {
                            engine.GetMetadata(inputFile);
                            engine.Convert(inputFile, outputfile);
                        }
                        progressBar1.Value += 20;
                        if (formate)
                        {
                            File.Delete(fdb.SelectedPath + @"\" + video.FullName);
                        }

                        else
                        {
                            File.Delete($"{fdb.SelectedPath + @"\" + video.FullName}.mp3");
                        }
                        progressBar1.Value += 20;
                        success.Visible     = true;
                        Thread.Sleep(1000);
                        progressBar1.Value = 0;
                        success.Visible    = false;
                    }
                    catch (Exception ex)
                    {
                        txtAddress.Text = "";
                        MessageBox.Show("not valid url");
                        failed.Visible = true;
                        Thread.Sleep(1000);
                        progressBar1.Value = 0;
                        failed.Visible     = false;
                    }
                }
                else
                {
                    failed.Visible = true;
                    Thread.Sleep(1000);
                    progressBar1.Value = 0;
                    failed.Visible     = false;
                }
            }
        }