Giter VIP home page Giter VIP logo

youtubeextractor's Introduction

YoutubeExtractor

Flattr this

Overview

YoutubeExtractor is a library for .NET, written in C#, that allows to download videos from YouTube and/or extract their audio track (audio extraction currently only for flash videos).

Target platforms

  • .NET Framework 3.5 and higher
  • Windows Phone 8
  • WinRT
  • Xamarin.Android
  • Xamarin.iOS

Note that Windows Phone 8, WinRT, Xamarin.Android and Xamarin.iOS only support the extraction of the download URLs

NuGet

YoutubeExtractor at NuGet

Install-Package YoutubeExtractor

License

YoutubeExtractor has two licenses;

The YouTube URL-extraction code is licensed under the MIT License

The audio extraction code that is originally from FlvExtract is licenced under the GNU General Public License version 2 (GPLv2)

Files that are GPLv2 licensed are explicitly marked with the GPLv2 header at the top of the file. All other files are implicitly MIT licensed.

Credits

  • FlvExtract for extracting MP3 and AAC audio tracks out of flash files.

Example code

Get the download URLs

// Our test youtube link
string link = "insert youtube link";

/*
 * Get the available video formats.
 * We'll work with them in the video and audio download examples.
 */
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

Download the video

/*
 * Select the first .mp4 video with 360p resolution
 */
VideoInfo video = videoInfos
    .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);
    
/*
 * If the video has a decrypted signature, decipher it
 */
if (video.RequiresDecryption)
{
    DownloadUrlResolver.DecryptDownloadUrl(video);
}

/*
 * Create the video downloader.
 * The first argument is the video to download.
 * The second argument is the path to save the video file.
 */
var videoDownloader = new VideoDownloader(video, Path.Combine("D:/Downloads", video.Title + video.VideoExtension));

// Register the ProgressChanged event and print the current progress
videoDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage);

/*
 * Execute the video downloader.
 * For GUI applications note, that this method runs synchronously.
 */
videoDownloader.Execute();

Download the audio track

/*
 * We want the first extractable video with the highest audio quality.
 */
VideoInfo video = videoInfos
    .Where(info => info.CanExtractAudio)
    .OrderByDescending(info => info.AudioBitrate)
    .First();
    
/*
 * If the video has a decrypted signature, decipher it
 */
if (video.RequiresDecryption)
{
    DownloadUrlResolver.DecryptDownloadUrl(video);
}

/*
 * Create the audio downloader.
 * The first argument is the video where the audio should be extracted from.
 * The second argument is the path to save the audio file.
 */
var audioDownloader = new AudioDownloader(video, Path.Combine("D:/Downloads", video.Title + video.AudioExtension));

// Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
// because the download will take much longer than the audio extraction.
audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

/*
 * Execute the audio downloader.
 * For GUI applications note, that this method runs synchronously.
 */
audioDownloader.Execute();

youtubeextractor's People

Contributors

fallaciousreasoning avatar flagbug avatar georgemarshall avatar ghuntley avatar jphellemons avatar kimmax avatar maik-kluwe avatar ovnisoftware avatar pjhuck avatar scotkelly avatar shadowconsp avatar skkeeper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtubeextractor's Issues

video.Downloadurl throws 403 forbidden

I'm using a custom downloader to get the video from the url provided by youtube extractor, and it keeps throwing "403 forbidden" when trying to download the video. I've tested in 3 machines and its done the same sadly.

Add a quality indication to VideoInfo

Make it easier to download the highest quality video that's available. Some kind of quality indicator in the VideoInfo class would be nice to do this. For example use vertical resolution (360, 480,...)

Error

Hi, I have an error:

Could not parse the Youtube page.
This may be due to a change of the Youtube page structure.
Please report this bug at www.github.com/flagbug/YoutubeExtractor/issues
at YoutubeExtractor.DownloadUrlResolver.GetDownloadUrls(String videoUrl)

Gema Block leads to parsing error

When accessing a video blocked by GEMA, it throws an parsing error, instead of a more descriptive error.

This affects many videos with music when accessing them from a German IP.

Abort Download

I can't find a method to abort the execute function.

Am I missing something?

Edit:
Sorry to be a noob.

I was looking through your updates and it seems you added this a day ago.

I realize this isn't a forum but am I doing this right? :3

Does this actually cancel the download or just the progress updates?

audioDownloader.DownloadProgressChanged += audioDownloader_DownloadProgressChanged;
void audioDownloader_AudioExtractionProgressChanged(object sender, ProgressEventArgs e)
{
    if (isDownloading)
        progressBar.Value = (int)(85 + e.ProgressPercentage * 0.15);
    else
        e = e.Cancel;
    }
}

ApplicationUnhandledException

I use this code for getting urls:
IEnumerable videoInfos = null;
videoInfos = await DownloadUrlResolver.GetDownloadUrlsAsync(LinkV);
But I have error "ApplicationUnhandledException" in my application for Windows Phone 8.

403 Errors

Anyone got a fix for this?

Seems to be VEVO videos but not 100% sure.

Thanks guys

Error 403 in "Execute()"

Hello

Nice project.

But I obtain "The remote server returned an error: (403) Forbidden." in VideoDownloader.cs file on method "Execute" in line:

 using (WebResponse response = request.GetResponse())

I am executing the sample project.

Thank you very much.

Regards

Couldn't parse Youtube page.

YoutubeExtractor gives the below when I use it to download an audio of a youtube video .
Could not parse the Youtube page.
This may be due to a change of the Youtube page structure.

BTW, I use your YoutubeExtractor and combine it to my music player.
It's really convenient. Thank you very much!

issue with vevo videos ( use_cipher_signature=True )

Better error handling in downloader

VideoDownloader.Execute swallows errors. If the download results in an error, args.Error of the completion notification will be an exception and not null. You should check it, and throw the exception if necessary.

Override VideoInfo.ToString

Overriding VideoInfo.ToString makes debugging a lot easier, since when viewing a list of VideoInfos, you can tell at a glance which formats were offered. I suggest something like the following:

public override string ToString()
{
    return VideoFormat + " " + Title + VideoExtension;
}

Could not parse the Youtube page

I'm getting the following error: "Could not parse the Youtube page. this may be due to a change of the Youtube page Structure. please report this bug at ..."
for every file i try to get. since today morning

YoutubeExtractor.YoutubeParseException

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary2.get_Item(TKey key) at YoutubeExtractor.DownloadUrlResolver.<ExtractDownloadUrls>d__0.MoveNext() at YoutubeExtractor.DownloadUrlResolver.GetVideoInfos(IEnumerable1 downloadUrls, String videoTitle)
at YoutubeExtractor.DownloadUrlResolver.GetDownloadUrls(String videoUrl)
--- End of inner exception stack trace ---
at YoutubeExtractor.DownloadUrlResolver.ThrowYoutubeParseException(Exception innerException)
at YoutubeExtractor.DownloadUrlResolver.GetDownloadUrls(String videoUrl)
at Youtube_DL_GUI.Form1.DLST_Click(Object sender, EventArgs e) in D:\Wack\Src\Youtube DL GUI\Youtube DL GUI\Form1.cs:line 180
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

public static IEnumerable GetDownloadUrls ( string videoUrl );

Windows Phone 8.1 System.Net.WebException

DownloadUrlResolver.GetDownloadUrlsAsync(url); throw a System.Net.WebException on WP 8.1.
The problem is in the class HttpHelper, in the method
public static string DownloadString(string url):

request.EndGetResponse(asyncResult) throw the exception.

I fixed it by setting the user-agent of the request (user agent of google chrome):

request.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36";

for some reasons youtube seems to refuse request that have the new wp ie in the user-agent.

Sometimes the VideoDownloader will stop downloading at 99%.

This occurs when...

  • I try to download a video without releasing my Image resources.
  • I download a video successfully and then try to download another. This only happens when downloading the videos on a different thread than the main thread.

That would be great if you could fix this bug or at least have it so it doesn't crash and gives you an error.

YoutubeParseException

It was working a few days ago, now it's not.

YoutubeExtractor.YoutubeParseException was unhandled
HResult=-2146233088
Message=Could not parse the Youtube page.
This may be due to a change of the Youtube page structure.
Please report this bug at www.github.com/flagbug/YoutubeExtractor/issues
Source=YoutubeExtractor
StackTrace:
at YoutubeExtractor.DownloadUrlResolver.ThrowYoutubeParseException(Exception innerException)
at YoutubeExtractor.DownloadUrlResolver.GetDownloadUrls(String videoUrl)
at XbmcTube.Video.GetDownloader(String destination)
at XbmcTube.Channel.DownloadAll()
at XbmcTube.Program.Main(String[] args)
InnerException: System.Collections.Generic.KeyNotFoundException
HResult=-2146232969
Message=The given key was not present in the dictionary.
Source=mscorlib
StackTrace:
at System.Collections.Generic.Dictionary2.get_Item(TKey key) at YoutubeExtractor.DownloadUrlResolver.<ExtractDownloadUrls>d__0.MoveNext() at YoutubeExtractor.DownloadUrlResolver.GetVideoInfos(IEnumerable1 downloadUrls, String videoTitle)
at YoutubeExtractor.DownloadUrlResolver.GetDownloadUrls(String videoUrl)

