Advertisement
AnarchyOnline

Youtube.xys 0.6.5

Jun 6th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 17.94 KB | None | 0 0
  1. "_Initialize"
  2.  {
  3.  // Configuration .ini file
  4.  global $g_ConfigurationFile;
  5.  $g_ConfigurationFile = "<xyscripts>\Youtube.ini";
  6.  
  7.  // Execution and buffer files
  8.  global $g_ExecutionFile;
  9.  $g_ExecutionFile = "<xyscripts>\Youtube.bat";
  10.  
  11.  // Configuration keys
  12.  global $g_ScriptVersion;
  13.  $g_ScriptVersion = '0.6.5';
  14.  
  15.  global $g_Vlc;
  16.  global $g_Downloads;
  17.  
  18.  if (exists("$g_ConfigurationFile") == '1' && $g_ScriptVersion == getkey('ScriptVersion', 'Configuration', "$g_ConfigurationFile", )){
  19.  
  20.   // Load keys
  21.   $g_Vlc = getkey ('Vlc', 'Configuration', "$g_ConfigurationFile", );
  22.   $g_Downloads = getkey ('Downloads', 'Configuration', "$g_ConfigurationFile", );
  23.  
  24.  } else {
  25.   msg <<<#
  26. Script is not configured.
  27. The configuration wizard will assist you.
  28. #;
  29.  
  30.  sub "_Configure";
  31.  }
  32.  }
  33.  
  34. "_Configure"
  35.  {
  36.  global $g_ConfigurationFile;
  37.  
  38.  msg <<<#
  39. 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.
  40.  
  41. The configuration file is located at:
  42.  
  43. $g_ConfigurationFile
  44. #;
  45.  
  46.  // Delete old configuration file
  47.  delete (0, 0, "$g_ConfigurationFile");
  48.  
  49.  // Define parameters
  50.  global $g_ScriptVersion;
  51.  global $g_Vlc;
  52.  global $g_Downloads;
  53.  
  54.  $g_Vlc = inputfile ('C:\', 'exe', 'Select vlc.exe');
  55. $g_Downloads = inputfolder ('C:\', 'Select download location');
  56.  
  57.  
  58. // Write configuration to disk
  59. $Configuration = <<<#
  60. [Configuration]
  61. ScriptVersion=$g_ScriptVersion
  62. Vlc=$g_Vlc
  63. Downloads=$g_Downloads
  64. #;
  65.  
  66. writefile ("$g_ConfigurationFile", "$Configuration", o, t);
  67.  
  68. msg <<<#
  69. Configuration completed.
  70. #;
  71. }
  72.  
  73. "XY - Single"
  74. {
  75. global $g_Downloads;
  76. global $g_MetaTitle;
  77. global $g_VersionsMenuChoiceExt;
  78. global $g_PlayableUrl;
  79.  
  80. sub "_Return-Playable-Url";
  81. download ($g_PlayableUrl, "$g_Downloads\$g_MetaTitle$g_VersionsMenuChoiceExt", o);
  82. }
  83.  
  84. "XY - Batch"
  85. {
  86. global $g_Downloads;
  87. $YoutubeSourceContentArray = '';
  88. $DownloadQueue = '';
  89.  
  90. $Urls = input ("Download Multiple Links - XY", "Paste 1 Youtube link per line followed by Enter", , m, , , );
  91.  
  92. //Load all Youtube sources into $YoutubeSourceContentArray
  93. foreach ($Url, $Urls, "<crlf>"){
  94.  global $g_YoutubeSourceUrl;
  95.  global $g_YoutubeSourceContent;
  96.  
  97.  $g_YoutubeSourceUrl = $Url;
  98.  sub "_Youtube-Get-SourceData";
  99.  //List delimiter must be multiple characters as sourcecode may contain all unicode characters
  100.  //|159@@@@@753|
  101.  $YoutubeSourceContentArray = $YoutubeSourceContentArray.'|159@@@@@753|'.$g_YoutubeSourceContent;
  102. }
  103.  
  104. $YoutubeSourceContentArray = formatlist ($YoutubeSourceContentArray, e, '|159@@@@@753|', );
  105.  
  106. //Ask the user what quality to download per video and store the result in $DownloadQueue
  107.  
  108. foreach ($a, $YoutubeSourceContentArray, '|159@@@@@753|'){
  109. //Can not use $g_YoutubeSourceContent directly instead use $a as intermediate
  110. $g_YoutubeSourceContent = $a;
  111.  
  112. global $g_MetaTitle;
  113. global $g_MetaDescription;
  114. sub "_SourceData-Get-MetaData";
  115.  
  116. global $g_StreamMap;
  117. sub "_SourceData-Get-StreamMap";
  118. sub "_StreamMap-Decode";
  119.  
  120. global $g_Itags;
  121. sub "_StreamMap-Get-Versions";
  122.  
  123. global $g_VersionsMenuList;
  124. global $g_VersionsMenuChoice;
  125. global $g_VersionsMenuChoiceExt;
  126. sub "_Versions-Get-Choice";
  127.  
  128. global $g_PlayableUrl;
  129. sub "_Choice-Create-PlayableUrl";
  130.  
  131. //Smuggle filename with into URL. We regex out the filename later and delete it leaving only the URL
  132. //This code needs clean-up at some point.
  133. //This could be done in a cleaner way by using buffer files.
  134. $Filename = "$g_MetaTitle$g_VersionsMenuChoiceExt";
  135. $DownloadQueue = $DownloadQueue.'|'.$g_PlayableUrl.">$Filename>";
  136. }
  137.  
  138. $DownloadQueue = formatlist ($DownloadQueue, e, '|', );
  139.  
  140. foreach ($Link, $DownloadQueue, '|'){
  141. $Filename = regexmatches ($Link, '[>][^>]+[>]', , 0);
  142. $Filename = replace ($Filename, '>', '', , , );
  143. $Link = regexreplace ($Link, '[>][^>]+[>]', '', );
  144. download ($Link, "$g_Downloads\$Filename", o);
  145. }
  146. }
  147.  
  148. "VLC - Single"
  149. {
  150. global $g_Vlc;
  151. global $g_Downloads;
  152. global $g_ExecutionFile;
  153. global $g_MetaTitle;
  154. global $g_VersionsMenuChoiceExt;
  155. global $g_PlayableUrl;
  156.  
  157. sub "_Return-Playable-Url";
  158.  
  159. $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
  160.  writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
  161.  run ($VlcCmd, , 0, 0);
  162.  }
  163.  
  164. "VLC - Single (Audio only)"
  165.  {
  166.  global $g_Vlc;
  167.  global $g_Downloads;
  168.  global $g_ExecutionFile;
  169.  global $g_MetaTitle;
  170.  global $g_VersionsMenuChoiceExt;
  171.  global $g_PlayableUrl;
  172.  
  173.  sub "_Return-Playable-Url";
  174.  
  175.  $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#transcode{vcodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
  176. writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
  177. run ($VlcCmd, , 0, 0);
  178. }
  179.  
  180. "VLC - Single (Video only)"
  181. {
  182. global $g_Vlc;
  183. global $g_Downloads;
  184. global $g_ExecutionFile;
  185. global $g_MetaTitle;
  186. global $g_VersionsMenuChoiceExt;
  187. global $g_PlayableUrl;
  188.  
  189. sub "_Return-Playable-Url";
  190.  
  191. $VlcCmd = '"'.$g_Vlc.'" "'.$g_PlayableUrl.'" :sout=#transcode{acodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
  192. text $VlcCmd;
  193. writefile ($g_ExecutionFile, $VlcCmd."<crlf>del ".'"'.$g_ExecutionFile.'"', o, t);
  194. run ($VlcCmd, , 0, 0);
  195. }
  196.  
  197. "VLC - Batch"
  198. {
  199. global $g_Vlc;
  200. global $g_Downloads;
  201. global $g_ExecutionFile;
  202. global $g_YoutubeSourceUrl;
  203. global $g_MetaTitle;
  204. global $g_VersionsMenuChoiceExt;
  205. global $g_PlayableUrl;
  206.  
  207. writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
  208.  
  209. $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
  210. foreach ($Url, $Urls, "<crlf>"){
  211.  
  212. $g_YoutubeSourceUrl = $Url;
  213. sub "_Youtube-Get-SourceData";
  214.  
  215. global $g_MetaTitle;
  216. global $g_MetaDescription;
  217. sub "_SourceData-Get-MetaData";
  218.  
  219. global $g_StreamMap;
  220. sub "_SourceData-Get-StreamMap";
  221. sub "_StreamMap-Decode";
  222.  
  223. global $g_Itags;
  224. sub "_StreamMap-Get-Versions";
  225.  
  226. global $g_VersionsMenuList;
  227. global $g_VersionsMenuChoice;
  228. global $g_VersionsMenuChoiceExt;
  229. sub "_Versions-Get-Choice";
  230.  
  231. global $g_PlayableUrl;
  232. sub "_Choice-Create-PlayableUrl";
  233.  
  234.  $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"}';
  235.   //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.
  236.  $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
  237.  writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
  238. }
  239.  
  240. writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
  241. run ($g_ExecutionFile, , 0, 0);
  242. }
  243.  
  244. "VLC - Batch (Audio only)"
  245. {
  246. global $g_Vlc;
  247. global $g_Downloads;
  248. global $g_ExecutionFile;
  249. global $g_YoutubeSourceUrl;
  250. global $g_MetaTitle;
  251. global $g_VersionsMenuChoiceExt;
  252. global $g_PlayableUrl;
  253.  
  254. writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
  255.  
  256. $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
  257. foreach ($Url, $Urls, "<crlf>"){
  258.  
  259. $g_YoutubeSourceUrl = $Url;
  260. sub "_Youtube-Get-SourceData";
  261.  
  262. global $g_MetaTitle;
  263. global $g_MetaDescription;
  264. sub "_SourceData-Get-MetaData";
  265.  
  266. global $g_StreamMap;
  267. sub "_SourceData-Get-StreamMap";
  268. sub "_StreamMap-Decode";
  269.  
  270. global $g_Itags;
  271. sub "_StreamMap-Get-Versions";
  272.  
  273. global $g_VersionsMenuList;
  274. global $g_VersionsMenuChoice;
  275. global $g_VersionsMenuChoiceExt;
  276. sub "_Versions-Get-Choice";
  277.  
  278. global $g_PlayableUrl;
  279. sub "_Choice-Create-PlayableUrl";
  280.  
  281.  $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#transcode{vcodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';  
  282.  //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.
  283.  $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
  284.  writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
  285. }
  286.  
  287. writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
  288. run ($g_ExecutionFile, , 0, 0);
  289. }
  290.  
  291. "VLC - Batch (Video only)"
  292. {
  293. global $g_Vlc;
  294. global $g_Downloads;
  295. global $g_ExecutionFile;
  296. global $g_YoutubeSourceUrl;
  297. global $g_MetaTitle;
  298. global $g_VersionsMenuChoiceExt;
  299. global $g_PlayableUrl;
  300.  
  301. writefile ($g_ExecutionFile, "$g_Vlc ", o, t);
  302.  
  303. $Urls = input ("Download Multiple Links - VLC", "Paste 1 Youtube link per line followed by Enter", , m, , , );
  304. foreach ($Url, $Urls, "<crlf>"){
  305.  
  306. $g_YoutubeSourceUrl = $Url;
  307. sub "_Youtube-Get-SourceData";
  308.  
  309. global $g_MetaTitle;
  310. global $g_MetaDescription;
  311. sub "_SourceData-Get-MetaData";
  312.  
  313. global $g_StreamMap;
  314. sub "_SourceData-Get-StreamMap";
  315. sub "_StreamMap-Decode";
  316.  
  317. global $g_Itags;
  318. sub "_StreamMap-Get-Versions";
  319.  
  320. global $g_VersionsMenuList;
  321. global $g_VersionsMenuChoice;
  322. global $g_VersionsMenuChoiceExt;
  323. sub "_Versions-Get-Choice";
  324.  
  325. global $g_PlayableUrl;
  326. sub "_Choice-Create-PlayableUrl";
  327.  
  328.  $VlcCmd = '"'.$g_PlayableUrl.'" :sout=#transcode{acodec=none}:file{dst="'.$g_Downloads.'\'.$g_MetaTitle.$g_VersionsMenuChoiceExt.'"} :sout-keep --play-and-exit';
  329.  //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.
  330.  $VlcCmd = replace ($VlcCmd, '%2C', ',', , , );
  331.  writefile ($g_ExecutionFile, "$VlcCmd ", a, t);
  332. }
  333. writefile ($g_ExecutionFile, "<crlf>del ".'"'.$g_ExecutionFile.'"', a, t);
  334. run ($g_ExecutionFile, , 0, 0);
  335. }
  336.  
  337. "Decode to CDN Link"
  338. {
  339. global $g_YoutubeSourceUrl;
  340. global $g_YoutubeSourceContent;
  341.  
  342. $g_YoutubeSourceUrl = "<clipboard>";
  343. sub "_Youtube-Get-SourceData";
  344.  
  345. global $g_MetaTitle;
  346. global $g_MetaDescription;
  347. sub "_SourceData-Get-MetaData";
  348.  
  349. global $g_StreamMap;
  350. sub "_SourceData-Get-StreamMap";
  351. sub "_StreamMap-Decode";
  352.  
  353. global $g_Itags;
  354. sub "_StreamMap-Get-Versions";
  355.  
  356. global $g_VersionsMenuList;
  357. global $g_VersionsMenuChoice;
  358. sub "_Versions-Get-Choice";
  359.  
  360. global $g_PlayableUrl;
  361. sub "_Choice-Create-PlayableUrl";
  362.  
  363. text $g_PlayableUrl;
  364. }
  365.  
  366. "Edit Configuration"
  367. {
  368. sub "_Configure";
  369. }
  370.  
  371. /* SUPPORT SCRIPT FUNCTIONS
  372. * Support functions are designed to perform stand-alone tasks only and return results to the main script functions
  373. */
  374.  
  375. //------------------------------------Youtube Support scripts------------------------------------//
  376. "_Return-Playable-Url"
  377. {
  378. global $g_YoutubeSourceUrl;
  379. global $g_YoutubeSourceContent;
  380.  
  381. $g_YoutubeSourceUrl = "<clipboard>";
  382. sub "_Youtube-Get-SourceData";
  383.  
  384. global $g_MetaTitle;
  385. global $g_MetaDescription;
  386. sub "_SourceData-Get-MetaData";
  387.  
  388. global $g_StreamMap;
  389. sub "_SourceData-Get-StreamMap";
  390. sub "_StreamMap-Decode";
  391.  
  392. global $g_Itags;
  393. sub "_StreamMap-Get-Versions";
  394.  
  395. global $g_VersionsMenuList;
  396. global $g_VersionsMenuChoice;
  397. sub "_Versions-Get-Choice";
  398.  
  399. global $g_PlayableUrl;
  400. sub "_Choice-Create-PlayableUrl";
  401. }
  402.  
  403. "_Youtube-Get-SourceData"
  404. {
  405. global $g_YoutubeSourceUrl;
  406. global $g_YoutubeSourceContent;
  407.  
  408. if (regexmatches ($g_YoutubeSourceUrl, "http[s]?://www\.youtube\.com[^ ]+", , 0)){  
  409.  } else {
  410.   $g_YoutubeSourceUrl = input ("Youtube.com", "Paste Youtube video URL here:", , s, , 300, 200);  
  411.  }
  412.   $g_YoutubeSourceContent = readurl ($g_YoutubeSourceUrl, 0, 0, 4);  
  413.  }
  414.  
  415. "_SourceData-Get-MetaData"
  416.  {
  417.  global $g_YoutubeSourceContent;
  418.  global $g_MetaTitle;
  419.  global $g_MetaDescription;
  420.  
  421.  $g_MetaTitle = regexmatches ($g_YoutubeSourceContent, '"og:title" content="[^"]+', , 0);
  422.  $g_MetaTitle = replace ($g_MetaTitle, '"og:title" content="', , , );
  423.  
  424.  $g_MetaDescription = regexmatches ($g_YoutubeSourceContent, '"og:description" content="[^"]+', , 0);
  425.  $g_MetaDescription = replace ($g_MetaDescription, '"og:description" content="', , , );
  426.  
  427.  //Convert HTML character codes
  428.  //Remove &#38;|&apos; because they interfere with VLC
  429.  $g_MetaTitle = replacelist ($g_MetaTitle, '&quot;|&#34;|&amp;|&#38;|&apos;|&#39;|&lt;|&#60;|&gt;|&#62;', "||&|&|||<|<|>|>", '|', 0);
  430.  $g_MetaDescription = replacelist ($g_MetaDescription, '&quot;|&#34;|&amp;|&#38;|&apos;|&#39;|&lt;|&#60;|&gt;|&#62;', "||&|&|||<|<|>|>", '|', 0);
  431.  
  432.  //Remove all NTFS filename illegal characters.
  433.  //Remove comma because it interferes with VLC
  434.  $g_MetaTitle = replacelist ($g_MetaTitle, '/-,-\-:-*-?-<->-"-|', , "-", 0);
  435.  $g_MetaDescription = replacelist ($g_MetaDescription, '/-,-\-:-*-?-<->-"-|', , "-", 0);
  436.  }
  437.  
  438. "_SourceData-Get-StreamMap"
  439.  {
  440.  global $g_RegEx_Haystack;
  441.  global $g_RegEx_Needles;
  442.  global $g_RegEx_Marker;
  443.  global $g_RegEx_Result;
  444.  
  445.  global $g_YoutubeSourceContent;
  446.  global $g_StreamMap;
  447.  
  448.  $g_RegEx_Haystack = $g_YoutubeSourceContent;
  449.  $g_RegEx_Needles = '"url_encoded_fmt_stream_map": "[^"]+~\w+=[^,]+';
  450.  $g_RegEx_Marker = '~';
  451.  sub "_RegEx_Iso";
  452.  
  453.  $g_StreamMap = $g_RegEx_Result;
  454.  }
  455.  
  456. "_StreamMap-Decode"
  457.  {
  458.  global $g_StreamMap;
  459.  $Streams = '';
  460.  
  461.  foreach ($Map, $g_StreamMap, "|"){
  462.   $Map = urldecode ($Map, 1);
  463.   $Map = replacelist ($Map, '\u0026,sig', '&,signature', ",", 0);  
  464.   $Streams = $Streams.$Map.'|';
  465.  }
  466.  $g_StreamMap = formatlist ($Streams, "e", "|", );
  467.  }
  468.  
  469. "_StreamMap-Get-Versions"
  470.  {
  471.  global $g_StreamMap;
  472.  global $g_Itags;
  473.  
  474.  $g_Itags = regexmatches ($g_StreamMap, 'itag=\d+', '|', 0);
  475.  $g_Itags = replace ($g_Itags, 'itag=', , , , );
  476.  $g_Itags = formatlist ($g_Itags, d, '|', );
  477.  }
  478.  
  479. "_Versions-Get-Choice"
  480.  {
  481.  global $g_VersionsDatabase;
  482.  
  483.  global $g_VersionsMenuList;
  484.  global $g_VersionsMenuChoice;
  485.  global $g_VersionsMenuChoiceExt;
  486.  global $g_Itags;
  487.  
  488.  global $g_MetaTitle;
  489.  global $g_MetaDescription;
  490.  
  491.  $g_VersionsDatabase = <<<#
  492. [036] 240p - 3GP
  493. [017] 144p - 3GP
  494. [013] Unknown - 3GP
  495. [035] 480p - FLV
  496. [034] 360p - FLV
  497. [006] 270p - FLV
  498. [005] 240p - FLV
  499. [102] 360p - WebM (3D)
  500. [101] 360p - WebM (3D)
  501. [100] 720p - WebM (3D)
  502. [046] 1080p - WebM
  503. [045] 720p - WebM
  504. [044] 480p - WebM
  505. [043] 360p - WebM
  506. [085] 520p - MP4 (3D)
  507. [084] 720p - MP4 (3D)
  508. [083] 240p - MP4 (3D)
  509. [082] 360p - MP4 (3D)
  510. [038] 3072p - MP4
  511. [037] 1080p - MP4
  512. [022] 720p - MP4
  513. [018] 360p - MP4
  514. #;
  515.  
  516.  // Loop compares tag numbers found in the Youtube source to a database of corresponding quality levels
  517.  // and creates list $g_VersionsMenuList that allows users to choose which video quality they want to download.
  518.  $g_VersionsMenuList = '';
  519.  foreach ($Tag, $g_Itags, '|'){
  520.   $Tag = format ($Tag, '000');
  521.   $g_VersionsMenuList = $g_VersionsMenuList.regexmatches($g_VersionsDatabase, "\[$Tag\][^\[]+", , 0).'|';
  522.  }
  523.  
  524.  $g_VersionsMenuChoice = inputselect ("Choose video quality:<crlf 2>$g_MetaTitle", $g_VersionsMenuList, "|", 0, , , , );
  525.  $g_VersionsMenuChoiceExt = '.'.recase(regexmatches ($g_VersionsMenuChoice, "3GP|FLV|MP4|WebM", , 0), l, );
  526.  
  527.  // After selecting a quality we retrieve the itag numerical value to use it in the PlayableUrl
  528.  $g_VersionsMenuChoice = regexmatches ($g_VersionsMenuChoice, "\[\d+\]", , 0);
  529.  $g_VersionsMenuChoice = replacelist ($g_VersionsMenuChoice, '[,]', , ',', );
  530.  $g_VersionsMenuChoice = trim ($g_VersionsMenuChoice, "0", "L");
  531.  }
  532.  
  533. "_Choice-Create-PlayableUrl"
  534.  {
  535.  global $g_StreamMap;
  536.  global $g_VersionsMenuChoice;
  537.  global $g_PlayableUrl;
  538.  
  539.  $g_PlayableUrl = regexmatches ($g_StreamMap, "[^|]+([&]?itag=$g_VersionsMenuChoice[^|]+)", , 0);
  540.  
  541.  $HttpFront = regexmatches ($g_PlayableUrl, "http[s]?:[^&]+", , 0);
  542.  $g_PlayableUrl = regexreplace ($g_PlayableUrl, "[&]?(type|quality|itag|fallback_host|url)=[^&]+", , 0);
  543.  $g_PlayableUrl = regexreplace ($g_PlayableUrl, "[?][&]", '?', 0);
  544.  $g_PlayableUrl = $HttpFront.'&'.$g_PlayableUrl."&itag=$g_VersionsMenuChoice";
  545.  
  546.  //Prevents && appearing in the URL
  547.  $g_PlayableUrl = replace ($g_PlayableUrl, '&&', '&', , , );
  548.  }
  549.  
  550. //------------------------------------Regular Expression Engine------------------------------------//  
  551. "_RegEx_Iso"
  552.  {
  553.  /*
  554.  _RegEx_Iso is a sub script that will recursively search a text source.
  555.  By using sequenced regular expressions it is able to isolate embedded text that you
  556.  can not isolate using just a single regular expression.
  557.  
  558.  You must define global variables Haystack, Needles, and Marker in your script as the "arguments"
  559.  to the "method" _RegEx_Iso.
  560.  
  561.  E.g:
  562.  
  563.  $g_RegEx_Haystack = $Source;
  564.  $g_RegEx_Needles = "www\.youtube\.com\/user\/[^""]+"."~"."[^\/]+$";
  565.  $g_RegEx_Marker = "~";
  566.  sub "_RegEx_Iso";
  567.  
  568.  text $g_RegEx_Result;
  569.  */  
  570.  
  571.  global $g_RegEx_Haystack;                      // Text source to search in
  572.  global $g_RegEx_Needles;                       // List of recursive regex to be used
  573.  global $g_RegEx_Marker;                        // Delimiting character used to sequence list of regex
  574.  global $g_RegEx_Result;                        // Result of the search are demarked by "|"
  575.  
  576.  $j = $g_RegEx_Haystack;
  577.  $k = $g_RegEx_Needles;
  578.  $l = $g_RegEx_Marker;
  579.  
  580.  foreach ($i, $k, $l){
  581.   $j = regexmatches ("$j", "$i", "|", "0");
  582.  }
  583.  $g_RegEx_Result = $j;
  584.  
  585.  }
  586.  
  587. "_DEBUGRegEx_Iso"
  588.  {
  589.  /*
  590.  _DEBUGRegEx_Iso will do exactly the same as "_RegEx_Iso".
  591.  In addition it will show the Haystack, Needle, Marker and Result for each
  592.  recursive regular expression cycle. Useful to identify buggy behavior.
  593.  */  
  594.  
  595.  global $g_RegEx_Haystack;
  596.  global $g_RegEx_Needles;
  597.  global $g_RegEx_Marker;
  598.  global $g_RegEx_Result;
  599.  
  600.  $j = $g_RegEx_Haystack;
  601.  $k = $g_RegEx_Needles;
  602.  $l = $g_RegEx_Marker;
  603.  
  604.  foreach ($i, $k, $l){
  605.   text "$j";
  606.   $j = regexmatches ("$j", "$i", "|", "0");
  607.   text "$j <crlf 2>$i <crlf 2>$l";
  608.  }
  609.  $g_RegEx_Result = $j;  
  610.  
  611.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement