Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using VideoLibrary;
- namespace YoutubeDownloader
- {
- class Program
- {
- static void Main(string[] args)
- {
- YouTube youtube = YouTube.Default;
- // 19 seconds of nature slides Totaly SFW NO AUDIO too
- YouTubeVideo video = youtube.GetVideo("https://www.youtube.com/watch?v=668nUCeBHyY");
- string outFile = $"dummy2{video.FileExtension}";
- FileStream fs = new FileStream(outFile, FileMode.OpenOrCreate);
- // problem if the user started the download ,then it break at somepoint
- // I know the video is on-demand so what ever position you wanna play
- // I can get
- // but can't because the stream is a net stream and can't be seekable
- // here is what I tried
- Stream videoStream = WebRequest.Create(video.Uri).GetResponse().GetResponseStream();
- byte[] buff = new byte[1024];
- int i = 0;
- int n = 0;
- while ((n = videoStream.Read(buff, i, buff.Length)) > 0)
- {
- fs.Write(buff, i, buff.Length);
- i++;
- }
- // right now i download and get the video's like this
- using (WebClient client = new WebClient())
- {
- // I use as assync and handle events but for simplicity
- // i'm just gonna use this
- client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged);
- client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloadFInished);
- client.DownloadFileAsync(new Uri(video.Uri), outFile);
- // but I have no way of resuming or pausing
- }
- }
- private static void downloadFInished(object sender, AsyncCompletedEventArgs e)
- {
- // do something on download finshed
- }
- private static void downloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- // show progress or what ever
- }
- }
- }
Add Comment
Please, Sign In to add comment