My calling code:
public VideoDownloader GetDownloader(string destination)
{
var video = DownloadUrlResolver.GetDownloadUrls(this.watchurl).First();
return new VideoDownloader(video, destination + video.VideoExtension);
}

1080p download

Youtube disabled 1080p download, any chance to get it back in this program?

alternative approach?

Could there be an alternative approach of getting the videos (like vevo's) from the youtube?

My current workaround is taking the cache files from the firefox cache directory and merging the splits to one..

Could there be a way to implement a "browser connetion" or the signatures still will make an issue towards it?

System.Net.WebException was unhandled

To reproduce, disable network adapter during download

Stack

System.Net.WebException was unhandled
HResult=-2146233079
Message=An exception occurred during a WebClient request.
Source=YoutubeExtractor
StackTrace:
at YoutubeExtractor.VideoDownloader.<>c__DisplayClass2.b__0(Object sender, AsyncCompletedEventArgs args)
at System.Net.WebClient.OnDownloadFileCompleted(AsyncCompletedEventArgs e)
at System.Net.WebClient.DownloadFileOperationCompleted(Object arg)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException: System.IO.IOException
HResult=-2146232800
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Source=System
StackTrace:
at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.PooledStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.BeginReadWithoutValidation(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.WebClient.DownloadBitsState.RetrieveBytes(Int32& bytesRetrieved)
at System.Net.WebClient.DownloadBitsReadCallbackState(DownloadBitsState state, IAsyncResult result)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
Source=System
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
InnerException:

Huge Git Repository

Why does your repo use 26 MB? Did you accidentally commit some large files in a former revision? If so, rewriting history to remove it might be a good idea.

On Windows Phone 8 took a lot of time

I wrote this on a Windows Phone 8 app:

string link = "http://www.youtube.com/watch?v=DYW50F42ss8";
IEnumerable videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
VideoInfo video = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);

When its try to invoke the method GetDownloadUrls I need to wait a lot. What I doing wron?

403 Errors

Hi there,

Love the project...was trying to make some use of it but i can't seem to download any Vevo videos.

Looking at some of the already open issues and comments i didn't find anything that wasn't in your code already. I'm guessing the issue is with the parsing of the download string and the generated code?

Anyways for this video: http://www.youtube.com/watch?v=H8Tv9j1dqh8
I get this DownloadUrl ":

http://r4---sn-nx57ynes.c.youtube.com/videoplayback?algorithm=throttle-factor&burst=40&sver=3&sparams=algorithm,burst,cp,factor,gcr,id,ip,ipbits,itag,source,upn,expire&id=1fc4eff63d5daa1f&key=yt1&factor=1.25&expire=1376972617&ms=au&fexp=909546,906397,929117,929121,929906,929907,929922,929127,929129,929131,929930,925720,925722,925718,925714,929917,906945,929919,929933,912521,932306,913428,904830,919373,930803,908536,904122,932211,938701,911423,909549,900816,912711,935802,904494,900375,906001&itag=35&ipbits=8&mt=1376949058&gcr=ca&ip=68.179.65.121&mv=m&cp=U0hWS1lSUF9GUUNONl9RTFRHOjlNOFBtS3Y3bERy&upn=uUwzpbfT5uk&source=youtube&fallback_host=tc.v13.cache2.c.youtube.com&signature=AA73CAFE65766436B8A71A2BCDCAD472C3ABA0282.E341B7BDA6B5CF25189E6CCD17778F0341BA56A"   

Any idea how i could solve this?

Thanks for all your help.

Portable audio extraction

Hello, first thanks for the good work, keep going with the good work!
I am really able to help ether to make this, the best extraction methotd.
I have a question because i recently found this script!
You says: "Note that Windows Phone 8, WinRT, Xamarin.Android and Xamarin.iOS only support the extraction of the download URLs", this means that in wp8 i can not extract the video url to mp3?

I know that if we try to extract from flv there is no need to encode or decode the the music stream, so in wp8 we can download and extract the audio from the url?

Info

Q:
Hi.
Are you relying (as me) on gantt's GreaseMonkey script at http://userscripts.org/scripts/show/25105 ?
I'm asking, just out of curiosity, because I noticed the same method named after "DecryptSignature", in both latest versions of your sources.
Or maybe YOU are gantt, or HE looked at your souce ;)

