Commit aab36d56b44d23a131d3973e773dcf7fba74b6e4

YouTube Video Downloads
  
1Copyright (c) 2009 Jason Robitaille <robitaille88@gmail.com>
2
3Permission is hereby granted, free of charge, to any person
4obtaining a copy of this software and associated documentation
5files (the "Software"), to deal in the Software without
6restriction, including without limitation the rights to use,
7copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the
9Software is furnished to do so, subject to the following
10conditions:
11
12The above copyright notice and this permission notice shall be
13included in all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
  
1Name: YouTube Video Downloads
2Version: 1.2.1-1
3Author: Jason Robitaille
4Description: Adds a download option for videos in the YouTube app (MIT license)
5
6--- .orig/usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js
7+++ /usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js
8@@ -15,7 +15,10 @@
9 // setup bottom menus
10 this.cmdMenuModel = {items: [{label: $L('More'), submenu:'more-menu'},
11 {label: $L('Share'), submenu:'share-menu'}]};
12-
13+
14+ this.moreMenuModel.items[2] = {label: $L('Download'), command:'download', disabled:false};
15+ this.currProgress = -1;
16+ this.controller.modelChanged(this.moreMenuModel);
17 this.controller.setupWidget('more-menu', undefined, this.moreMenuModel);
18 this.controller.setupWidget('share-menu', undefined, this.shareMenuModel);
19 this.controller.setupWidget(Mojo.Menu.commandMenu, {menuClass: "no-fade"}, this.cmdMenuModel);
20@@ -59,6 +59,47 @@
21 }
22 event.stop(event);
23 }
24+ else if (event.command == 'download') {
25+ this.moreMenuModel.items[2] = {label: $L('-Downloading-'), command:'download', disabled:true};
26+ this.controller.modelChanged(this.moreMenuModel);
27+ var filename = this.video.title;
28+ if(filename.length>40) { filename = filename.substring(0, 39) + "..."; }
29+ this.controller.serviceRequest('palm://com.palm.downloadmanager/', {
30+ method: 'download',
31+ parameters: {
32+ target: this.video.link,
33+ mime: "video/mp4",
34+ targetFilename: filename + ".mp4",
35+ subscribe: true
36+ },
37+ onSuccess: function(response) {
38+ if(response.completed) {
39+ this.moreMenuModel.items[2] = {label: $L('Download'), command:'download', disabled:false};
40+ this.controller.modelChanged(this.moreMenuModel);
41+ this.controller.showBanner("Download finished!", "");
42+ /*this.controller.showAlertDialog({
43+ onChoose: function(value){},
44+ title: "Download Complete",
45+ message: "\"" + response.target + "\" downloaded successfully!",
46+ choices: [{label: "OK", value: "ok"}],
47+ allowHTMLMessage: true
48+ });*/
49+ } else {
50+ if(response.amountReceived && response.amountTotal) {
51+ var percent = (response.amountReceived / response.amountTotal)*100;
52+ percent = Math.round(percent);
53+ if(percent!=NaN) {
54+ if(this.currProgress != percent) {
55+ this.currProgress = percent;
56+ this.controller.showBanner("Downloading: " + percent + "%", "");
57+ }
58+ }
59+ }
60+ }
61+ }.bind(this)
62+ });
63+ event.stop(event);
64+ }
65 else if (event.command == 'email' && this.video.shareLink && this.video.shareLink != "") {
66 this.controller.serviceRequest('luna://com.palm.applicationManager', {
67 method: 'open',
68@@ -86,7 +86,8 @@
69 moreMenuModel: {label: $L('More'),
70 items: [
71 {label: $L('More from This Author'), command:'more'},
72- {label: $L('Related Videos'), command:'related' }
73+ {label: $L('Related Videos'), command:'related'},
74+ {label: $L('Download'), command:'download' }
75 ]},
76
77 shareMenuModel: {label: $L('Share'),