Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "_Initialize"
- {
- // Configuration .ini file
- global $g_ConfigurationFile;
- $g_ConfigurationFile = "<xyscripts>\Youtube.ini";
- // Execution and buffer files
- global $g_ExecutionFile;
- $g_ExecutionFile = "<xyscripts>\Youtube.bat";
- // Configuration keys
- global $g_ScriptVersion;
- $g_ScriptVersion = '0.6.5';
- global $g_Vlc;
- global $g_Downloads;
- if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
- // Load keys
- $g_Vlc = getkey ('Vlc', 'Configuration', "$g_ConfigurationFile", );
- $g_Downloads = getkey ('Downloads', 'Configuration', "$g_ConfigurationFile", );
- } else {
- msg <<<#
- Script is not configured.
- The configuration wizard will assist you.
- #;
- sub "_Configure";
- }
- }
- "_Configure"
- {
- global $g_ConfigurationFile;
- msg <<<#
- This wizard configures the script for first use. To edit the configuration file click "Edit Configuration" after launching the script. If the configuration file is not found or you upgrade to a new version of this script the wizard will appear automatically.
- The configuration file is located at:
- $g_ConfigurationFile
- #;
- // Delete old configuration file
- delete (0, 0, "$g_ConfigurationFile");
- // Define parameters
- global $g_ScriptVersion;
- global $g_Vlc;
- global $g_Downloads;
- $g_Vlc = inputfile ('C:\', 'exe', 'Select vlc.exe');
- $g_Downloads = inputfolder ('C:\', 'Select download location');
- // Write configuration to disk
- $Configuration = <<<#
- [Configuration]
- ScriptVersion=$g_ScriptVersion
- Vlc=$g_Vlc
- Downloads=$g_Downloads
- #;
- writefile ("$g_ConfigurationFile", "$Configuration", o, t);
- msg <<<#
- Configuration completed.
- #;
- }
- "XY - Single"
- {
- global $g_Downloads;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url";
- download ($g_PlayableUrl, "$g_Downloads\$g_MetaTitle$g_VersionsMenuChoiceExt", o);
- }
- "XY - Batch"
- {
- global $g_Downloads;
- $YoutubeSourceContentArray = '';
- $DownloadQueue = '';
- $Urls = input ("Download Multiple Links - XY", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- //Load all Youtube sources into $YoutubeSourceContentArray
- foreach ($Url, $Urls, "<crlf>"){
- global $g_YoutubeSourceUrl;
- global $g_YoutubeSourceContent;
- $g_YoutubeSourceUrl = $Url;
- sub "_Youtube-Get-SourceData";
- //List delimiter must be multiple characters as sourcecode may contain all unicode characters
- //|159@@@@@753|
- $YoutubeSourceContentArray = $YoutubeSourceContentArray.'|159@@@@@753|'.$g_YoutubeSourceContent;
- }
- $YoutubeSourceContentArray = formatlist ($YoutubeSourceContentArray, e, '|159@@@@@753|', );
- //Ask the user what quality to download per video and store the result in $DownloadQueue
- foreach ($a, $YoutubeSourceContentArray, '|159@@@@@753|'){
- //Can not use $g_YoutubeSourceContent directly instead use $a as intermediate
- $g_YoutubeSourceContent = $a;
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- //Smuggle filename with into URL. We regex out the filename later and delete it leaving only the URL
- //This code needs clean-up at some point.
- //This could be done in a cleaner way by using buffer files.
- $Filename = "$g_MetaTitle$g_VersionsMenuChoiceExt";
- $DownloadQueue = $DownloadQueue.'|'.$g_PlayableUrl.">$Filename>";
- }
- $DownloadQueue = formatlist ($DownloadQueue, e, '|', );
- foreach ($Link, $DownloadQueue, '|'){
- $Filename = regexmatches ($Link, '[>][^>]+[>]', , 0);
- $Filename = replace ($Filename, '>', '', , , );
- $Link = regexreplace ($Link, '[>][^>]+[>]', '', );
- download ($Link, "$g_Downloads\$Filename", o);
- }
- }
- "VLC - Single"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url";
- $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
- writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
- run ($VlcCmd, , 0, 0);
- }
- "VLC - Single (Audio only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url";
- $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#transcode{vcodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
- writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
- run ($VlcCmd, , 0, 0);
- }
- "VLC - Single (Video only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- sub "_Return-Playable-Url";
- $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#transcode{acodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
- text $VlcCmd;
- writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
- run ($VlcCmd, , 0, 0);
- }
- "VLC - Batch"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($Url, $Urls, "<crlf>"){
- $g_YoutubeSourceUrl = $Url;
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"}';
- //For unknown reasons the parameter %2C causes VLC to quit when multiple files are queued up in a batch file. When only a single file is present the batch file will run. As a countermeasure I'm replace %2C by comma. If anyone knows why this behavior occurs please let me know.
- $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
- writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
- }
- writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
- run ($g_ExecutionFile, , 0, 0);
- }
- "VLC - Batch (Audio only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($Url, $Urls, "<crlf>"){
- $g_YoutubeSourceUrl = $Url;
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#transcode{vcodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
- //For unknown reasons the parameter %2C causes VLC to quit when multiple files are queued up in a batch file. When only a single file is present the batch file will run. As a countermeasure I'm replace %2C by comma. If anyone knows why this behavior occurs please let me know.
- $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
- writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
- }
- writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
- run ($g_ExecutionFile, , 0, 0);
- }
- "VLC - Batch (Video only)"
- {
- global $g_Vlc;
- global $g_Downloads;
- global $g_ExecutionFile;
- global $g_YoutubeSourceUrl;
- global $g_MetaTitle;
- global $g_VersionsMenuChoiceExt;
- global $g_PlayableUrl;
- writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
- $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
- foreach ($Url, $Urls, "<crlf>"){
- $g_YoutubeSourceUrl = $Url;
- sub "_Youtube-Get-SourceData";
- global $g_MetaTitle;
- global $g_MetaDescription;
- sub "_SourceData-Get-MetaData";
- global $g_StreamMap;
- sub "_SourceData-Get-StreamMap";
- sub "_StreamMap-Decode";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#transcode{acodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
- //For unknown reasons the parameter %2C causes VLC to quit when multiple files are queued up in a batch file. When only a single file is present the batch file will run. As a countermeasure I'm replace %2C by comma. If anyone knows why this behavior occurs please let me know.
- $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
- writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
- }
- writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
- run ($g_ExecutionFile, , 0, 0);
- }
- "Decode to CDN Link"
- {
- 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";
- global $g_Itags;
- sub "_StreamMap-Get-Versions";
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- sub "_Versions-Get-Choice";
- global $g_PlayableUrl;
- sub "_Choice-Create-PlayableUrl";
- text $g_PlayableUrl;
- }
- "Edit Configuration"
- {
- sub "_Configure";
- }
- /* 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"
- {
- 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";
- 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, 4);
- }
- "_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_MetaDescription = regexmatches ($g_YoutubeSourceContent, '"og:description" content="[^"]+', , 0);
- $g_MetaDescription = replace ($g_MetaDescription, '"og:description" content="', , , );
- //Convert HTML character codes
- //Remove &|' because they interfere with VLC
- $g_MetaTitle = replacelist ($g_MetaTitle, '"|"|&|&|'|'|<|<|>|>', "||&|&|||<|<|>|>", '|', 0);
- $g_MetaDescription = replacelist ($g_MetaDescription, '"|"|&|&|'|'|<|<|>|>', "||&|&|||<|<|>|>", '|', 0);
- //Remove all NTFS filename illegal characters.
- //Remove comma because it interferes with VLC
- $g_MetaTitle = replacelist ($g_MetaTitle, '/-,-\-:-*-?-<->-"-|', , "-", 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"
- {
- 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-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_VersionsDatabase;
- global $g_VersionsMenuList;
- global $g_VersionsMenuChoice;
- global $g_VersionsMenuChoiceExt;
- global $g_Itags;
- global $g_MetaTitle;
- global $g_MetaDescription;
- $g_VersionsDatabase = <<<#
- [036] 240p - 3GP
- [017] 144p - 3GP
- [013] Unknown - 3GP
- [035] 480p - FLV
- [034] 360p - FLV
- [006] 270p - FLV
- [005] 240p - FLV
- [102] 360p - WebM (3D)
- [101] 360p - WebM (3D)
- [100] 720p - WebM (3D)
- [046] 1080p - WebM
- [045] 720p - WebM
- [044] 480p - WebM
- [043] 360p - WebM
- [085] 520p - MP4 (3D)
- [084] 720p - MP4 (3D)
- [083] 240p - MP4 (3D)
- [082] 360p - MP4 (3D)
- [038] 3072p - MP4
- [037] 1080p - MP4
- [022] 720p - MP4
- [018] 360p - MP4
- #;
- // Loop compares tag numbers found in the Youtube source to a database of corresponding quality levels
- // and creates list $g_VersionsMenuList that allows users to choose which video quality they want to download.
- $g_VersionsMenuList = '';
- foreach ($Tag, $g_Itags, '|'){
- $Tag = format ($Tag, '000');
- $g_VersionsMenuList = $g_VersionsMenuList.regexmatches($g_VersionsDatabase, "\[$Tag\][^\[]+", , 0).'|';
- }
- $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, );
- // After selecting a quality we retrieve the itag numerical value to use it in the PlayableUrl
- $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[s]?:[^&]+", , 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";
- //Prevents && appearing in the URL
- $g_PlayableUrl = replace ($g_PlayableUrl, '&&', '&', , , );
- }
- //------------------------------------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