Another YouTube Downloader js
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
// ==UserScript== // @name Another YouTube Downloader // @version 1.2.7 // @namespace http://pradip.x10.mx/ // @author Pradip Vadher // @license GPL3+ (http://www.gnu.org/copyleft/gpl.html) // @description Download now playing video in available formats. // @include http://*.youtube.com/* // @include https://*.youtube.com/* // @exclude http://m.youtube.com/* // @exclude https://m.youtube.com/* // @grant GM_log // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_registerMenuCommand // @grant unsafeWindow // ==/UserScript== /* Changelog for SourceForge: v1.1.9: -> Initial version on SourceForge. v1.2.0: -> CSS fixed for buttons. -> Some debug information added. v1.2.1 -> NoScript supported again. Works without JavaScript enabled. v1.2.2 -> Some fixes -> One more method added to find download links. 5 methods to find them all. v1.2.3 -> Tooltips styled. v1.2.4 -> New layout support. v1.2.5 -> Two new preferences: Enable/Disable ToolTips and Sort/Unsort Video Formats. -> New "signature" flashvar added. -> grants added for new Greasemonkey versions. v1.2.6 -> Bug fix: Only first link was working. V1.2.7 -> Bug fix: No title on new layout. */ /* YouTube urls to test * Blocked in USA: https://www.youtube.com/watch?v=1UR6klggoJo * Another: https://www.youtube.com/watch?v=F4P3j8dh2ro * Embed disabled: https://www.youtube.com/watch?v=7vMUvgce_5s * Slash in filename: https://www.youtube.com/watch?v=JL6Wasm2J-8 * RTMPE Streaming: https://www.youtube.com/watch?v=R9upjxi7_lk * No embed: https://www.youtube.com/watch?v=Rb43gnZI1A0 */ var AnotherYouTubeDownloaderTranslation = {}; AnotherYouTubeDownloaderTranslation = { // You can add your own translation. Debug strings, video properties and helper application strings are not translated. strTranslations: { "en" : { // English 0: "LQ Download button is shown.nnPress OK to hide.", 1: "LQ Download button is not shown.nnPress OK to show. (Needs refresh)", 2: "Add mobile compatible links to download links", 3: "LQ", 4: "LQ Download", 5: "Loading", 6: "Unable to fetch links. Try again.", 7: "Unknown", 8: "Download this video", 9: "Download", 10: "Stream", 11: "Show/Hide LQ Download Button", 12: "Enable/Disable ToolTips", 13: "Press OK to disable ToolTips. (Needs refresh)", 14: "Press OK to enable ToolTips. (Needs refresh)", 15: "Sort/Unsort Formats", 16: "Press OK to sort formats. (Needs refresh)", 17: "Press OK to unsort formats. (Needs refresh)" }, "sms" : { // SMS 0: "LQDL is shown.nnPress OK to hide.", 1: "LQDL is hidden.nnPress OK to show.", 2: "Mob links", 3: "LQ", 4: "LQDL", 5: "Wait", 6: "Err. Retry.", 7: "?", 8: "DL", 9: "DL", 10: "STRM", 11: "LQDL Config", 12: "ToolTips", 13: "Press OK to disable ToolTips.", 14: "Press OK to enable ToolTips.", 15: "Sort/Unsort Fmt", 16: "Press OK to sort formats.", 17: "Press OK to unsort formats." } }, getLanguage: function () { var preferedLanguage = "", strUserLang; // Set preferedLanguage to your prefered language short, like preferedLanguage="sms"; if (preferedLanguage.length !== 0) { strUserLang = preferedLanguage; } else if (navigator && navigator.language) { strUserLang = navigator.language.toLowerCase(); } else { strUserLang = "en"; } if (strUserLang.indexOf("-") !== -1 && !AnotherYouTubeDownloaderTranslation.strTranslations[strUserLang]) { strUserLang = strUserLang.substring(0, strUserLang.indexOf("-")); } if (!AnotherYouTubeDownloaderTranslation.strTranslations[strUserLang]) { strUserLang = "en"; } return strUserLang; }, getTranslation:function (id) { return AnotherYouTubeDownloaderTranslation.strTranslations[AnotherYouTubeDownloaderTranslation.getLanguage()][id]; } }; Logger={ blLog: false, LOG_TYPE_CONSOLE: 0, LOG_TYPE_GM_LOG: 1, LOG_TYPE_ALERT: 2, LOG_TYPE_GM_ALERT: 3, log: function (strMessage, intType){ if(Logger.blLog==false) return; switch(intType){ case Logger.LOG_TYPE_GM_LOG: if(typeof GM_log!="undefined"){ GM_log(strMessage); break; } else { Logger.log(strMessage, Logger.LOG_TYPE_CONSOLE); } case Logger.LOG_TYPE_CONSOLE: if(typeof console != "undefined" && console.log) console.log(strMessage); else Logger.log(strMessage, Logger.LOG_TYPE_ALERT); break; case Logger.LOG_TYPE_ALERT: if(typeof unsafeWindow!="undefined" && unsafeWindow.alert){ unsafeWindow.alert(strMessage); break; } else { Logger.log(strMessage, Logger.LOG_TYPE_GM_ALERT); } case Logger.LOG_TYPE_GM_ALERT: // Don't use for too many alerts alert(strMessage); break; } }, space: function (intTimes){ if(Logger.blLog==false) return "[Logger Disabled]"; var strReturn=""; for(var i=0;i<intTimes;i++){ strReturn+=" "; } return strReturn; }, formatArray: function (aArray, intLevel){ if(Logger.blLog==false) return "[Logger Disabled]"; if(!intLevel) intLevel=0; var strReturn=Logger.space(intLevel)+"["; for(var i in aArray){ if(typeof aArray[i]!="string" && aArray[i].length) strReturn+=formatArray(aArray[i], intLevel+1); else strReturn+=Logger.space(intLevel+1)+"n"+i+": '"+aArray[i]+"',"; } strReturn+="n]"; return strReturn; } }; AnotherYouTubeDownloader={ blHelperInstalled: false, // Helper finds the file size of video without downloading. $: function(id){ if(document && document.getElementById) return document.getElementById(id); else return null; }, $$: function(tag){ if(document && document.getElementsByTagName) return document.getElementsByTagName(tag); else return null; }, isWatchPage: function(){ return (location.pathname.indexOf("/watch")==0); }, isUserChannelPage: function(){ return (!AnotherYouTubeDownloader.isWatchPage() && (location.pathname.indexOf("/user")==0 || AnotherYouTubeDownloader.$("playnav-title-bar"))); }, isGreasemonkey: function(){ try{ if(typeof GM_getValue!="undefined" && GM_getValue("test","test")){ return true; } else { return false; } }catch(e){ return false; } }, fetchDownloadLinks: function(){ if(AnotherYouTubeDownloader.$("table-download-menu")) return; if (AnotherYouTubeDownloader.isUserChannelPage()){ if(document.body.removeEventListener) document.body.removeEventListener("DOMNodeInserted",AnotherYouTubeDownloader.domChanged,false); } var divEmbed=AnotherYouTubeDownloader.$$("embed"); var divVideos=AnotherYouTubeDownloader.$$("video"); if(divEmbed.length>0) divEmbed=divEmbed[0]; else divEmbed=null; var blLinksAdded=false; // Method 1: Find from <embed> tag. if(blLinksAdded==false && divEmbed && divEmbed.getAttribute("flashvars")) { try{ AnotherYouTubeDownloader.putDownloadLinksFromFlashVars(divEmbed.getAttribute("flashvars")); if(AnotherYouTubeDownloader.$("table-download-menu")){ if(divEmbed.getAttribute("flashvars").indexOf("cc_module")!=-1) AnotherYouTubeDownloader.addDownloadLink("http://www.youtube.com/api/timedtext?name=&format=1&hl=en&type=track&lang=en&v="+AnotherYouTubeDownloader.getVidId()+"&kind=","text/xml","Subtitles","x",0,"x"); blLinksAdded=true; } }catch(e){ Logger.log("Error while adding links from embed->flashvars: "+e, Logger.LOG_TYPE_ALERT); } } if(blLinksAdded==false){ Logger.log("Unable to find links from embed->flashvars .", Logger.LOG_TYPE_CONSOLE); Logger.log("Trying to find links from yt.config_->flashvars .", Logger.LOG_TYPE_CONSOLE); } // Method 2: Find from yt object set by page js if (blLinksAdded==false && (window.yt || (typeof unsafeWindow != "undefined" && unsafeWindow.yt))) { try{ var yt; if(window.yt) yt=window.yt; else yt=unsafeWindow.yt; if(yt.config_ && yt.config_.PLAYER_CONFIG && yt.config_.PLAYER_CONFIG.args && yt.config_.PLAYER_CONFIG.args.fmt_list && yt.config_.PLAYER_CONFIG.args.url_encoded_fmt_stream_map){ AnotherYouTubeDownloader.putDownloadLinks(yt.config_.PLAYER_CONFIG.args.fmt_list, yt.config_.PLAYER_CONFIG.args.url_encoded_fmt_stream_map); } if(AnotherYouTubeDownloader.$("table-download-menu")){ if(yt.config_.PLAYER_CONFIG.args.cc_module) AnotherYouTubeDownloader.addDownloadLink("http://www.youtube.com/api/timedtext?name=&format=1&hl=en&type=track&lang=en&v="+AnotherYouTubeDownloader.getVidId()+"&kind=","text/xml","Subtitles","?",0,"?"); blLinksAdded=true; } }catch(e){ Logger.log("Error while adding links from yt.config_->flashvars: "+e, Logger.LOG_TYPE_ALERT); } } if (blLinksAdded==false) { Logger.log("Unable to find links from yt.config_->flashvars .", Logger.LOG_TYPE_CONSOLE); Logger.log("Trying to find links from js embed->flashvars .", Logger.LOG_TYPE_CONSOLE); } // Method 3: Find from <embed> tag in js, but not executed, only for NoScript if (blLinksAdded==false && document.scripts.length>0){ try{ for(var i=0;i<document.scripts.length;i++){ var scriptCode=document.scripts[i].innerHTML; if(scriptCode.indexOf("fmt_list=")!=-1 && scriptCode.indexOf("url_encoded_fmt_stream_map=")!=-1){ //scriptCode=scriptCode.replace(/\/g, ""); scriptCode=scriptCode.replace(/\//g, "/").replace(/\u0026/g, "&"); //scriptCode=unescape(unescape(unescape(scriptCode))); AnotherYouTubeDownloader.putDownloadLinksFromFlashVars(scriptCode); } } if(AnotherYouTubeDownloader.$("table-download-menu")){ blLinksAdded=true; } }catch(e){ Logger.log("Error while adding links from js embed->flashvars: "+e, Logger.LOG_TYPE_ALERT); } } if (blLinksAdded==false){ Logger.log("Unable to find links from js embed->flashvars .", Logger.LOG_TYPE_CONSOLE); Logger.log("Trying to find links from javascript->flashvars.", Logger.LOG_TYPE_CONSOLE); } // Method 4: Find from yt object in js, not executed or removed by js if (blLinksAdded==false && document.scripts.length>0){ try{ for(var i=0;i<document.scripts.length;i++){ var scriptCode=document.scripts[i].innerHTML; if(scriptCode.indexOf(""fmt_list":")!=-1 && scriptCode.indexOf(""url_encoded_fmt_stream_map":")!=-1){ var fmt_list=scriptCode.substr(scriptCode.indexOf(""fmt_list":")+(""fmt_list":").length).trim(); fmt_list=fmt_list.substring(1, fmt_list.substr(1).indexOf(""")+1); fmt_list=fmt_list.replace(/\//g, "/").replace(/\u0026/g, "&"); var fmt_stream_map=scriptCode.substr(scriptCode.indexOf(""url_encoded_fmt_stream_map":")+(""url_encoded_fmt_stream_map":").length).trim(); fmt_stream_map=fmt_stream_map.substring(1, fmt_stream_map.substr(1).indexOf(""")+1); fmt_stream_map=fmt_stream_map.replace(/\//g, "/").replace(/\u0026/g, "&"); AnotherYouTubeDownloader.putDownloadLinks(fmt_list, fmt_stream_map); } } if(AnotherYouTubeDownloader.$("table-download-menu")){ blLinksAdded=true; } }catch(e){ Logger.log("Error while adding links from javascript->flashvars: "+e, Logger.LOG_TYPE_ALERT); } } if (blLinksAdded==false){ Logger.log("Unable to find links from javascript->flashvars .", Logger.LOG_TYPE_CONSOLE); Logger.log("Trying to find links from HTML5 Video.", Logger.LOG_TYPE_CONSOLE); } // Method 5: Find from <video> tag if (blLinksAdded==false && divVideos.length>0){ try{ for(var i=0;i<divVideos.length;i++){ if(divVideos[i].src) AnotherYouTubeDownloader.addLink(divVideos[i].src); } if(AnotherYouTubeDownloader.$("table-download-menu")) blLinksAdded=true; }catch(e){ Logger.log("Error while adding links from html5video->flashvars: "+e, Logger.LOG_TYPE_ALERT); } } if (blLinksAdded==false) { Logger.log("Unable to find links from HTML5 Video. No downloads available.", Logger.LOG_TYPE_CONSOLE); } if(blLinksAdded==true && AnotherYouTubeDownloader.isGreasemonkey()){ AnotherYouTubeDownloader.putMobileCompatibleLinks(); } if (AnotherYouTubeDownloader.isUserChannelPage()){ if(document.body.addEventListener) document.body.addEventListener("DOMNodeInserted",AnotherYouTubeDownloader.domChanged,false); } }, putDownloadLinksFromFlashVars: function(strFlashVars){ strFlashVars=unescape(strFlashVars.replace(/&amp;/g,"&")); //.replace(/amp;/g, "&"); var fmt_list=strFlashVars.match(/fmt_list=([0-9/x,]*)&/)[1]; /*if(fmt_list.indexOf("&")!=-1) fmt_list=fmt_list.substr(0,fmt_list.indexOf("&"));*/ /*if(fmt_list.indexOf("amp;")!=-1) fmt_list=fmt_list.substr(0,fmt_list.indexOf("amp;"));*/; var fmt_stream_map=strFlashVars.match(/url_encoded_fmt_stream_map=(.*)/)[1]; AnotherYouTubeDownloader.putDownloadLinks(fmt_list, fmt_stream_map); }, putDownloadLinks: function(fmt_list, fmt_stream_map){ var fmt_list_s=fmt_list.split(","); var fmt_stream_maps=fmt_stream_map.split(","); Logger.log("fmt_list:n"+fmt_list, Logger.LOG_TYPE_CONSOLE); Logger.log("fmt_list_s:n"+Logger.formatArray(fmt_list_s), Logger.LOG_TYPE_CONSOLE); Logger.log("fmt_stream_map:n"+fmt_stream_map, Logger.LOG_TYPE_CONSOLE); Logger.log("fmt_stream_maps:n"+Logger.formatArray(fmt_stream_maps), Logger.LOG_TYPE_CONSOLE); for(var i=0;i<fmt_list_s.length;i++){ var vid_vars=fmt_stream_maps[i].split("&"); var url=""; var conn=""; var stream=""; var type=""; var quality=""; var stereo3d=0; var itag=-1; var resolution=""; var sig=""; // signature is *required* to fetch the vid. for(var j=0;j<vid_vars.length;j++){ var key=vid_vars[j].substr(0,vid_vars[j].indexOf("=")); var value=unescape(vid_vars[j].substr(vid_vars[j].indexOf("=")+1)); switch(key){ case "itag": if(itag==-1) itag=value;break; case "url": if(url=="" && conn=="") url=value;break; case "conn": if(conn=="") conn=value; break; case "stream": if(stream=="") stream=value; break; case "type": if(type=="") type=value;break; case "quality": if(quality=="") quality=value;break; case "stereo3d": if(stereo3d==0) stereo3d=value;break; case "fallback_host": break; case "sig": if(sig=="") sig=value;break; //case "signature": if(signature="") signature=value;break; default: if(key.trim().length>0 && i!=fmt_list_s.length-1){ Logger.log("New parameter found. To help make script better, please report this video URL at script forum/support.nnMore details:nnparameter name: "+key+"nparameter value: "+value+"nfmt_stream_maps["+i+"]: "+fmt_stream_maps[i], Logger.LOG_TYPE_ALERT); };break; } } if(url.length!=0 && sig.length!=0){ url=url+"&signature="+escape(sig); // "sig" should be sent as "signature" instead. } if(itag==fmt_list_s[i].split("/")[0]){ resolution=fmt_list_s[i].split("/")[1]; } else if(itag>0 && !isNaN(parseInt(itag))) { Logger.log("fmt_list and fmt_stream_maps mismatch. Please report this video URL at script forum/support.nnMore details:nnitag: "+itag, Logger.LOG_TYPE_ALERT); } if(url.length!=0) AnotherYouTubeDownloader.addDownloadLink(url, type, resolution, quality, stereo3d, itag); else if(conn.length!=0) AnotherYouTubeDownloader.addDownloadLink(conn+(stream.length!=0?"?"+stream:""), type, resolution, quality, stereo3d, itag); else if(type.trim().length>0) { Logger.log("Unsupported protocol found. To help make script better, please report this video URL at script forum/support.nnMore details:nntype: "+type+"nresolution: "+resolution+"nquality:"+quality+"nfmt_stream_maps["+i+"]: "+fmt_stream_maps[i], Logger.LOG_TYPE_ALERT); } } }, gmShowHideLQLinks: function(){ var blShowLQLinks=GM_getValue("LQDownload",true); if(confirm(AnotherYouTubeDownloaderTranslation.getTranslation((blShowLQLinks ? 0 : 1)))) blShowLQLinks=!blShowLQLinks; GM_setValue("LQDownload",blShowLQLinks); if(!blShowLQLinks && AnotherYouTubeDownloader.$("watch-low-quality-download")){ AnotherYouTubeDownloader.$("watch-low-quality-download").parentNode.removeChild(AnotherYouTubeDownloader.$("watch-low-quality-download")); } }, gmSortUnsortFormats: function (){ var blFormatsSorted=GM_getValue("SortFormats", false); if(confirm(AnotherYouTubeDownloaderTranslation.getTranslation((blFormatsSorted ? 17 : 16)))) blFormatsSorted=!blFormatsSorted; GM_setValue("SortFormats", blFormatsSorted); }, formatsSorted: function (){ if(AnotherYouTubeDownloader.isGreasemonkey()) return GM_getValue("SortFormats", false); return false; }, gmEnableDisableToolTips: function (){ var blToolTips=GM_getValue("ToolTips", true); if(confirm(AnotherYouTubeDownloaderTranslation.getTranslation((blToolTips ? 13 : 14)))) blToolTips=!blToolTips; GM_setValue("ToolTips", blToolTips); }, toolTipsEnabled: function (){ if(AnotherYouTubeDownloader.isGreasemonkey()) return GM_getValue("ToolTips", true); return true; }, putMobileCompatibleLinks: function(){ var btnMLinksButton=AnotherYouTubeDownloader.$("watch-low-quality-download"); if(GM_getValue("LQDownload",true)==false){ if(AnotherYouTubeDownloader.$("watch-low-quality-download")) AnotherYouTubeDownloader.$("watch-low-quality-download").parentNode.removeChild(AnotherYouTubeDownloader.$("watch-low-quality-download")); return; } var divWatchActions=AnotherYouTubeDownloader.getWatchActionsEl(); if(divWatchActions && !btnMLinksButton){ btnMLinksButton=document.createElement("button"); btnMLinksButton.id="watch-low-quality-download"; btnMLinksButton.className="yt-uix-tooltip-reverse yt-uix-tooltip yt-uix-button yt-uix-button-text yt-uix-button-default b"; if(AnotherYouTubeDownloader.toolTipsEnabled()) btnMLinksButton.title=AnotherYouTubeDownloaderTranslation.getTranslation(2); btnMLinksButton.addEventListener("click", AnotherYouTubeDownloader.fetchLowQualityLinks, false); divWatchActions.appendChild(btnMLinksButton); } if(btnMLinksButton){ btnMLinksButton.innerHTML="<span class="yt-uix-button-content">"+(AnotherYouTubeDownloader.isCosmicPanda()?AnotherYouTubeDownloaderTranslation.getTranslation(3):AnotherYouTubeDownloaderTranslation.getTranslation(4))+"</span>"; if(AnotherYouTubeDownloader.isCosmicPanda() && AnotherYouTubeDownloader.$("watch-like") && AnotherYouTubeDownloader.$("watch-like").getElementsByClassName("yt-uix-button-content").length>0){ AnotherYouTubeDownloader.$("watch-like").getElementsByClassName("yt-uix-button-content")[0].innerHTML=""; } } }, fetchLowQualityLinks: function(){ AnotherYouTubeDownloader.$("watch-low-quality-download").disabled=true; AnotherYouTubeDownloader.$("watch-low-quality-download").innerHTML="<span class="yt-uix-button-content">"+(AnotherYouTubeDownloader.isCosmicPanda()?"...":AnotherYouTubeDownloaderTranslation.getTranslation(5))+"</span>"; GM_xmlhttpRequest({ method : "GET", url: "http://m.youtube.com/watch?ajax=1&layout=mobile&tsp=1&v="+AnotherYouTubeDownloader.getVidId(), headers: { "User-Agent":"iPhone" }, onload: function (res){ try{ AnotherYouTubeDownloader.$("watch-low-quality-download").parentNode.removeChild(AnotherYouTubeDownloader.$("watch-low-quality-download")); var strResponse=res.responseText; var strLinksPart=strResponse.substr(0,strResponse.indexOf("related_videos")); var strLinksString=strLinksPart.split("stream_url": "); for(var i=1;i<strLinksString.length;i++){ var strLQLinkURL=strLinksString[i].substr(0,strLinksString[i].indexOf(""",1)+1); if(strLQLinkURL.length>2) AnotherYouTubeDownloader.addLink(eval(strLQLinkURL)); } }catch(e){ }finally{ AnotherYouTubeDownloader.toggleDownloadMenu(true); } }, onerror: function (res){ AnotherYouTubeDownloader.$("watch-low-quality-download").disabled=false; AnotherYouTubeDownloader.putMobileCompatibleLinks(); alert(AnotherYouTubeDownloaderTranslation.getTranslation(6)); } }); return false; }, addLink: function(strLink){ var itag=parseInt(strLink.substr(strLink.indexOf("itag=")+5)); var itags={ 13 : { type: "video/3gpp", resolution:"176x144", quality:"small" }, 17 : { type: "video/3gpp", resolution:"176x144", quality:"medium" }, 18 : { type: "video/mp4", resolution:"640x360", quality:"medium" }, 36 : { type: "video/3gpp", resolution:"320x240", quality:"high" } }; if(itags[itag]) AnotherYouTubeDownloader.addDownloadLink(strLink, itags[itag].type, itags[itag].resolution, itags[itag].quality, 0, itag); else AnotherYouTubeDownloader.addDownloadLink(strLink, AnotherYouTubeDownloaderTranslation.getTranslation(7)+" ("+itag+")", AnotherYouTubeDownloaderTranslation.getTranslation(7)+" ("+itag+")", AnotherYouTubeDownloaderTranslation.getTranslation(7)+" ("+itag+")", 0, itag); }, getVidId: function(){ var strVidId; if(AnotherYouTubeDownloader.isWatchPage()){ strVidId=location.search.substring(location.search.indexOf("v=")+2); } else if (AnotherYouTubeDownloader.isUserChannelPage()){ var divPlayNavCurrentTitle=AnotherYouTubeDownloader.$("playnav-curvideo-title"); if(!divPlayNavCurrentTitle) return ""; var aVidLink=divPlayNavCurrentTitle.getElementsByTagName("a"); if(aVidLink.length==0) return ""; strVidId=aVidLink[0].search.substring(aVidLink[0].search.indexOf("v=")+2); } if(strVidId.indexOf("&")!=-1) strVidId=strVidId.substring(0,strVidId.indexOf("&")); if(strVidId.indexOf("#")!=-1) strVidId=strVidId.substring(0,strVidId.indexOf("#")); return strVidId; }, getWatchActionsEl: function(){ if(AnotherYouTubeDownloader.isWatchPage()){ var divWatchActions=AnotherYouTubeDownloader.$("watch-actions"); if(!divWatchActions){ divWatchActions=AnotherYouTubeDownloader.$("watch-content"); } if(!divWatchActions){ divWatchActions=AnotherYouTubeDownloader.$("watch7-action-buttons"); } if(!divWatchActions){ divWatchActions=AnotherYouTubeDownloader.$("vo"); } if(divWatchActions) return divWatchActions; } else if (AnotherYouTubeDownloader.isUserChannelPage()){ var divPlayNavInfoLine=AnotherYouTubeDownloader.$("playnav-curvideo-info-line"); if(divPlayNavInfoLine) return divPlayNavInfoLine; } return null; }, isCosmicPanda: function(){ return AnotherYouTubeDownloader.$("watch-content")!=null; }, toggleDownloadMenu: function(blForce){ var divDLContainer=AnotherYouTubeDownloader.$("watch-download-area-container"); if(blForce==true || divDLContainer.className=="hid"){ divDLContainer.className=""; } else if(blForce==false || divDLContainer.className==""){ divDLContainer.className="hid"; } }, getDownloadMenu: function(){ var tblDownloadMenu=AnotherYouTubeDownloader.$("table-download-menu"); if(!tblDownloadMenu){ var divWatchActions=AnotherYouTubeDownloader.getWatchActionsEl(); if(divWatchActions){ // && divWatchActions.nextSibling){ // v1.2.4 var divDownloadContainer=document.createElement("div"); divDownloadContainer.id="watch-download-area-container"; divDownloadContainer.className=(navigator.userAgent.indexOf("Opera Mini")==-1)?"hid":""; divDownloadContainer.innerHTML=""+ "<div class="yt-rounded" id="watch-download-area">"+ "<div class="watch-actions-panel" id="watch-download-display">"+ "<table id="table-download-menu" cellspacing=0 cellpadding=0>"+ "<tr>"+ "<td width=40></td>"+ "</tr>"+ "</table>"+ "</div>"+ "<div class="close">"+ "<img class="close-button" id="watch-download-close" src="http://s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif">"+ "</div>"+ "</div>"+ ""; if(divWatchActions.nextSibling) divWatchActions.parentNode.insertBefore(divDownloadContainer, divWatchActions.nextSibling); else divWatchActions.parentNode.appendChild(divDownloadContainer); AnotherYouTubeDownloader.addCSS(""+ "#watch-download-area-container{margin-bottom:10px;height:auto}"+ "#watch-download-area{border:1px solid #CCCCCC;padding:5px;position:relative}"+ "#watch-download-area .close{cursor:pointer;position:absolute;right:5px;top:5px}"+ "#table-download-menu{width:100%;}"+ "#table-download-menu td{border:1px solid #E0E0E0;padding:3px 9px}"+ "#table-download-menu td.bold{font-weight:bold}"+ "#watch-download{margin-left:10px}"+ "#watch-low-quality-download{margin-left:4px}"+ ""); var btnDownloadButton=document.createElement("button"); btnDownloadButton.id="watch-download"; btnDownloadButton.className="yt-uix-tooltip-reverse yt-uix-tooltip yt-uix-button yt-uix-button-text yt-uix-button-default b"; if(AnotherYouTubeDownloader.toolTipsEnabled()) btnDownloadButton.title=AnotherYouTubeDownloaderTranslation.getTranslation(8); btnDownloadButton.innerHTML="<span class="yt-uix-button-content">"+AnotherYouTubeDownloaderTranslation.getTranslation(9)+"</span>"; if(btnDownloadButton.addEventListener) btnDownloadButton.addEventListener("click", AnotherYouTubeDownloader.toggleDownloadMenu, false); else if(btnDownloadButton.attachEvent) btnDownloadButton.attachEvent("onclick", AnotherYouTubeDownloader.toggleDownloadMenu); else btnDownloadButton.onclick=AnotherYouTubeDownloader.toggleDownloadMenu; divWatchActions.appendChild(btnDownloadButton); if(AnotherYouTubeDownloader.$("watch-download-close") && AnotherYouTubeDownloader.$("watch-download-close").addEventListener){ AnotherYouTubeDownloader.$("watch-download-close").addEventListener("click", AnotherYouTubeDownloader.toggleDownloadMenu, false); } else if(AnotherYouTubeDownloader.$("watch-download-close") && AnotherYouTubeDownloader.$("watch-download-close").attachEvent){ AnotherYouTubeDownloader.$("watch-download-close").attachEvent("onclick", AnotherYouTubeDownloader.toggleDownloadMenu); } else { AnotherYouTubeDownloader.$("watch-download-close").onclick=AnotherYouTubeDownloader.toggleDownloadMenu; } tblDownloadMenu=AnotherYouTubeDownloader.$("table-download-menu"); } } return tblDownloadMenu; }, getType: function(type){ if(type.indexOf(";")!=-1) type=type.substring(0,type.indexOf(";")); if(type.indexOf("/")!=-1) type=type.substring(type.indexOf("/")+1); switch(type){ case "webm": type="WebM"; break; case "mp4": type="MP4"; break; case "x-flv": type="FLV"; break; case "3gpp": type="3GP"; break; case "xml": type="XML"; break; } return type; }, getHeight: function(resolution){ if(resolution.indexOf("x")!=-1) resolution=resolution.substring(resolution.indexOf("x")+1)+"p"; return resolution; }, maintainTableCells: function(tblTable){ var intCols=0; var i=0; for(i=0;i<tblTable.rows.length;i++){ if(intCols<tblTable.rows[i].cells.length) intCols=tblTable.rows[i].cells.length; } for(i=0;i<tblTable.rows.length;i++){ while(tblTable.rows[i].cells.length<intCols){ tblTable.rows[i].insertCell(tblTable.rows[i].cells.length).innerHTML=""; } } }, addDownloadLink: function(url, type, resolution, quality, stereo3d, itag){ var tblMenu=AnotherYouTubeDownloader.getDownloadMenu(); if(!tblMenu){ return; } var strHType=AnotherYouTubeDownloader.getType(type); var strHHeight=AnotherYouTubeDownloader.getHeight(resolution); var rowHeights=tblMenu.rows[0]; var i; var intHeightIndex=-1; for(i=1;i<rowHeights.cells.length;i++){ if(rowHeights.cells[i].innerHTML==strHHeight) intHeightIndex=i; } if(intHeightIndex==-1){ intHeightIndex=rowHeights.cells.length; rowHeights.insertCell(intHeightIndex).innerHTML=strHHeight; rowHeights.cells[intHeightIndex].className="bold"; } var intTypeIndex=-1; for(i=1;i<tblMenu.rows.length;i++){ if(tblMenu.rows[i].cells[0] && tblMenu.rows[i].cells[0].innerHTML==strHType) intTypeIndex=i; } if(intTypeIndex==-1 && AnotherYouTubeDownloader.formatsSorted()){ for(i=1;i<tblMenu.rows.length;i++){ if(tblMenu.rows[i].cells[0] && tblMenu.rows[i].cells[0].innerHTML.localeCompare(strHType) > 0){ intTypeIndex=i; var curRow=tblMenu.insertRow(intTypeIndex); curRow.insertCell(0).innerHTML=strHType; curRow.cells[0].className="bold"; break; } } } if(intTypeIndex==-1){ intTypeIndex=tblMenu.rows.length; var curRow=tblMenu.insertRow(intTypeIndex); curRow.insertCell(0).innerHTML=strHType; curRow.cells[0].className="bold"; } AnotherYouTubeDownloader.maintainTableCells(tblMenu); var strNewLink=url; if(AnotherYouTubeDownloader.getVideoTitle()!="") strNewLink=strNewLink.substring(0,strNewLink.indexOf("?")+1)+"title="+escape(AnotherYouTubeDownloader.getVideoTitle())+"&"+strNewLink.substring(strNewLink.indexOf("?")+1) var tdCell=tblMenu.rows[intTypeIndex].cells[intHeightIndex]; tdCell.innerHTML=""; var aFirstLink=document.createElement("a"); aFirstLink.setAttribute("href", strNewLink); aFirstLink.setAttribute("class", "yt-uix-tooltip"); if(AnotherYouTubeDownloader.toolTipsEnabled()) aFirstLink.setAttribute("title", "<b>Resolution: </b>"+resolution+"<br/>n<b>MIME Type: </b>"+type.replace(/"/g,"'")+"<br/>n<b>Quality: </b>"+quality+(stereo3d==1?"<br/>n<b>3D: </b>stereo3d audio":"")+"<br/>n<b>YT iTag: </b>"+itag); aFirstLink.innerHTML=(url.indexOf("rtmpe://")==0?AnotherYouTubeDownloaderTranslation.getTranslation(10):AnotherYouTubeDownloaderTranslation.getTranslation(9)); tdCell.appendChild(aFirstLink); if(url.indexOf("rtmpe://")==0){ var aSecondLink=document.createElement("a"); aSecondLink.setAttribute("href", location.protocol+strNewLink.substr(6)); aSecondLink.setAttribute("class", "yt-uix-tooltip"); if(AnotherYouTubeDownloader.toolTipsEnabled()) aSecondLink.setAttribute("title", aFirstLink.getAttribute("title")); aSecondLink.innerHTML=AnotherYouTubeDownloaderTranslation.getTranslation(9); tdCell.appendChild(document.createTextNode("/")); tdCell.appendChild(aSecondLink); } if(AnotherYouTubeDownloader.blHelperInstalled){ var aFileSizeLink=document.createElement("a"); aFileSizeLink.href="javascript:void(0);"; aFileSizeLink.setAttribute("class", "yt-uix-tooltip"); aFileSizeLink.setAttribute("url",(url.indexOf("rtmpe://")==0?"http:"+url.substr(6):url)); aFileSizeLink.addEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); aFileSizeLink.innerHTML="?"; if(AnotherYouTubeDownloader.toolTipsEnabled()) aFileSizeLink.title="Find file size of this download link"; tdCell.appendChild(document.createTextNode(" (")); tdCell.appendChild(aFileSizeLink); tdCell.appendChild(document.createTextNode(")")); } }, fetchFileSize: function(){ var me=this; var url=me.getAttribute("url"); me.innerHTML="..."; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title="Loading..."; me.removeEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); GM_xmlhttpRequest({ method : "GET", url: "http://127.0.0.1:9688/"+url, headers: { "Referer": location.href // If cookies are cleared after page is loaded, this will lead to 403 Forbidden. Better disable cookies. }, onload: function (res){ //unsafeWindow.testRes = res; /*for(var resAttr in res){ Logger.log(resAttr + ": " + res[resAttr], Logger.LOG_TYPE_CONSOLE); }*/ var lngFileSize=parseInt(res.responseText); var strFileSize=""; if(lngFileSize==-2){ me.innerHTML="!2"; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title="Helper application was unable to connect. Check internet settings."; me.addEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); return; } if(lngFileSize==-3){ me.innerHTML="!3"; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title="Helper application does not support this protocol."; me.addEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); return; } if(lngFileSize==-4){ me.innerHTML="!4"; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title="Helper application denied checking file size for this url."; me.addEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); return; } if(lngFileSize==-1){ strFileSize="Unknown"; } else if(lngFileSize<9999){ strFileSize=lngFileSize+"bytes"; } else if(lngFileSize<9999*1024){ strFileSize=(Math.round(lngFileSize/10.24)/100)+"KB"; } else if(lngFileSize<9999*1024*1024){ strFileSize=(Math.round(lngFileSize/(10.24*1024))/100)+"MB"; } else { strFileSize=(Math.round(lngFileSize/(10.24*1024*1024))/100)+"GB"; } me.removeAttribute("href"); me.style.textDecoration="none"; me.style.color="auto"; me.innerHTML=strFileSize; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title=lngFileSize+" bytes"; }, onerror: function (res){ me.innerHTML="!1"; if(AnotherYouTubeDownloader.toolTipsEnabled()) me.title="Unable to fetch file size. Make sure Helper application is running and browser is online."; me.addEventListener("click",AnotherYouTubeDownloader.fetchFileSize,false); } }); }, getVideoTitle: function(){ var spanEowTitle; var strReturnValue=""; if(AnotherYouTubeDownloader.isWatchPage()){ spanEowTitle=AnotherYouTubeDownloader.$("eow-title"); if(spanEowTitle && spanEowTitle.title) { strReturnValue=spanEowTitle.title; } else { spanEowTitle=AnotherYouTubeDownloader.$("watch-headline-title"); if(spanEowTitle && spanEowTitle.textContent) strReturnValue=spanEowTitle.textContent.trim(); } } else if (AnotherYouTubeDownloader.isUserChannelPage()){ spanEowTitle=AnotherYouTubeDownloader.$("playnav-curvideo-title"); if(spanEowTitle && spanEowTitle.textContent) strReturnValue=spanEowTitle.textContent.trim(); } return strReturnValue.replace(/("|*|:|<|>|?|||\|/)/g,"_"); }, domChanged: function(){ setTimeout(function (){ AnotherYouTubeDownloader.fetchDownloadLinks(); },0); }, addCSS: function(css){ if (typeof GM_addStyle != "undefined") { GM_addStyle(css); } else if (typeof PRO_addStyle != "undefined") { PRO_addStyle(css); } else if (typeof addStyle != "undefined") { addStyle(css); } else { var heads = AnotherYouTubeDownloader.$$("head"); if (heads.length > 0) { var node = document.createElement("style"); node.type = "text/css"; try{ node.appendChild(document.createTextNode(css)); }catch(e){} heads[0].appendChild(node); } } }, runScript: function(){ if(!document.body || !document.body.innerHTML) return; if(AnotherYouTubeDownloader.blHelperInstalled && !AnotherYouTubeDownloader.isGreasemonkey()) AnotherYouTubeDownloader.blHelperInstalled=false; if(AnotherYouTubeDownloader.isGreasemonkey()){ GM_registerMenuCommand("Another YouTube Downloader -> "+AnotherYouTubeDownloaderTranslation.getTranslation(11),AnotherYouTubeDownloader.gmShowHideLQLinks); GM_registerMenuCommand("Another YouTube Downloader -> "+AnotherYouTubeDownloaderTranslation.getTranslation(12),AnotherYouTubeDownloader.gmEnableDisableToolTips); GM_registerMenuCommand("Another YouTube Downloader -> "+AnotherYouTubeDownloaderTranslation.getTranslation(15),AnotherYouTubeDownloader.gmSortUnsortFormats); } if(AnotherYouTubeDownloader.isWatchPage()){ AnotherYouTubeDownloader.fetchDownloadLinks(); } else if (AnotherYouTubeDownloader.isUserChannelPage()){ if(document.body.addEventListener) document.body.addEventListener("DOMNodeInserted",AnotherYouTubeDownloader.domChanged,false); } } }; try{ AnotherYouTubeDownloader.runScript(); }catch(e){ window.alert("Another YouTube Downloader Error: "+e); } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=153