Skip to content

Instantly share code, notes, and snippets.

@pcworld
Last active December 22, 2015 13:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pcworld/6480448 to your computer and use it in GitHub Desktop.
webOS 2.1 patch: Fix low YouTube quality and missing search results; see http://forums.webosnation.com/webos-patches/326010-patch-webos-2-fix-low-youtube-quality.html
# webOS 2.1: Fix low YouTube quality (http://forums.webosnation.com/webos-patches/326010-patch-webos-2-fix-low-youtube-quality.html)
#Copyright (c) 2013, "pcworld", 0188801@gmail.com
#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
# The search fix for webOS 2.1 in yt-api.js is by "Nafetz" from the webOS Nation forums: http://forums.webosnation.com/palm-pixi-pixi-plus/325994-palm-pixi-youtube-bug.html#post3401504
diff -burN com.palm.app.youtube_2.1.0_orig/app/controllers/common.js com.palm.app.youtube_2.1.0/app/controllers/common.js
--- /usr/palm/applications/com.palm.app.youtube/app/controllers/common.js 2010-08-06 00:32:27.000000000 +0200
+++ /usr/palm/applications/com.palm.app.youtube/app/controllers/common.js 2013-09-08 01:24:00.774587934 +0200
@@ -37,10 +37,78 @@
AppAssistant.history.insert(video);
var params = {};
- params.target = video.link;
params.title = video.title;
params.thumbUrl = video.thumbnail_240_320;
+ new Ajax.Request("http://www.youtube.com/get_video_info?video_id=" + video.id, {
+ onSuccess: function(resp) {
+ var videoInfo = resp.responseText;
+ var videoInfoSplit = videoInfo.split("&");
+ var streams;
+ 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]);
+ break;
+ }
+ }
+
+ if (!streams) {
+ var msg = "YouTube videoInfo parsing: url_encoded_fmt_stream_map not found";
+ Mojo.Log.error(msg);
+ Mojo.Controller.errorDialog(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;
+ }
+ }
+
+ if (found) {
+ Mojo.Log.info("video direct URL found: " + url);
+ params.target = url;
+ this.foundVideo(params);
+ } else {
+ var msg = "Couldn't find video in MP4 360p";
+ Mojo.Log.error(msg);
+ Mojo.Controller.errorDialog(msg);
+ return;
+ }
+ }.bind(this),
+
+ onFailure: function() {
+ var msg = "requesting get_video_info failed";
+ Mojo.Log.error(msg);
+ Mojo.Controller.errorDialog(msg);
+ return;
+ }.bind(this)
+ });
+ },
+
+ foundVideo: function(params) {
var VideoLibrary = MojoLoader.require({
name: "metascene.videos",
version: "1.0"
diff -burN com.palm.app.youtube_2.1.0_orig/app/models/yt-api.js com.palm.app.youtube_2.1.0/app/models/yt-api.js
--- /usr/palm/applications/com.palm.app.youtube/app/models/yt-api.js 2010-06-25 22:53:38.000000000 +0200
+++ /usr/palm/applications/com.palm.app.youtube/app/models/yt-api.js 2013-09-08 01:18:40.742590984 +0200
@@ -484,7 +484,7 @@
// TODO, do I ever need format 2?
// 2 - 3gp over http
// 3 - mp4 over http (H.264)
- videoFormat : 3,
+ videoFormat: 1,
// URLs
registerDeviceURL: "http://www.google.com/youtube/accounts/registerDevice"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment