Skip to content

Instantly share code, notes, and snippets.

@pcworld
Last active December 22, 2015 13:28
  • 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/6479028 to your computer and use it in GitHub Desktop.
#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
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-07 21:50:13.500767536 +0200
@@ -28,33 +28,79 @@
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;
+ 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 launch parameter direct set to true then launch video directly
- if (this.appIsRunning) {
- AppAssistant.myStageController.activate();
+ 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;
- this.foundVideo(video);
- //AppAssistant.common.playVideo(video);
+ 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;
}
- else {
- Mojo.Log.error("Youtube:invalid video found");
- this.closeWindowDialogue();
- //window.close();
+ }
+
+ // Palm Code: "If launch parameter direct set to true then launch video directly"
+ if (this.appIsRunning) {
+ AppAssistant.myStageController.activate();
+ }
+
+ if (found) {
+ Mojo.Log.info("video direct URL found: " + url);
+ this.foundVideo({
+ link: url,
+ title: "",
+ thumbUrl: "https://www.google.de/intl/de_ALL/images/logos/images_logo_lg.gif"
+ });
+ } 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);
+
+ onFailure: function() {
+ Mojo.Log.error("requesting get_video_info failed");
this.closeWindowDialogue();
- //window.close();
- }.bind(this));
+ return;
+ }.bind(this)
+ });
},
foundVideo: function(video){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment