youtube download
[webos-internals:skurriers-modifications.git] / youtube / youtube-video-downloads.patch
1 diff --git a/usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js b/usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js
2 index 5c3be25..bf05551 100644
3 --- a/usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.youtube/app/controllers/video-assistant.js
5 @@ -16,7 +16,10 @@ var VideoAssistant = Class.create({
6                 // setup bottom menus
7                 this.cmdMenuModel = {items: [{label: $L('More'), submenu:'more-menu'}, 
8                                                                         {label: $L('Share'), submenu:'share-menu'}]};
9 -                                                                       
10 +               
11 +               this.moreMenuModel.items[2] = {label: $L('Download'), command:'download', disabled:false};
12 +               this.currProgress = -1;
13 +               this.controller.modelChanged(this.moreMenuModel);                                       
14                 this.controller.setupWidget('more-menu', undefined, this.moreMenuModel);
15                 this.controller.setupWidget('share-menu', undefined, this.shareMenuModel);
16                 this.controller.setupWidget(Mojo.Menu.commandMenu, {menuClass: "no-fade"}, this.cmdMenuModel);
17 @@ -69,6 +72,47 @@ var VideoAssistant = Class.create({
18                                         }});
19                                 event.stop(event);
20                         }
21 +                       else if (event.command == 'download') {
22 +                               this.moreMenuModel.items[2] = {label: $L('-Downloading-'), command:'download', disabled:true};
23 +                               this.controller.modelChanged(this.moreMenuModel);
24 +                               var filename = this.video.title;
25 +                               if(filename.length>40) { filename = filename.substring(0, 39) + "..."; }
26 +                               this.controller.serviceRequest('palm://com.palm.downloadmanager/', {
27 +                                       method: 'download',
28 +                                       parameters: {
29 +                                               target: this.video.link,
30 +                                               mime: "video/mp4",
31 +                                               targetFilename: filename + ".mp4",
32 +                                               subscribe: true
33 +                                       },
34 +                                       onSuccess: function(response) {
35 +                                               if(response.completed) {
36 +                                                       this.moreMenuModel.items[2] = {label: $L('Download'), command:'download', disabled:false};
37 +                                                       this.controller.modelChanged(this.moreMenuModel);
38 +                                                       this.controller.showBanner("Download finished!", "");
39 +                                                       /*this.controller.showAlertDialog({
40 +                                                               onChoose: function(value){},
41 +                                                               title: "Download Complete",
42 +                                                               message: "\"" + response.target + "\" downloaded successfully!",
43 +                                                               choices: [{label: "OK", value: "ok"}],
44 +                                                               allowHTMLMessage: true
45 +                                                       });*/
46 +                                               } else {
47 +                                                       if(response.amountReceived && response.amountTotal) {
48 +                                                               var percent = (response.amountReceived / response.amountTotal)*100;
49 +                                                               percent = Math.round(percent);
50 +                                                               if(percent!=NaN) {
51 +                                                                       if(this.currProgress != percent) {
52 +                                                                               this.currProgress = percent;
53 +                                                                               this.controller.showBanner("Downloading: " + percent + "%", "");
54 +                                                                       }
55 +                                                               }
56 +                                                       }
57 +                                               }
58 +                                       }.bind(this)
59 +                               });
60 +                               event.stop(event);
61 +                       }
62                         else if (event.command == 'msg' && this.video.shareLink && this.video.shareLink != "") {
63                                 this.controller.serviceRequest('luna://com.palm.applicationManager', {  
64                                                 method: 'open',
65 @@ -87,7 +131,8 @@ var VideoAssistant = Class.create({
66         moreMenuModel: {label: $L('More'), 
67                                         items: [
68                                                 {label: $L('More from This Author'), command:'more'}, 
69 -                                               {label: $L('Related Videos'), command:'related' }
70 +                                               {label: $L('Related Videos'), command:'related'},
71 +                                               {label: $L('Download'), command:'download' }
72                                         ]},
73                                         
74         shareMenuModel: {label: $L('Share'),