Last active
December 22, 2015 13:28
-
-
Save pcworld/6479028 to your computer and use it in GitHub Desktop.
webOS 2.2.4 patch: Fix low YouTube quality;
see http://forums.webosnation.com/webos-patches/326010-patch-webos-2-fix-low-youtube-quality.html
This file contains hidden or 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
# webOS-2.2.4-v2: Fix low YouTube quality (http://forums.webosnation.com/webos-patches/326010-patch-webos-2-fix-low-youtube-quality.html) | |
#Copyright (c) 2013, "pcworld", [email protected] | |
#All rights reserved. | |
# | |
#Redistribution and use in source and binary forms, with or without | |
#modification, are permitted provided that the following conditions are met: | |
# * Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# * Neither the name of the author nor the | |
# names of its contributors may be used to endorse or promote products | |
# derived from this software without specific prior written permission. | |
# | |
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
#ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
#WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY | |
#DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
#(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
#ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
#SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# This patch is based on information found on http://coding-everyday.blogspot.de/2013/03/how-to-grab-youtube-playback-video-files.html and http://userscripts.org/scripts/review/25105 | |
diff -burN com.palm.app.youtube_orig/app/controllers/home-assistant.js com.palm.app.youtube/app/controllers/home-assistant.js | |
--- /usr/palm/applications/com.palm.app.youtube/app/controllers/home-assistant.js 2011-07-09 02:53:42.000000000 +0200 | |
+++ /usr/palm/applications/com.palm.app.youtube/app/controllers/home-assistant.js 2013-09-08 20:56:49.837472384 +0200 | |
@@ -28,33 +28,86 @@ | |
videoId = videoId.substr(0, videoId.indexOf("&")); | |
} | |
- Mojo.Log.info ("findme looking up the video"); | |
- AppAssistant.api.lookupVideo(videoId, | |
- function(video) { | |
- Mojo.Log.info ("findme have the id..."); | |
- if (video) { | |
- Mojo.Log.info("Youtube: startYoutube lookupVideo video %j", video); | |
+ new Ajax.Request("http://www.youtube.com/get_video_info?video_id=" + videoId, { | |
+ onSuccess: function(resp) { | |
+ var videoInfo = resp.responseText; | |
+ var videoInfoSplit = videoInfo.split("&"); | |
+ var streams, title, thumbnail; | |
+ for (var i = 0; i < videoInfo.length; i++) { | |
+ var paramPair = videoInfoSplit[i].split("="); | |
+ if (paramPair[0] === "url_encoded_fmt_stream_map") { | |
+ streams = decodeURIComponent(paramPair[1]); | |
+ } else if (paramPair[0] === "title") { | |
+ title = decodeURIComponent(paramPair[1]).replace(/\+/g, " "); | |
+ } else if (paramPair[0] === "iurl") { // for higher quality, use "iurlsd" or even "iurlmaxres" | |
+ thumbnail = decodeURIComponent(paramPair[1]); | |
+ } | |
- //If launch parameter direct set to true then launch video directly | |
- if (this.appIsRunning) { | |
- AppAssistant.myStageController.activate(); | |
+ if (streams && title && thumbnail) | |
+ break; | |
+ } | |
+ | |
+ if (!streams) { | |
+ var msg = "YouTube videoInfo parsing: url_encoded_fmt_stream_map not found"; | |
+ Mojo.Log.error(msg); | |
+ this.closeWindowDialogue(msg); | |
+ return; | |
+ } | |
+ streamsSplit = streams.split("&"); | |
+ | |
+ // some lines contain two value pairs separated by comma | |
+ var newSplit = []; | |
+ for (var i = 0; i < streamsSplit.length; i++) { | |
+ var secondSplit = streamsSplit[i].split(","); | |
+ newSplit.push.apply(newSplit, secondSplit); | |
} | |
+ streamsSplit = newSplit; | |
+ var url, sig, itag; | |
+ var found = false; | |
+ for (var i = 0; i < streamsSplit.length; i++) { | |
+ var paramPair = streamsSplit[i].split("="); | |
+ if (paramPair[0] === "url") { | |
+ url = decodeURIComponent(paramPair[1]); | |
+ } else if (paramPair[0] === "sig") { | |
+ sig = paramPair[1]; // do not decode, as we would have to encode it later (although decoding/encoding has currently no effect for the signature) | |
+ } else if (paramPair[0] === "itag") { | |
+ itag = paramPair[1]; | |
+ } | |
+ if ((i + 1) % 6 === 0 && itag === "18") { // 6 parameters per video; itag 18 is "MP4 360p", see http://userscripts.org/scripts/review/25105 | |
+ found = true; | |
+ url += "&signature=" + sig; | |
+ break; | |
+ } | |
+ } | |
- this.foundVideo(video); | |
- //AppAssistant.common.playVideo(video); | |
+ // Palm Code: "If launch parameter direct set to true then launch video directly" | |
+ if (this.appIsRunning) { | |
+ AppAssistant.myStageController.activate(); | |
} | |
- else { | |
- Mojo.Log.error("Youtube:invalid video found"); | |
- this.closeWindowDialogue(); | |
- //window.close(); | |
+ | |
+ if (found) { | |
+ Mojo.Log.info("video direct URL found: " + url); | |
+ this.foundVideo({ | |
+ link: url, | |
+ title: title, | |
+ thumbnail_240_320: thumbnail | |
+ }); | |
+ } else { | |
+ var msg = "Couldn't find video in MP4 360p"; | |
+ Mojo.Log.error(msg); | |
+ this.closeWindowDialogue(msg); | |
+ return; | |
} | |
}.bind(this), | |
- function(err) { | |
- Mojo.Log.error("Youtube: startYoutube lookupVideo failed FUNCTION %s", err); | |
- this.closeWindowDialogue(); | |
- //window.close(); | |
- }.bind(this)); | |
+ | |
+ onFailure: function() { | |
+ var msg = "requesting get_video_info failed"; | |
+ Mojo.Log.error(msg); | |
+ this.closeWindowDialogue(msg); | |
+ return; | |
+ }.bind(this) | |
+ }); | |
}, | |
foundVideo: function(video){ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment