Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Last active October 15, 2022 06:26
Show Gist options
  • Select an option

  • Save sheharyarn/3a6a94b277968ad13d27 to your computer and use it in GitHub Desktop.

Select an option

Save sheharyarn/3a6a94b277968ad13d27 to your computer and use it in GitHub Desktop.

Revisions

  1. sheharyarn revised this gist Jan 27, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions YoutubeDownloader.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Youtube Downloaders
    ===================

    > Download Youtube Videos using Ruby or PHP
    Just copy the appropriate script, provide the `video_id` and run. It will list download links for different qualities and streams.

    :P
  2. sheharyarn revised this gist Jan 27, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions youtube_dl.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    <?php
    // Download Videos from Youtube in PHP
    // By: Sheharyar Naseer

    $id = 'RllJtOw0USI'; // just in case

    if (isset($_GET["id"]))
  3. sheharyarn revised this gist Jan 27, 2015. 2 changed files with 34 additions and 1 deletion.
    33 changes: 33 additions & 0 deletions youtube_dl.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?php
    $id = 'RllJtOw0USI'; // just in case

    if (isset($_GET["id"]))
    $id = $_GET["id"];

    parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id='.$id), $video_data);

    $streams = $video_data['url_encoded_fmt_stream_map'];
    $streams = explode(',',$streams);
    $counter = 1;

    foreach ($streams as $streamdata) {
    printf("Stream %d:<br/>----------------<br/><br/>", $counter);

    parse_str($streamdata,$streamdata);

    foreach ($streamdata as $key => $value) {
    if ($key == "url") {
    $value = urldecode($value);
    printf("<strong>%s:</strong> <a href='%s'>video link</a><br/>", $key, $value);
    } else {
    printf("<strong>%s:</strong> %s<br/>", $key, $value);
    }
    }

    $counter = $counter+1;
    printf("<br/><br/>");
    }

    // start server and go to http://url/?id=video-id

    ?>
    2 changes: 1 addition & 1 deletion youtube_dl.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Download Videos from Youtube
    # Download Videos from Youtube in Ruby
    # By: Sheharyar Naseer

    require 'open-uri'
  4. sheharyarn created this gist Jan 26, 2015.
    45 changes: 45 additions & 0 deletions youtube_dl.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # Download Videos from Youtube
    # By: Sheharyar Naseer

    require 'open-uri'
    require 'cgi'

    def tube(id)
    'http://youtube.com/get_video_info?video_id=' + id
    end

    def get_video_data(id)
    CGI.parse open(tube(id)).read
    end

    def get_video_streams(id)
    streams = get_video_data(id)['url_encoded_fmt_stream_map'].first.split(',')
    streams.map do |s|
    x = CGI.parse s
    x.each do |k,v|
    if k == 'type'
    x[k] = v.first.split('; ')
    else
    x[k] = v.first
    end
    end
    end
    end


    # Get Videos

    video_id = "ekz-FY_MDGA"
    streams = get_video_streams(video_id)

    puts "### Total #{streams.count} streams available:\n\n"
    streams.each_with_index do |s,i|
    puts "Stream #{i+1}",
    "-------------",
    "Quality: #{s['quality']}",
    "Type: #{s['type'].first}",
    "URL: #{s['url'][0..70]}......\n\n"
    end

    puts "(Modify the code to get full urls)"