Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************************************
- *** 40k's Xyplorer Youtube script 0.5 ***
- *** ***
- *** Special thanks to forum users Marco, Highend and klownboy ***
- *** for their troubleshooting with video titles. ***
- *** ***
- *** As of 0.5 this script now uses a configuration file nested in ***
- *** XY's Scripts folder. The config file is initialized during ***
- *** "_Initialize". The script also writes small .bat files into ***
- *** that folder to improve performance on batch downloading with VLC ***
- *** These files should delete themselves. It is entirely possible to ***
- *** change all this in the code should you desire. ***
- *** ***
- *** TEMPORARY LIMITATION: ***
- *** As of Xyplorer 12.30 a download file size limit of 100mb is ***
- *** in place for "Get Full Video - Xyplorer". ***
- *** THIS LIMITATION IS SET TO DISAPPEAR IN THE COMING XY VERSIONS! ***
- *** ***
- *** Please visit the script thread on the Xy forums at: ***
- *** http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=9396&sid=194326252b4e01c78ffa00695a6eb953 ***
- *** ***
- *** - 40k ***
- ******************************************************************************************************/
- /* MAIN SCRIPT FUNCTIONS
- * Main functions contain minimal unique code and are designed to chain smaller script modules
- * to generate a desired output.
- *
- * FOR VLC MAIN FUNCTIONS:
- * VLC sometimes parses a command line internally. Documentation on this is poor. This will result
- * in buggy behavior. During testing most coming bugs have been worked around (mainly URL parsing).
- * More specific bugs may still appear. Please post on the forum if you encounter odd behavior.
- */
- "_Initialize"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_INIFile;
- global $g_BATFile;
- $g_INIFile = "<xyscripts>\YouTube.ini";
- $g_BATFile = "<xyscripts>\YouTube.bat";
- if (exists($g_INIFile) == 1){
- $g_Vlc = getkey ('Vlc', 'Config', $g_INIFile, );
- $g_Downloads = getkey ('Downloads', 'Config', $g_INIFile, );
- } else {
- msg <<<#
- This is your first time running YouTube.xys 0.6 or you have deleted your configuration file. This configuration wizard helps you quickly configure the script for use. You can later edit your configuration file through the script.
- 1. Select the location of vlc.exe
- 2. Select the location where you want downloads to appear
- #;
- $g_Vlc = inputfile ("C:", "exe", "Configuration on first script run - Select vlc.exe");
- $g_Downloads = inputfolder ("C:", "Configuration on first script run - Select desired download location");
- $Configuration = <<<#
- [Config]
- Vlc=$g_Vlc
- Downloads=$g_Downloads
- #;
- writefile ($g_INIFile, $Configuration, o, t);
- msg <<<#
- The script is now configured for use!
- #;
- }
- }
- "Download 1 Link - XY"
- {
- global $g_Downloads;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url-XY";
- download ($g_PlayableUrl, "$g_Downloads\$g_MetaTitle$g_VersionsMenuChoiceExt", u);
- }
- "Download 1 Link - VLC"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url-VLC";
- $VlcCmd = '"'.$g_Vlc.'" --sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep "'.$g_PlayableUrl.'" vlc://quit';
- writefile ($g_BATFile, $VlcCmd."<crlf>del ".'"'.$g_BATFile.'"', o, t);
- run ($VlcCmd, , 0, 0);
- }
- "Download 1 Link - VLC (Audio only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url-VLC";
- $VlcCmd = '"'.$g_Vlc.'" --sout=#transcode{vcodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep "'.$g_PlayableUrl.'" vlc://quit';
- writefile ($g_BATFile, $VlcCmd."<crlf>del ".'"'.$g_BATFile.'"', o, t);
- run ($g_BATFile, , 0, 0);
- }
- "Download 1 Link - VLC (Video only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url-VLC";
- $VlcCmd = '"'.$g_Vlc.'" --sout=#transcode{acodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep "'.$g_PlayableUrl.'" vlc://quit';
- writefile ($g_BATFile, $VlcCmd."<crlf>del ".'"'.$g_BATFile.'"', o, t);
- run ($g_BATFile, , 0, 0);
- }
- "Download Multiple Links - XY"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($a, $Urls, "<crlf>"){ //$a is intermediate, foreach loop does not accept uninitialized global?
- $g_YoutubeSourceUrl = $a;
- sub "_Return-Playable-Urls-XY";
- download ($g_PlayableUrl, "$g_Downloads\$g_MetaTitle$g_VersionsMenuChoiceExt", u);
- }
- }
- "Download Multiple Links - VLC"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- writefile ($g_BATFile, '', o, t);
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($a, $Urls, "<crlf>"){ //$a is intermediate, foreach loop does not accept uninitialized global?
- $g_YoutubeSourceUrl = $a;
- sub "_Return-Playable-Urls-VLC";
- $VlcCmd = '"'.$g_Vlc.'" --sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep "'.$g_PlayableUrl.'" vlc://quit';
- writefile ($g_BATFile, $VlcCmd."<crlf>", a, t);
- }
- writefile ($g_BATFile, "del ".'"'.$g_BATFile.'"', a, t);
- run ($g_BATFile, , 0, 0);
- }
- "Podcast Encoder" //EXPERIMENTAL
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_BATFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- writefile ($g_BATFile, '', o, t);
- $Acodec = inputselect ('Podcast Encoder - Choose your codec', 'mp3|mp4a|mpga|flac|vorb|a52|spx', '|', 0, , 300, 300);
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($a, $Urls, "<crlf>"){ //$a is intermediate, foreach loop does not accept uninitialized global?
- $g_YoutubeSourceUrl = $a;
- sub "_Return-Playable-Urls-VLC";
- // Encoding GUI is still in testing phase during development of v.0.5
- // To change output of encoding done by VLC change values in $VlcCmd below as follows:
- // ab = Audio Bitrate in kb. (E.g: ab=128 is 128kb/s)
- // channels = Audio channels encoded. Maximum is 8 (?)
- // samplerate = Most commonly 44k or 48k
- $VlcCmd = '"'.$g_Vlc.'" --sout=#transcode{vcodec=none,acodec='.$Acodec.',ab=192,channels=2,samplerate=48000}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.'.'.$Acodec.'"} :sout-keep "'.$g_PlayableUrl.'" vlc://quit';
- writefile ($g_BATFile, $VlcCmd."<crlf>", a, t);
- }
- writefile ($g_BATFile, "del ".'"'.$g_BATFile.'"', a, t);
- run ($g_BATFile, , 0, 0);
- }
- "File Encoder" //EXPERIMENTAL
- {
- global $g_Vlc;
- global $g_BATFile;
- }
- /* SUPPORT SCRIPT FUNCTIONS
- * Support functions are designed to perform stand-alone tasks only and return results to the main script functions
- */
- //------------------------------------Youtube Support scripts------------------------------------//
- "_Return-Playable-Url-XY"
- {
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- $g_YoutubeSourceUrl = "<clipboard>";
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode-XY";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- }
- "_Return-Playable-Url-VLC"
- {
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- $g_YoutubeSourceUrl = "<clipboard>";
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode-VLC";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- }
- "_Return-Playable-Urls-XY"
- {
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode-VLC";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- }
- "_Return-Playable-Urls-VLC"
- {
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode-VLC";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- }
- "_Youtube-Get-SourceData"
- {
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- if (regexmatches ($g_YoutubeSourceUrl, "http[s]?://www\.youtube\.com[^ ]+", , 0)){
- } else {
- $g_YoutubeSourceUrl = input ("Youtube.com", "Paste Youtube video URL here", , s, , 300, 200);
- }
- $g_YoutubeSourceContent = readurl ($g_YoutubeSourceUrl, 0, 0, 1);
- }
- "_SourceData-Get-MetaData"
- {
- global $g_YoutubeSourceContent;
- global $g_MetaTitle;
- global $g_MetaDescription;
- $g_MetaTitle = regexmatches ($g_YoutubeSourceContent, '"og:title" content="[^"]+', , 0);
- $g_MetaTitle = replace ($g_MetaTitle, '"og:title" content="', , , );
- $g_MetaTitle = replacelist ($g_MetaTitle, "","", '', ",", 0);
- $g_MetaTitle = replacelist ($g_MetaTitle, "&,&,',',<,<,>,>", "&,&,',',<,<,>,>", ",", 0);
- $g_MetaTitle = replacelist ($g_MetaTitle, '/-\-:-*-?-<->-"-|-,', , '-', 0); // Remove comma as it interferes with VLC command line parameters
- $g_MetaDescription = regexmatches ($g_YoutubeSourceContent, '"og:description" content="[^"]+', , 0);
- $g_MetaDescription = replace ($g_MetaDescription, '"og:description" content="', , , );
- $g_MetaDescription = replacelist ($g_MetaDescription, "","", '"', ",", 0);
- $g_MetaDescription = replacelist ($g_MetaDescription, "&,&,',',<,<,>,>", "&,&,',',<,<,>,>", ",", 0);
- $g_MetaDescription = replacelist ($g_MetaDescription, "/,\,:,*,?,<,>,|", , ",", 0);
- }
- "_SourceData-Get-StreamMap"
- {
- global $g_RegEx_Haystack;
- global $g_RegEx_Needles;
- global $g_RegEx_Marker;
- global $g_RegEx_Result;
- global $g_YoutubeSourceContent;
- global $g_StreamMap;
- $g_RegEx_Haystack = $g_YoutubeSourceContent;
- $g_RegEx_Needles = '"url_encoded_fmt_stream_map": "[^"]+~\w+=[^,]+';
- $g_RegEx_Marker = '~';
- sub "_RegEx_Iso";
- $g_StreamMap = $g_RegEx_Result;
- }
- "_StreamMap-Decode-XY"
- {
- global $g_StreamMap;
- $Streams = '';
- foreach ($Map, $g_StreamMap, "|"){
- $Map = urldecode ($Map, 1);
- $Map = replacelist ($Map, '\u0026,sig', '&,signature', ",", 0);
- $Streams = $Streams.$Map.'|';
- }
- $g_StreamMap = formatlist ($Streams, "e", "|", );
- }
- "_StreamMap-Decode-VLC"
- {
- global $g_StreamMap;
- $Streams = '';
- foreach ($Map, $g_StreamMap, "|"){
- $Map = urldecode ($Map, 1);
- $Map = replacelist ($Map, '\u0026|sig|%2C', '&|signature|,', "|", 0);
- $Streams = $Streams.$Map.'|';
- }
- $g_StreamMap = formatlist ($Streams, "e", "|", );
- }
- "_StreamMap-Get-Versions"
- {
- global $g_StreamMap;
- global $g_Itags;
- $g_Itags = regexmatches ($g_StreamMap, 'itag=\d+', '|', 0);
- $g_Itags = replace ($g_Itags, 'itag=', , , , );
- $g_Itags = formatlist ($g_Itags, "d", '|', );
- }
- "_Versions-Get-Choice"
- {
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- global $g_Itags;
- global $g_MetaTitle;
- global $g_MetaDescription;
- $ThreeGP =
- "
- >[036] 240p - 3GP
- >[017] 144p - 3GP
- >[013] Unknown - 3GP
- ";
- $Flv =
- "
- >[035] 480p - FLV
- >[034] 360p - FLV
- >[006] 270p - FLV
- >[005] 240p - FLV
- ";
- $Webm =
- "
- >[046] 1080p - WebM
- >[045] 720p - WebM
- >[044] 480p - WebM
- >[043] 360p - WebM
- ";
- $Mp4 =
- "
- >[038] 3072p - MP4
- >[037] 1080p - MP4
- >[022] 720p - MP4
- >[018] 360p - MP4
- ";
- $DataBase = replace($ThreeGP.$Flv.$Webm.$Mp4, ' >', , 0, , );
- $g_VersionsMenuList = '';
- foreach ($Tag, $g_Itags, '|'){
- $Tag = format ($Tag, '000'); //format itags to 3 digits
- $g_VersionsMenuList = $g_VersionsMenuList.regexmatches($DataBase, "\[$Tag\][^\[]+", , 0).'|'; //Create list from available qualities
- }
- $g_VersionsMenuChoice = inputselect ("Choose video quality:<crlf 2>$g_MetaTitle", $g_VersionsMenuList, "|", 0, , , , );
- $g_VersionsMenuChoiceExt = '.'.recase(regexmatches ($g_VersionsMenuChoice, "3GP|FLV|MP4|WebM", , 0), l, );
- $g_VersionsMenuChoice = regexmatches ($g_VersionsMenuChoice, "\[\d+\]", , 0);
- $g_VersionsMenuChoice = replacelist ($g_VersionsMenuChoice, '[,]', , ',', );
- $g_VersionsMenuChoice = trim ($g_VersionsMenuChoice, "0", "L");
- }
- "_Choice-Create-PlayableUrl"
- {
- global $g_StreamMap;
- global $g_VersionsMenuChoice;
- global $g_PlayableUrl;
- $g_PlayableUrl = regexmatches ($g_StreamMap, "[^|]+([&]?itag=$g_VersionsMenuChoice[^|]+)", , 0);
- $HttpFront = regexmatches ($g_PlayableUrl, "http:[^&]+", , 0);
- $g_PlayableUrl = regexreplace ($g_PlayableUrl, "[&]?(type|quality|itag|fallback_host|url)=[^&]+", , 0);
- $g_PlayableUrl = regexreplace ($g_PlayableUrl, "[?][&]", , 0);
- $g_PlayableUrl = $HttpFront.'&'.$g_PlayableUrl."&itag=$g_VersionsMenuChoice";
- $g_PlayableUrl = replace ($g_PlayableUrl, '&&', '&', , , ); //quick fix to prevent & disappearing after httpfront move
- }
- //------------------------------------Encoder Support scripts------------------------------------//
- //------------------------------------Regular Expression Engine------------------------------------//
- "_RegEx_Iso"
- {
- /*
- _RegEx_Iso is a sub script that will recursively search a text source.
- By using sequenced regular expressions it is able to isolate embedded text that you
- can not isolate using just a single regular expression.
- You must define global variables Haystack, Needles, and Marker in your script as the "arguments"
- to the "method" _RegEx_Iso.
- E.g:
- $g_RegEx_Haystack = $Source;
- $g_RegEx_Needles = "www\.youtube\.com\/user\/[^""]+"."~"."[^\/]+$";
- $g_RegEx_Marker = "~";
- sub "_RegEx_Iso";
- text $g_RegEx_Result;
- */
- global $g_RegEx_Haystack; // Text source to search in
- global $g_RegEx_Needles; // List of recursive regex to be used
- global $g_RegEx_Marker; // Delimiting character used to sequence list of regex
- global $g_RegEx_Result; // Result of the search are demarked by "|"
- $j = $g_RegEx_Haystack;
- $k = $g_RegEx_Needles;
- $l = $g_RegEx_Marker;
- foreach ($i, $k, $l){
- $j = regexmatches ("$j", "$i", "|", "0");
- }
- $g_RegEx_Result = $j;
- }
- "_DEBUGRegEx_Iso"
- {
- /*
- _DEBUGRegEx_Iso will do exactly the same as "_RegEx_Iso".
- In addition it will show the Haystack, Needle, Marker and Result for each
- recursive regular expression cycle. Useful to identify buggy behavior.
- */
- global $g_RegEx_Haystack;
- global $g_RegEx_Needles;
- global $g_RegEx_Marker;
- global $g_RegEx_Result;
- $j = $g_RegEx_Haystack;
- $k = $g_RegEx_Needles;
- $l = $g_RegEx_Marker;
- foreach ($i, $k, $l){
- text "$j";
- $j = regexmatches ("$j", "$i", "|", "0");
- text "$j <crlf 2>$i <crlf 2>$l";
- }
- $g_RegEx_Result = $j;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement