Permalink
Browse files

fix parsing stream map properly

  • Loading branch information...
1 parent 9818863 commit e504cc5e37df5f3a2b01992106e1ed6becac86ac @fent committed Aug 22, 2012
Showing with 18 additions and 30 deletions.
  1. +15 −28 lib/index.js
  2. +2 −1 test/files/info1.json
  3. +1 −1 test/files/video1.html
View
@@ -178,46 +178,33 @@ ytdl.getInfo = function getInfo(link, requestOptions, callback) {
}
});
- // a few more manual data cleansing
- var fmt_map = info.url_encoded_fmt_stream_map =
- qs.parse(info.url_encoded_fmt_stream_map);
-
- fmt_map.itag = fmt_map.itag
- .map(function(itag) {
- var split = itag.split(',');
- return { itag: split[0], url: split[1] ? split[1].slice(4) : null };
- })
- ;
-
- info.fmt_list = info.fmt_list.map(function(fmt) {
- return fmt.split('/');
+ info.fmt_list = info.fmt_list.map(function(format) {
+ return format.split('/');
});
- info.formats = info.fmt_list
- .map(function(format, i) {
- var itag = format[0];
- format = FORMATS[itag];
+ info.formats = info.url_encoded_fmt_stream_map
+ .split(',')
+ .map(function(format) {
+ var data = qs.parse(format);
+ format = FORMATS[data.itag];
if (!format) {
- err = new Error('Unrecognized format itag: ' + itag);
+ err = new Error('No suck format for itag ' + data.itag + ' found');
return;
}
- format = Hash.copy(format);
- format.quality = fmt_map.quality[i];
- format.fallback_host = fmt_map.fallback_host[i];
- format.type = fmt_map.type[i];
- format.url = fmt_map.itag[i].url;
+ Hash(format).forEach(function(val, key) {
+ data[key] = val;
+ });
- return format;
- })
- .filter(function(format) {
- return !!format.url;
+ return data;
})
;
+ delete info.url_encoded_fmt_stream_map;
+
if (err) {
- callback(err);
+ return callback(err);
}
info.video_verticals = info.video_verticals
Oops, something went wrong.

0 comments on commit e504cc5

Please sign in to comment.