Created
September 20, 2012 16:09
-
-
Save christoph-jerolimov/3756821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// javascript reimplementation of | |
// https://github.com/hellozimi/HCYoutubeParser/blob/master/YoutubeParser/Classes/HCYoutubeParser.m | |
var url = require('url'); | |
var http = require('http'); | |
var videoId = '7qpvjsMaXPE'; | |
var infoUrl = 'http://www.youtube.com/get_video_info?video_id=' + videoId; | |
var queryStringMap = function(data) { | |
var result = {}; | |
data.split('&').forEach(function(entry) { | |
result[ | |
decodeURIComponent(entry.substring(0, entry.indexOf('=')))] = | |
decodeURIComponent(entry.substring(entry.indexOf('=') + 1)); | |
}); | |
return result; | |
}; | |
var listOfQueryStringMaps = function(data) { | |
var result = []; | |
data.split(',').forEach(function(entry) { | |
result.push(queryStringMap(entry)); | |
}); | |
return result; | |
}; | |
var req = http.request(url.parse(infoUrl), function(res) { | |
if (res.statusCode != 200) { | |
console.log('Status code not 200: ' + res.statusCode); | |
process.exit(1); | |
} | |
var data = ''; | |
res.on('data', function (chunk) { | |
data += chunk; | |
}); | |
res.on('end', function () { | |
data = queryStringMap(data); | |
if (typeof data['url_encoded_fmt_stream_map'] == 'string') { | |
data['url_encoded_fmt_stream_map'] = listOfQueryStringMaps(data['url_encoded_fmt_stream_map']); | |
} | |
// console.log(JSON.stringify(data.url_encoded_fmt_stream_map, null, '\t')); | |
data.url_encoded_fmt_stream_map.forEach(function(videoEntry) { | |
//if (videoEntry.quality != 'medium') return; | |
//if (videoEntry.type.indexOf('mp4') == -1) return; | |
console.log(JSON.stringify(videoEntry, null, '\t')); | |
}); | |
}); | |
}); | |
req.on('error', function(e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req.end(); |
@Zibri this code is ~ 7 years old and I didn't tested it since then. You can expect that the YouTube "API" changed.
You should take a look into the youtube-dl
command line project. See https://github.com/ytdl-org/youtube-dl
I know youtube-dl very well thanks...It was just a comment.Maybe a line
of code can solve that.
…On Sun, 2019-07-21 at 02:01 -0700, Christoph Jerolimov wrote:
@Zibri this code is ~ 7 years old and I didn't tested it since then.
You can expect that the YouTube "API" changed.
I recommend you a look into the youtube-dl command line project. See
https://github.com/ytdl-org/youtube-dl
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
[
{
***@***.***": "http://schema.org",
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "https://gist.github.com/3756821?email_source=notifications
\u0026email_token=AAGQZCCL7DHDIHJUUASOA3LQAQQV3A5CNFSM4ID7DE7KYY3PNVW
WK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFVVCE#gistcommen
t-2976290",
"url": "https://gist.github.com/3756821?email_source=notifications\u0
026email_token=AAGQZCCL7DHDIHJUUASOA3LQAQQV3A5CNFSM4ID7DE7KYY3PNVWWK3
TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFVVCE#gistcomment-
2976290",
"name": "View Gist"
},
"description": "View this Gist on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to get the final url?
Because if i use "url" it does not work (403).
if I use url + &sig= s still 403