/[gentoo-x86]/media-video/xvideoservicethief/files/xvideoservicethief-2.4.1-youtube-api.patch
Gentoo

Contents of /media-video/xvideoservicethief/files/xvideoservicethief-2.4.1-youtube-api.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Sun Aug 14 13:11:31 2011 UTC (3 years, 1 month ago) by hwoarang
Branch: MAIN
add patch from upstream svn repository to fix youtube plugin

(Portage version: 2.2.0_alpha50/cvs/Linux x86_64)

1 --- resources/services/youtube/youtube.js 2010/09/02 11:52:07 911
2 +++ resources/services/youtube/youtube.js 2011/08/06 23:30:28 961
3 @@ -3,7 +3,7 @@
4 * This file is part of xVideoServiceThief,
5 * an open-source cross-platform Video service download
6 *
7 -* Copyright (C) 2007 - 2010 Xesc & Technology
8 +* Copyright (C) 2007 - 2011 Xesc & Technology
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 @@ -25,9 +25,9 @@
13
14 function RegistVideoService()
15 {
16 - this.version = "2.1.5";
17 + this.version = "3.0.1";
18 this.minVersion = "2.0.0a";
19 - this.author = "Xesc & Technology 2009";
20 + this.author = "Xesc & Technology 2011";
21 this.website = "http://www.youtube.com/";
22 this.ID = "youtube.com";
23 this.caption = "YouTube";
24 @@ -55,32 +55,103 @@
25 // download webpage
26 var http = new Http();
27 var html = http.downloadWebpage(youTubeURL);
28 + // get cookies
29 + result.cookies = http.getCookies("|");
30 // get the video title
31 result.title = copyBetween(html, "<title>", "</title>");
32 result.title = normalizeSpaces(result.title);
33 + result.title = strReplace(result.title, "\n", "");
34 + result.title = strReplace(result.title, " - YouTube", "");
35 // check if this video need a login
36 - result.needLogin = result.title == "Broadcast Yourself.";
37 + result.needLogin = strIndexOf(html, "signing_in") != -1;
38 // if we can continue (no loggin needed)
39 if (result.needLogin) return result;
40 - // get the video info block
41 - var dirtyUrl = copyBetween(html, "fmt_stream_map=", "34%7Chttp");
42 - // we have an empty "dirtyUrl"?? if yes then we give it a second try
43 - if (dirtyUrl == "") dirtyUrl = copyBetween(html, "fmt_url_map=", "&") + "&";
44 - // get the video resolution
45 - var vidRes = getToken(dirtyUrl, "%7C", 0);
46 - // check if is a HD_VIDEO_RES (for HD videos the extension is mp4)
47 - if (vidRes == HD_VIDEO_RES) result.extension = ".mp4";
48 - // get the video url
49 - result.URL = getToken(dirtyUrl, "%7C", 1);
50 - // convert the hex codes to ascii
51 - result.URL = cleanUrl(result.URL);
52 - // remove the last "," and replace it with an "&" (if is needed)
53 - if (strLastIndexOf(result.URL, "&") < strLastIndexOf(result.URL, ","))
54 - result.URL = strRemove(result.URL, strLastIndexOf(result.URL, ","), result.URL.toString().length) + "&";
55 + // get the video URL and extension
56 + var videoInfo = getVideoUrlAndExtension(html);
57 + result.URL = videoInfo.url;
58 + result.extension = videoInfo.extension;
59 // return the video information
60 return result;
61 }
62
63 +function getVideoUrlAndExtension(html)
64 +{
65 + // init result
66 + var result = { url:null, extension:null };
67 + // get the flashVars value
68 + var flashVars = "?" + copyBetween(html, 'flashvars="', '"');
69 + // convert each "&amp;" into "&"
70 + flashVars = strReplace(flashVars, "&amp;", "&");
71 + // get an array with all fmt_stream_map values
72 + var fmt_stream_map_arr = splitString(getUrlParam(flashVars, "url_encoded_fmt_stream_map"), "url%3D", false);
73 + // default selected video quality
74 + var selectedFormat = -1;
75 + // detect the better quality
76 + for (var n = 0; n < fmt_stream_map_arr.length && selectedFormat == -1; n++)
77 + {
78 + fmt_stream_map_arr[n] = "?url=" + cleanUrl(fmt_stream_map_arr[n]).toString();
79 + // remove the last "," (if exists)
80 + if (strLastIndexOf(fmt_stream_map_arr[n], ",") == fmt_stream_map_arr[n].toString().length - 1)
81 + fmt_stream_map_arr[n] = strRemove(fmt_stream_map_arr[n], fmt_stream_map_arr[n].toString().length - 1, 1);
82 + // check video type
83 + var vtype = getToken(getUrlParam(fmt_stream_map_arr[n], "type"), ";", 0);
84 + // is known format?
85 + if (vtype == "video/x-flv" || vtype == "video/mp4")
86 + {
87 + selectedFormat = n;
88 + // configure video extension
89 + result.extension = extensionFromVideoType(vtype);
90 + }
91 + }
92 + // no format selected?
93 + if (selectedFormat == -1) selectedFormat = 0;
94 + // get the host url
95 + var urlHost = getToken(fmt_stream_map_arr[selectedFormat], "?", 1);
96 + urlHost = strReplace(urlHost, "url=", "");
97 + // leave only the parameters
98 + fmt_stream_map_arr[selectedFormat] = getToken(fmt_stream_map_arr[selectedFormat], "?", 2);
99 + // get url parts
100 + var urlParts = splitString(fmt_stream_map_arr[selectedFormat], "&", false);
101 + // set the url host
102 + result.url = urlHost + "?";
103 + // build the initial url
104 + for (var n = 0; n < urlParts.length; n++)
105 + {
106 + var pname = getToken(urlParts[n], "=", 0).toString();
107 + var pvalue = getToken(urlParts[n], "=", 1).toString();
108 + var duplicatedPname = strIndexOf(result.url, pname + "=") != -1;
109 + // is an excluded param?
110 + if (!duplicatedPname && pname != "fexp" && pname != "quality" && pname != "fallback_host" && pname != "type")
111 + result.url += pname + "=" + pvalue + "&";
112 + }
113 + // remove the last &
114 + if (strLastIndexOf(result.url, "&") == result.url.length - 1)
115 + urlInitial = strRemove(result.url, result.url.length - 1, 1);
116 + // get extra (optional) params
117 + var ptchn = getUrlParam(flashVars, "ptchn");
118 + if (ptchn != "") result.url += "ptchn=" + ptchn + "&";
119 + var ptk = getUrlParam(flashVars, "ptk");
120 + if (ptk != "") result.url += "ptk=" + ptk;
121 + // configure the video extension (if is not yet configured)
122 + if (!result.extension)
123 + {
124 + var vtype = getToken(getUrlParam(fmt_stream_map_arr[selectedFormat], "type"), ";", 0);
125 + // configure video extension
126 + result.extension = extensionFromVideoType(vtype);
127 + }
128 + // return
129 + return result;
130 +}
131 +
132 +function extensionFromVideoType(vtype)
133 +{
134 + if (vtype == "video/x-flv") return ".flv";
135 + if (vtype == "video/mp4") return ".mp4";
136 + if (vtype == "video/webm") return ".webm";
137 + // default extension
138 + return ".flv";
139 +}
140 +
141 /*
142 This function "normalizeSpaces(str)" will be deprecated on next xVST version
143 and replaced with the new "simplifyString(str)" function (added in xVST 2.3.1)
144 @@ -99,9 +170,11 @@
145 function searchVideos(keyWord, pageIndex)
146 {
147 const URL_SEARCH = "http://www.youtube.com/results?search_query=%1&page=%2&hl=%3";
148 - const HTML_SEARCH_START = "<!-- start search results -->";
149 - const HTML_SEARCH_FINISH = "<!-- end search results -->";
150 - const HTML_SEARCH_SEPARATOR = '<div class="video-entry">';
151 + const HTML_SEARCH_START = '<div id="search-results">';
152 + const HTML_SEARCH_FINISH = '<span id="search-pva-content">';
153 + const HTML_SEARCH_SEPARATOR = '<div class="result-item *sr ">';
154 + const HTML_SEARCH_SUMMARY_START = '<p class="num-results">';
155 + const HTML_SEARCH_SUMMARY_END = '</p>';
156 // replace all spaces for "+"
157 keyWord = strReplace(keyWord, " ", "+");
158 // init search results object
159 @@ -110,7 +183,7 @@
160 var http = new Http();
161 var html = http.downloadWebpage(strFormat(URL_SEARCH, keyWord, pageIndex, searchResults.getUserLanguage()));
162 // get the search summary
163 - var summary = copyBetween(html, '<div id="search-num-results" class="name">', '</div>');
164 + var summary = copyBetween(html, HTML_SEARCH_SUMMARY_START, HTML_SEARCH_SUMMARY_END);
165 searchResults.setSummary(cleanSummary(summary));
166 // get results html block
167 var htmlResults = copyBetween(html, HTML_SEARCH_START, HTML_SEARCH_FINISH);
168 @@ -148,14 +221,17 @@
169 var tmp, videoUrl, imageUrl, title, description, duration, rating;
170 // get video url
171 videoUrl = VIDEO_URL + copyBetween(html, 'href="', '"');
172 - // get title and image url
173 + // get image url
174 tmp = copyBetween(html, '<img', '>') ;
175 - title = copyBetween(tmp, 'title="', '"');
176 imageUrl = copyBetween(tmp, 'src="', '"');
177 if (strIndexOf(imageUrl, "default.jpg") == -1) // if is not a "default.jpg"...
178 imageUrl = copyBetween(tmp, 'thumb="', '"');
179 + imageUrl = "http:" + imageUrl;
180 + // get video title
181 + title = copyBetween(html, 'dir="ltr" title="', '"');
182 // get video description
183 - description = copyBetween(html, 'class="video-description">', '</div>');
184 + description = copyBetween(html, '<p id="video-description-', '</p>');
185 + description = copyBetween(description + '|', '>', '|');
186 // get video duration
187 duration = convertToSeconds(copyBetween(html, '<span class="video-time">', '</span>'));
188 // get rating

  ViewVC Help
Powered by ViewVC 1.1.20