Otherwise, I'm not sure is this is necessary, but a notice in your README would be appropriate.

getting result is too long

Hi,

just downloaded your stuff with nuget, and entered a small video url, but it is still running. already for 15-20 mins. this is the youtube video http://www.youtube.com/watch?v=ehbrEPZZnlo
wants to extract an audio from a small youtube video.
i downloaded the zipped package as well, but in VS2010 i cannot open.

thanks in advance giving me a hint what could be an issue.
Ivan

Regarding the Audio Extraction Functionality

Hi there,

I'm Essam, a developer in YouTubeFisher project; I've been following your project for a while now and like the work you're doing in this project.

I have a note though regarding the audio extraction functionality in your library. We, in YouTubeFisher, are using the excellent code from FLV Extract project by J.D. Purcell which is published under GNU-GPL. This code doesn't belong to YouTubeFisher and we do not maintain it.

It makes sense to give credit to the code author, for this reason, I've created a NuGet package FlvExtract which will be used by YouTubeFisher in the future releases and hope you reference it as well instead of bundling the code in your library.

Have a nice day.

GetDownloadUrls cannot be called concurrently

GetDownloadUrls() returns shared instances of VideoInfo. However, for each call it sets the DownloadUrl and Title properties on the shared instance. Therefore, it cannot be called concurrently, because one thread may overwrite the values returned on another.

I believe the simplest solution is to not return shared instances of VideoInfo from GetDownloadUrls().

Signature Issue

Today is looks like all signatures being 82 in lenght and Decripter is not working... I tried some things like not decripting 82 lenght but nothing.

Possible backend changes?

Could not parse the Youtube page.
This may be due to a change of the Youtube page structure.
Please report this bug at www.github.com/flagbug/YoutubeExtractor/issues

has been thrown on this youtube ID w28ZREQe3

I'm also getting error 403:forbidden from time to time

edit: it may be an error from my behalf, since im running it on a playlist and some of the links are invalid... will check this out.
apparently

it seems like it's alternatively succeeding in parsing the link, I have no idea why.
seems like it was my fault, I build the project and it replaced the new library with the old one...

Figure out ciphers automatically

For this, we need to convert this script into C#

require 'open-uri'

def decipher_function_name_pattern
  # Find "C" in this: var A = B.sig || C (B.s)
  /
  \.sig
  \s*
  \|\|
  (\w+)
  \(
  /x
end

def function_body_pattern
  # Match nested angle braces
  /
  (?<brace>
  {
  (
  [^{}]
  | \g<brace>
  )*
  }
  )
  /x
end

def function_pattern(function_name)
  # Match the function function_name (that has one argument)
  /
  #{function_name}
  \(
  \w+
  \)
  #{function_body_pattern}
  /x
end

js = open("http://s.ytimg.com/yts/jsbin/html5player-#{ARGV.first}.js").read

deciph_func_name    = js[decipher_function_name_pattern, 1]
deciph_func_pattern = function_pattern(deciph_func_name)
body_match          = deciph_func_pattern.match(js)

raise "could not extract body" unless body_match

body = body_match[:brace]

lines = body.split(";")

# The first line splits the string into an array and the last joins and returns
lines.delete_at(0)
lines.delete_at(lines.size - 1)

lines.map! do |line|
  if /\(\w+,(?<index>\d+)\)/      =~ line  # calling a two argument function (swap)
    "w#{index}"
  elsif /slice\((?<index>\d+)\)/  =~ line  # calling slice
    "s#{index}"
  elsif /reverse\(\)/             =~ line  # calling reverse
    "r"
  else
    raise "Cannot parse line: #{line}"
  end
end

cipher = lines.join(" ")
puts cipher

Application_UnhandledException - Windows Phone 8

Im trying to use Youtube Extractor on a App for Windows Phone 8 writen in VB.

When i try:
Dim videoInfos As IEnumerable(Of VideoInfo) = DownloadUrlResolver.GetDownloadUrls("Link")
the App stops responding.

Tried using GetDownloadUrls, but crashes into:
Diagnostics.Debugger.Break(), of App.xaml.vb

Public Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles Me.UnhandledException

    ' Show graphics profiling information while debugging.
    If Diagnostics.Debugger.IsAttached Then
        Diagnostics.Debugger.Break()
    Else
        e.Handled = True
        MessageBox.Show(e.ExceptionObject.Message & Environment.NewLine & e.ExceptionObject.StackTrace,
                        "Error", MessageBoxButton.OK)
    End If
End Sub

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.