Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ad2213babc
Fetching contributors…

Cannot retrieve contributors at this time

244 lines (239 sloc) 8.948 kb
Update plugin.
Index: xvst-2.4.1/resources/services/youtube/youtube.js
===================================================================
--- xvst-2.4.1.orig/resources/services/youtube/youtube.js 2013-03-29 14:13:52.530353275 +0100
+++ xvst-2.4.1/resources/services/youtube/youtube.js 2013-03-29 14:14:19.214353046 +0100
@@ -3,7 +3,7 @@
* This file is part of xVideoServiceThief,
* an open-source cross-platform Video service download
*
-* Copyright (C) 2007 - 2010 Xesc & Technology
+* Copyright (C) 2007 - 2013 Xesc & Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,9 @@
function RegistVideoService()
{
- this.version = "2.1.5";
+ this.version = "3.1.1";
this.minVersion = "2.0.0a";
- this.author = "Xesc & Technology 2009";
+ this.author = "Xesc & Technology 2013";
this.website = "http://www.youtube.com/";
this.ID = "youtube.com";
this.caption = "YouTube";
@@ -38,7 +38,6 @@
function getVideoInformation(url)
{
const URL_YOUTBE = "http://www.youtube.com/watch?v=%1";
- const HD_VIDEO_RES = "22";
// init result
var result = new VideoDefinition();
// default URL
@@ -52,35 +51,89 @@
embededID = strRemove(embededID, 0, embededID.lastIndexOf("/v/") + 3);
youTubeURL = strFormat(URL_YOUTBE, embededID);
}
+ // cehck if is an embeded video (v2)
+ else if (youTubeURL.toString().indexOf("/embed/") != -1)
+ {
+ var embededID = copyBetween(youTubeURL + "?", "/embed/", "?");
+ youTubeURL = strFormat(URL_YOUTBE, embededID);
+ }
// download webpage
var http = new Http();
var html = http.downloadWebpage(youTubeURL);
+ // get cookies
+ result.cookies = http.getCookies("|");
+ // get video information
+ var videoInformationJSON = getVideoInformationJSON(html);
// get the video title
- result.title = copyBetween(html, "<title>", "</title>");
- result.title = normalizeSpaces(result.title);
+ result.title = videoInformationJSON.args.title;
// check if this video need a login
- result.needLogin = result.title == "Broadcast Yourself.";
+ result.needLogin = strIndexOf(html, 'id="verify-details"') != -1;
// if we can continue (no loggin needed)
if (result.needLogin) return result;
- // get the video info block
- var dirtyUrl = copyBetween(html, "fmt_stream_map=", "34%7Chttp");
- // we have an empty "dirtyUrl"?? if yes then we give it a second try
- if (dirtyUrl == "") dirtyUrl = copyBetween(html, "fmt_url_map=", "&") + "&";
- // get the video resolution
- var vidRes = getToken(dirtyUrl, "%7C", 0);
- // check if is a HD_VIDEO_RES (for HD videos the extension is mp4)
- if (vidRes == HD_VIDEO_RES) result.extension = ".mp4";
- // get the video url
- result.URL = getToken(dirtyUrl, "%7C", 1);
- // convert the hex codes to ascii
- result.URL = cleanUrl(result.URL);
- // remove the last "," and replace it with an "&" (if is needed)
- if (strLastIndexOf(result.URL, "&") < strLastIndexOf(result.URL, ","))
- result.URL = strRemove(result.URL, strLastIndexOf(result.URL, ","), result.URL.toString().length) + "&";
+ // get the video URL and extension
+ var videoInfo = getVideoUrlAndExtension(videoInformationJSON);
+ result.URL = videoInfo.url;
+ result.extension = videoInfo.extension;
// return the video information
return result;
}
+function getVideoInformationJSON(html)
+{
+ var playerConfig = /ytplayer.config\s*=\s*\{(.*?)\};/g;
+ return eval('({' + playerConfig.exec(html)[1] + '})');
+}
+
+function getVideoUrlAndExtension(videoInformationJSON)
+{
+ var url_encoded_fmt_stream_map = videoInformationJSON.args.url_encoded_fmt_stream_map;
+ // split into small chunks
+ var url_encoded_fmt_stream_map_arr = url_encoded_fmt_stream_map.split(",");
+ var videos_arr = new Array();
+ // get video formats
+ for (var n in url_encoded_fmt_stream_map_arr)
+ {
+ videos_arr.push(getVideoObjectFromEncodedParam(url_encoded_fmt_stream_map_arr[n]));
+ }
+ // get the first video
+ var video = videos_arr[0];
+ // init result
+ return {
+ url: video.url + "&signature=" + video.sig,
+ extension: extensionFromVideoType(getToken(video.type, ";", 0))
+ };
+}
+
+function getVideoObjectFromEncodedParam(encodedParam)
+{
+ var json = "";
+ var params_arr = encodedParam.split("&");
+ // convert each "line" into json objects
+ for (var i in params_arr)
+ {
+ json += '"' + strReplace(params_arr[i], '=', '":"') + '"';
+ if (i < params_arr.length - 1) json += ",";
+ }
+ // parse json and convert it
+ var video = eval('({' + json + '})');
+ // clean up object variables
+ for (var member in video)
+ {
+ video[member] = cleanUrl(video[member]);
+ }
+ // add this new one
+ return video;
+}
+
+function extensionFromVideoType(vtype)
+{
+ if (vtype == "video/x-flv") return ".flv";
+ if (vtype == "video/mp4") return ".mp4";
+ if (vtype == "video/webm") return ".webm";
+ // default extension
+ return ".flv";
+}
+
/*
This function "normalizeSpaces(str)" will be deprecated on next xVST version
and replaced with the new "simplifyString(str)" function (added in xVST 2.3.1)
@@ -98,85 +151,30 @@
function searchVideos(keyWord, pageIndex)
{
- const URL_SEARCH = "http://www.youtube.com/results?search_query=%1&page=%2&hl=%3";
- const HTML_SEARCH_START = "<!-- start search results -->";
- const HTML_SEARCH_FINISH = "<!-- end search results -->";
- const HTML_SEARCH_SEPARATOR = '<div class="video-entry">';
- // replace all spaces for "+"
- keyWord = strReplace(keyWord, " ", "+");
+ const URL_SEARCH = "http://gdata.youtube.com/feeds/api/videos?q=%1&orderby=published&start-index=%2&max-results=%3&v=2&alt=jsonc&hl=%4";
+ const RESULTS_COUNT = 10
// init search results object
var searchResults = new SearchResults();
+ // replace all spaces for "+"
+ keyWord = strReplace(keyWord, " ", "+");
+ // update the page index
+ var firstResult = (pageIndex - 1)*RESULTS_COUNT + 1;
// init http object
var http = new Http();
- var html = http.downloadWebpage(strFormat(URL_SEARCH, keyWord, pageIndex, searchResults.getUserLanguage()));
- // get the search summary
- var summary = copyBetween(html, '<div id="search-num-results" class="name">', '</div>');
- searchResults.setSummary(cleanSummary(summary));
- // get results html block
- var htmlResults = copyBetween(html, HTML_SEARCH_START, HTML_SEARCH_FINISH);
- // if we found some results then...
- if (htmlResults != "")
- {
- var block = "";
- // iterate over results
- while ((block = copyBetween(htmlResults, HTML_SEARCH_SEPARATOR, HTML_SEARCH_SEPARATOR)) != "")
- {
- parseResultItem(searchResults, block);
- htmlResults = strRemove(htmlResults, 0, block.toString().length);
- }
- // get last result
- parseResultItem(searchResults, htmlResults);
+ var json = http.downloadWebpage(strFormat(URL_SEARCH, keyWord, firstResult, RESULTS_COUNT, searchResults.getUserLanguage()));
+ var results = eval('(' + json + ')');
+ // set summary
+ searchResults.setSummary(results.data.totalItems + " results");
+ // fill with search results
+ for (var index in results.data.items)
+ {
+ var result = results.data.items[index];
+ searchResults.addSearchResult(result.player['default'], result.thumbnail.sqDefault, result.title, result.description, result.duration, 0);
}
// return search results
return searchResults;
}
-function cleanSummary(summary)
-{
- // remove all "\n"
- summary = strReplace(summary, "\n", "");
- // remove unused </span>
- summary = strReplace(summary, "</span>", '');
- // return cleanned summary
- return summary;
-}
-
-function parseResultItem(searchResults, html)
-{
- const VIDEO_URL = "http://www.youtube.com";
- // vars
- var tmp, videoUrl, imageUrl, title, description, duration, rating;
- // get video url
- videoUrl = VIDEO_URL + copyBetween(html, 'href="', '"');
- // get title and image url
- tmp = copyBetween(html, '<img', '>') ;
- title = copyBetween(tmp, 'title="', '"');
- imageUrl = copyBetween(tmp, 'src="', '"');
- if (strIndexOf(imageUrl, "default.jpg") == -1) // if is not a "default.jpg"...
- imageUrl = copyBetween(tmp, 'thumb="', '"');
- // get video description
- description = copyBetween(html, 'class="video-description">', '</div>');
- // get video duration
- duration = convertToSeconds(copyBetween(html, '<span class="video-time">', '</span>'));
- // get rating
- tmp = copyBetween(html, '<button class="master-sprite ratingVS', '>');
- rating = copyBetween(tmp, 'title="', '"');
- // add to results list
- searchResults.addSearchResult(videoUrl, imageUrl, title, description, duration, rating);
-}
-
-function convertToSeconds(text)
-{
- // how many ":" exists?
- var count = getTokenCount(text, ":");
- // get mins and seconds
- var h = new Number(h = count == 3 ? getToken(text, ":", 0) * 3600 : 0);
- var m = new Number(getToken(text, ":", count - 2) * 60);
- var s = new Number(getToken(text, ":", count - 1));
- // convert h:m:s to seconds
- return h + m + s;
-}
-
function getVideoServiceIcon()
{
return new Array(
Jump to Line
Something went wrong with that request. Please try again.