Advertisement
AnarchyOnline

YoutubeGet 0.4

Mar 28th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.44 KB | None | 0 0
  1. /************************************************************************
  2. *** 40k's Xyplorer Youtube script 0.4                     ***
  3. ***                                                                   ***    
  4. *** Special thanks to forum users Marco, Highend and klownboy         ***
  5. *** for their troubleshooting with video titles.                      ***
  6. ***                                                                   ***  
  7. *** IF YOU PLAN TO USE THE VLC FEATURES OF THIS SCRIPT:               ***  
  8. *** - Enable permanent variables OR hard code vlc path in $p_VLC      ***  
  9. ***                                                                   ***  
  10. *** LIMITATION:                                                       ***
  11. *** - As of Xyplorer 12.30 a download file size limit of 100mb is     ***  
  12. ***   in place for "Get Full Video - Xyplorer". This is an Xyplorer   ***  
  13. ***   limitation and may get resolved in future versions of XY.       ***  
  14. ***                                                                   ***          
  15. *** ADVICE:                                                           ***  
  16. *** - Use VLC features of this script if you want to download         ***  
  17. ***   videos larger than 100mb in size. It will work.                 ***  
  18. ***                                                                   ***  
  19. *** - 40k                                                             ***      
  20. ************************************************************************/
  21.  
  22. "Get Full Video - Xyplorer"
  23.  {
  24. /* VARIABLES */
  25.  
  26.  // "Get Full Video - Xyplorer" globals
  27.  global $g_Menu;
  28.  global $g_AvailableQualities;
  29.  
  30.  // "_RegEx_Iso" globals
  31.  global $g_RegEx_Haystack;                     
  32.  global $g_RegEx_Needles;                  
  33.  global $g_RegEx_Marker;                   
  34.  global $g_RegEx_Result;
  35.  
  36.  //Variables called $YoutubeSource_XYZ contain original Youtube source code  
  37.  
  38.  // Initialize variables that need to be empty before first use
  39.  $ParsedQualities = "";
  40.  $g_AvailableQualities = "";
  41.  
  42. /* Read Youtube video page content */
  43.  if (regexmatches (<clipboard>, "http[s]?://www\.youtube\.com[^ ]+", "", "0")){
  44.   $YoutubeSource_URL = <clipboard>;
  45.  } else {
  46.   $YoutubeSource_URL = input ("Youtube", "Paste Youtube video URL here", "", "s", "", "300", "200");
  47.  }  
  48.  
  49.  $YoutubeSource_All = readurl ("$YoutubeSource_URL");
  50.  
  51. /* Find the video title */
  52.  $VideoTitle = regexmatches ($YoutubeSource_All, "<title>.+<\/title>", "", "0");
  53.  $VideoTitle = regexreplace ($VideoTitle, "<title>|<\/title>", "", "0");
  54.  $VideoTitle = regexreplace ($VideoTitle, " - Youtube", "", "0");
  55.  $VideoTitle = regexreplace ($VideoTitle, "&quot;|&#34;", '"', "0");
  56.  $VideoTitle = replacelist($VideoTitle, "&amp;,&#38;,&apos;,&#39;,&lt;,&#60;,&gt;,&#62;", "&,&,',',<,<,>,>", ",");
  57.  $VideoTitle = replacelist($VideoTitle, "/,\,:,*,?,<,>,|", "", ",");
  58.  
  59. /* Isolate different quality maps. Quality maps are delimited by "|" in $YoutubeSource_QualityMap */
  60.  $g_RegEx_Haystack = $YoutubeSource_All;                       
  61.  $g_RegEx_Needles = quote("url_encoded_fmt_stream_map"": ""[^""]*", "0")."~"."\w+=[^,]+";
  62.  $g_RegEx_Marker = "~";
  63.  sub "_RegEx_Iso";
  64.  $YoutubeSource_QualityMap = $g_RegEx_Result;
  65.  
  66. /* Isolate available qualities */
  67.  foreach ($Quality, $YoutubeSource_QualityMap, "|"){
  68.   // Decode URL and replace \\u0026 and "sig"
  69.   $Quality = urldecode ($Quality, "1");
  70.   $Quality = regexreplace ($Quality, "\\u0026", "&", "0");
  71.   $Quality = regexreplace ($Quality, "sig", "signature", "0");
  72.  
  73.   // Youtube URL generation is dynamic. First make sure "http://..." is at start of URL
  74.   // Note that http://...?parameter=xyz will contain 1 URL parameter that does not start with &
  75.   $Quality = regexreplace ($Quality, "[&]?url=", "", "0");
  76.   $Http = regexmatches ($Quality, "http:[^&]+", "|", "0");
  77.   $Quality = $Http.regexreplace ($Quality, "http:[^&]+", "", "0");
  78.  
  79.   // Find URL specific itag value, isolate, and replace with single occurence of "itag=..."
  80.   $Itag = regexreplace (regexmatches ("$Quality", "[&]?itag=\d{1,3}", "@", "0"),"[&]?itag=|@[&]?itag=\d+","","0");
  81.   $Quality = regexreplace ($Quality, "[&]?(type|quality|itag|fallback_host)=[^&]+", "", "0")."&itag=$Itag";
  82.  
  83.   $ParsedQualities = $ParsedQualities.$Quality."|";
  84.   $g_AvailableQualities = $g_AvailableQualities.$Itag."|";
  85.  }
  86.  
  87.  sub "_IdentItag";
  88.  $RequestedVideos = inputselect ("Youtube.com", $g_Menu, "|", "0", , "300", , );
  89.  
  90. // The script currently processes one video at a time.
  91. // This foreach loop has been implemented with the goal of supporting processing of multiple videos
  92. // one after the other (Batch style) in future versions of this script  
  93.  foreach ($Video, $RequestedVideos, "|"){
  94.   $Itag = replacelist(regexmatches ($Video, "\[\d+\]", "", "0"), "[,]", "", "", "0");  
  95.   $VideoExt = recase(regexmatches ($Video, "3GP|FLV|MP4|WebM", "", "0"), "l", );
  96.   $Url = regexmatches ($ParsedQualities, "[^|]*itag=$Itag[^|]*", "", "0");
  97.   writefile ("$VideoTitle.$VideoExt", readurl($Url), "o", "b");
  98.  }
  99.  }
  100.  
  101. "Get Full Video - VLC"
  102.  {
  103. /* VARIABLES */
  104.  
  105.  global $p_VLC;
  106.  
  107.  if ($p_VLC == ""){
  108.  $p_VLC = inputfile("<curpath>", "exe", "Select vlc.exe - Please ENABLE PERMANENT VARIABLES");
  109.  perm $p_VLC;
  110.  }
  111.  
  112.  // "Get Full Video - VLC" globals
  113.  global $g_Menu;
  114.  global $g_AvailableQualities;
  115.  
  116.  // "_RegEx_Iso" globals
  117.  global $g_RegEx_Haystack;                     
  118.  global $g_RegEx_Needles;                  
  119.  global $g_RegEx_Marker;                   
  120.  global $g_RegEx_Result;
  121.  
  122.  //Variables called $YoutubeSource_XYZ contain original Youtube source code  
  123.  
  124.  // Initialize variables that need to be empty before first use
  125.  $ParsedQualities = "";
  126.  $g_AvailableQualities = "";
  127.  
  128. /* Read Youtube video page content */
  129.  if (regexmatches (<clipboard>, "http[s]?://www\.youtube\.com[^ ]+", "", "0")){
  130.   $YoutubeSource_URL = <clipboard>;
  131.  } else {
  132.   $YoutubeSource_URL = input ("Youtube", "Paste Youtube video URL here", "", "s", "", "300", "200");
  133.  }  
  134.  
  135.  $YoutubeSource_All = readurl ("$YoutubeSource_URL");
  136.  
  137. /* Find the video title */
  138.  $VideoTitle = regexmatches ($YoutubeSource_All, "<title>.+<\/title>", "", "0");
  139.  $VideoTitle = regexreplace ($VideoTitle, "<title>|<\/title>", "", "0");
  140.  $VideoTitle = regexreplace ($VideoTitle, " - Youtube", "", "0");
  141.  $VideoTitle = regexreplace ($VideoTitle, "&quot;|&#34;", '"', "0");
  142.  $VideoTitle = replacelist($VideoTitle, "&amp;,&#38;,&apos;,&#39;,&lt;,&#60;,&gt;,&#62;", "&,&,',',<,<,>,>", ",");
  143.  $VideoTitle = replacelist($VideoTitle, "/,\,:,*,?,<,>,|", "", ",");
  144.  
  145. /* Isolate different quality maps. Quality maps are delimited by "|" in $YoutubeSource_QualityMap */
  146.  $g_RegEx_Haystack = $YoutubeSource_All;                       
  147.  $g_RegEx_Needles = quote("url_encoded_fmt_stream_map"": ""[^""]*", "0")."~"."\w+=[^,]+";
  148.  $g_RegEx_Marker = "~";
  149.  sub "_RegEx_Iso";
  150.  $YoutubeSource_QualityMap = $g_RegEx_Result;
  151.  
  152. /* Isolate available qualities */
  153.  foreach ($Quality, $YoutubeSource_QualityMap, "|"){
  154.   // Decode URL and replace \\u0026 and "sig"
  155.   $Quality = urldecode ($Quality, "1");
  156.   $Quality = regexreplace ($Quality, "\\u0026", "&", "0");
  157.   $Quality = regexreplace ($Quality, "sig", "signature", "0");
  158.  
  159.   // Youtube URL generation is dynamic. First make sure "http://..." is at start of URL
  160.   // Note that http://...?parameter=xyz will contain 1 URL parameter that does not start with &
  161.   $Quality = regexreplace ($Quality, "[&]?url=", "", "0");
  162.   $Http = regexmatches ($Quality, "http:[^&]+", "|", "0");
  163.   $Quality = $Http.regexreplace ($Quality, "http:[^&]+", "", "0");
  164.  
  165.   // Find URL specific itag value, isolate, and replace with single occurence of "itag=..."
  166.   $Itag = regexreplace (regexmatches ("$Quality", "[&]?itag=\d{1,3}", "@", "0"),"[&]?itag=|@[&]?itag=\d+","","0");
  167.   $Quality = regexreplace ($Quality, "[&]?(type|quality|itag|fallback_host)=[^&]+", "", "0")."&itag=$Itag";
  168.  
  169.   $ParsedQualities = $ParsedQualities.$Quality."|";
  170.   $g_AvailableQualities = $g_AvailableQualities.$Itag."|";
  171.  }
  172.  
  173.  sub "_IdentItag";
  174.  $RequestedVideos = inputselect ("Youtube.com", $g_Menu, "|", "0", , "300", , );
  175.  
  176.  // The script currently processes one video at a time.
  177.  // This foreach loop has been implemented with the goal of supporting processing of multiple videos
  178.  // one after the other (Batch style) in future versions of this script
  179.  foreach ($Video, $RequestedVideos, "|"){
  180.   $Itag = replacelist(regexmatches ($Video, "\[\d+\]", "", "0"), "[,]", "", "", "0");
  181.   $VideoExt = recase(regexmatches ($Video, "3GP|FLV|MP4|WebM", "", "0"), "l", );
  182.   $Url = regexmatches ($ParsedQualities, "[^|]*itag=$Itag[^|]*", "", "0");
  183.   $VLCcommand = quote("$p_VLC", "0")." --sout=#file{""dst=$VideoTitle.$VideoExt""} :sout-keep ".quote("$Url", "0")." vlc://quit";
  184.   run($VLCcommand, , );
  185.  }
  186.  }
  187.  
  188. "Get Audio Only - VLC"
  189.  {
  190. /* VARIABLES */
  191.  
  192.  global $p_VLC;
  193.  
  194.  if ($p_VLC == ""){
  195.  $p_VLC = inputfile("<curpath>", "exe", "Select vlc.exe - Please ENABLE PERMANENT VARIABLES");
  196.  perm $p_VLC;
  197.  }
  198.  
  199.  // "Get Audio Only - VLC" globals
  200.  global $g_Menu;
  201.  global $g_AvailableQualities;
  202.  
  203.  // "_RegEx_Iso" globals
  204.  global $g_RegEx_Haystack;                     
  205.  global $g_RegEx_Needles;                  
  206.  global $g_RegEx_Marker;                   
  207.  global $g_RegEx_Result;
  208.  
  209.  //Variables called $YoutubeSource_XYZ contain original Youtube source code  
  210.  
  211.  // Initialize variables that need to be empty before first use
  212.  $ParsedQualities = "";
  213.  $g_AvailableQualities = "";
  214.  
  215. /* Read Youtube video page content */
  216.  if (regexmatches (<clipboard>, "http[s]?://www\.youtube\.com[^ ]+", "", "0")){
  217.   $YoutubeSource_URL = <clipboard>;
  218.  } else {
  219.   $YoutubeSource_URL = input ("Youtube", "Paste Youtube video URL here", "", "s", "", "300", "200");
  220.  }  
  221.  
  222.  $YoutubeSource_All = readurl ("$YoutubeSource_URL");
  223.  
  224. /* Find the video title */
  225.  $VideoTitle = regexmatches ($YoutubeSource_All, "<title>.+<\/title>", "", "0");
  226.  $VideoTitle = regexreplace ($VideoTitle, "<title>|<\/title>", "", "0");
  227.  $VideoTitle = regexreplace ($VideoTitle, " - Youtube", "", "0");
  228.  $VideoTitle = regexreplace ($VideoTitle, "&quot;|&#34;", '"', "0");
  229.  $VideoTitle = replacelist($VideoTitle, "&amp;,&#38;,&apos;,&#39;,&lt;,&#60;,&gt;,&#62;", "&,&,',',<,<,>,>", ",");
  230.  $VideoTitle = replacelist($VideoTitle, "/,\,:,*,?,<,>,|", "", ",");
  231.  
  232. /* Isolate different quality maps. Quality maps are delimited by "|" in $YoutubeSource_QualityMap */
  233.  $g_RegEx_Haystack = $YoutubeSource_All;                       
  234.  $g_RegEx_Needles = quote("url_encoded_fmt_stream_map"": ""[^""]*", "0")."~"."\w+=[^,]+";
  235.  $g_RegEx_Marker = "~";
  236.  sub "_RegEx_Iso";
  237.  $YoutubeSource_QualityMap = $g_RegEx_Result;
  238.  
  239. /* Isolate available qualities */
  240.  foreach ($Quality, $YoutubeSource_QualityMap, "|"){
  241.   // Decode URL and replace \\u0026 and "sig"
  242.   $Quality = urldecode ($Quality, "1");
  243.   $Quality = regexreplace ($Quality, "\\u0026", "&", "0");
  244.   $Quality = regexreplace ($Quality, "sig", "signature", "0");
  245.  
  246.   // Youtube URL generation is dynamic. First make sure "http://..." is at start of URL
  247.   // Note that http://...?parameter=xyz will contain 1 URL parameter that does not start with &
  248.   $Quality = regexreplace ($Quality, "[&]?url=", "", "0");
  249.   $Http = regexmatches ($Quality, "http:[^&]+", "|", "0");
  250.   $Quality = $Http.regexreplace ($Quality, "http:[^&]+", "", "0");
  251.  
  252.   // Find URL specific itag value, isolate, and replace with single occurence of "itag=..."
  253.   $Itag = regexreplace (regexmatches ("$Quality", "[&]?itag=\d{1,3}", "@", "0"),"[&]?itag=|@[&]?itag=\d+","","0");
  254.   $Quality = regexreplace ($Quality, "[&]?(type|quality|itag|fallback_host)=[^&]+", "", "0")."&itag=$Itag";
  255.  
  256.   $ParsedQualities = $ParsedQualities.$Quality."|";
  257.   $g_AvailableQualities = $g_AvailableQualities.$Itag."|";
  258.  }
  259.  
  260.  //text  $ParsedQualities;
  261.  sub "_IdentItag";
  262.  $RequestedVideos = inputselect ("Youtube.com", $g_Menu, "|", "0", , "300", , );
  263.  
  264. // The script currently processes one video at a time.
  265. // This foreach loop has been implemented with the goal of supporting processing of multiple videos
  266. // one after the other (Batch style) in future versions of this script  
  267.  foreach ($Video, $RequestedVideos, "|"){
  268.   $Itag = replacelist(regexmatches ($Video, "\[\d+\]", "", "0"), "[,]", "", "", "0");
  269.   $VideoExt = recase(regexmatches ($Video, "3GP|FLV|MP4|WebM", "", "0"), "l", );  
  270.   $Url = regexmatches ($ParsedQualities, "[^|]*itag=$Itag[^|]*", "", "0");
  271.   $VLCcommand = quote("$p_VLC", "0")." --sout=#transcode{vcodec=none}:file{dst=""$VideoTitle.$VideoExt""} :sout-keep ".quote("$Url", "0")." vlc://quit";
  272.   run($VLCcommand, , );
  273.  }
  274.  }
  275.  
  276. "Get Video Only - VLC"
  277.  {
  278. /* VARIABLES */
  279.  
  280.  global $p_VLC;
  281.  
  282.  if ($p_VLC == ""){
  283.  $p_VLC = inputfile("<curpath>", "exe", "Select vlc.exe - Please ENABLE PERMANENT VARIABLES");
  284.  perm $p_VLC;
  285.  }
  286.  
  287.  // "Get Video Only - VLC" globals
  288.  global $g_Menu;
  289.  global $g_AvailableQualities;
  290.  
  291.  // "_RegEx_Iso" globals
  292.  global $g_RegEx_Haystack;                     
  293.  global $g_RegEx_Needles;                  
  294.  global $g_RegEx_Marker;                   
  295.  global $g_RegEx_Result;
  296.  
  297.  //Variables called $YoutubeSource_XYZ contain original Youtube source code  
  298.  
  299.  // Initialize variables that need to be empty before first use
  300.  $ParsedQualities = "";
  301.  $g_AvailableQualities = "";
  302.  
  303. /* Read Youtube video page content */
  304.  if (regexmatches (<clipboard>, "http[s]?://www\.youtube\.com[^ ]+", "", "0")){
  305.   $YoutubeSource_URL = <clipboard>;
  306.  } else {
  307.   $YoutubeSource_URL = input ("Youtube", "Paste Youtube video URL here", "", "s", "", "300", "200");
  308.  }  
  309.  
  310.  $YoutubeSource_All = readurl ("$YoutubeSource_URL");
  311.  
  312. /* Find the video title */
  313.  $VideoTitle = regexmatches ($YoutubeSource_All, "<title>.+<\/title>", "", "0");
  314.  $VideoTitle = regexreplace ($VideoTitle, "<title>|<\/title>", "", "0");
  315.  $VideoTitle = regexreplace ($VideoTitle, " - Youtube", "", "0");
  316.  $VideoTitle = regexreplace ($VideoTitle, "&quot;|&#34;", '"', "0");
  317.  $VideoTitle = replacelist($VideoTitle, "&amp;,&#38;,&apos;,&#39;,&lt;,&#60;,&gt;,&#62;", "&,&,',',<,<,>,>", ",");
  318.  $VideoTitle = replacelist($VideoTitle, "/,\,:,*,?,<,>,|", "", ",");
  319.  
  320. /* Isolate different quality maps. Quality maps are delimited by "|" in $YoutubeSource_QualityMap */
  321.  $g_RegEx_Haystack = $YoutubeSource_All;                       
  322.  $g_RegEx_Needles = quote("url_encoded_fmt_stream_map"": ""[^""]*", "0")."~"."\w+=[^,]+";
  323.  $g_RegEx_Marker = "~";
  324.  sub "_RegEx_Iso";
  325.  $YoutubeSource_QualityMap = $g_RegEx_Result;
  326.  
  327. /* Isolate available qualities */
  328.  foreach ($Quality, $YoutubeSource_QualityMap, "|"){
  329.   // Decode URL and replace \\u0026 and "sig"
  330.   $Quality = urldecode ($Quality, "1");
  331.   $Quality = regexreplace ($Quality, "\\u0026", "&", "0");
  332.   $Quality = regexreplace ($Quality, "sig", "signature", "0");
  333.  
  334.   // Youtube URL generation is dynamic. First make sure "http://..." is at start of URL
  335.   // Note that http://...?parameter=xyz will contain 1 URL parameter that does not start with &
  336.   $Quality = regexreplace ($Quality, "[&]?url=", "", "0");
  337.   $Http = regexmatches ($Quality, "http:[^&]+", "|", "0");
  338.   $Quality = $Http.regexreplace ($Quality, "http:[^&]+", "", "0");
  339.  
  340.   // Find URL specific itag value, isolate, and replace with single occurence of "itag=..."
  341.   $Itag = regexreplace (regexmatches ("$Quality", "[&]?itag=\d{1,3}", "@", "0"),"[&]?itag=|@[&]?itag=\d+","","0");
  342.   $Quality = regexreplace ($Quality, "[&]?(type|quality|itag|fallback_host)=[^&]+", "", "0")."&itag=$Itag";
  343.  
  344.   $ParsedQualities = $ParsedQualities.$Quality."|";
  345.   $g_AvailableQualities = $g_AvailableQualities.$Itag."|";
  346.  }
  347.  
  348.  //text  $ParsedQualities;
  349.  sub "_IdentItag";
  350.  $RequestedVideos = inputselect ("Youtube.com", $g_Menu, "|", "0", , "300", , );
  351.  
  352. // The script currently processes one video at a time.
  353. // This foreach loop has been implemented with the goal of supporting processing of multiple videos
  354. // one after the other (Batch style) in future versions of this script  
  355.  foreach ($Video, $RequestedVideos, "|"){
  356.   $Itag = replacelist(regexmatches ($Video, "\[\d+\]", "", "0"), "[,]", "", "", "0");
  357.   $VideoExt = recase(regexmatches ($Video, "3GP|FLV|MP4|WebM", "", "0"), "l", );  
  358.   $Url = regexmatches ($ParsedQualities, "[^|]*itag=$Itag[^|]*", "", "0");
  359.   $VLCcommand = quote("$p_VLC", "0")." --sout=#transcode{acodec=none}:file{dst=""$VideoTitle.$VideoExt""} :sout-keep ".quote("$Url", "0")." vlc://quit";
  360.   run($VLCcommand, , );
  361.  }
  362.  }
  363.  
  364. "Batch MP3 Encoder - VLC"
  365.  
  366.  /* VARIABLES */
  367.  
  368.  global $p_VLC;
  369.  
  370.  if ($p_VLC == ""){
  371.  $p_VLC = inputfile("<curpath>", "exe", "Select vlc.exe - Please ENABLE PERMANENT VARIABLES");
  372.  perm $p_VLC;
  373.  }
  374.  
  375.  // "Podcast Encoder - VLC" globals
  376.  global $g_Menu;
  377.  global $g_AvailableQualities;
  378.  
  379.  // "_RegEx_Iso" globals
  380.  global $g_RegEx_Haystack;                     
  381.  global $g_RegEx_Needles;                  
  382.  global $g_RegEx_Marker;                   
  383.  global $g_RegEx_Result;
  384.  
  385.  //Variables called $YoutubeSource_XYZ contain original Youtube source code  
  386.  
  387.  
  388.  
  389.  // Ask user to provide desired links
  390.  $Links = input("Podcast Encoder", "Paste Youtube links of all videos you want encoded to podcast. 1 Link per line!", "", "m", "400", "600");
  391.  
  392. /* Read Youtube video page content */
  393.  foreach ($YoutubeSource_URL, $Links, "<crlf>"){
  394.  
  395.  // Initialize variables that need to be empty before  use
  396.  $ParsedQualities = "";
  397.  $g_AvailableQualities = "";
  398.  $YoutubeSource_All = readurl ($YoutubeSource_URL);
  399.  
  400. /* Find the video title */
  401.  $VideoTitle = regexmatches ($YoutubeSource_All, "<title>.+<\/title>", "", "0");
  402.  $VideoTitle = regexreplace ($VideoTitle, "<title>|<\/title>", "", "0");
  403.  $VideoTitle = regexreplace ($VideoTitle, " - Youtube", "", "0");
  404.  $VideoTitle = regexreplace ($VideoTitle, "&quot;|&#34;", '"', "0");
  405.  $VideoTitle = replacelist($VideoTitle, "&amp;,&#38;,&apos;,&#39;,&lt;,&#60;,&gt;,&#62;", "&,&,',',<,<,>,>", ",");
  406.  $VideoTitle = replacelist($VideoTitle, "/,\,:,*,?,<,>,|", "", ",");
  407.  
  408. /* Isolate different quality maps. Quality maps are delimited by "|" in $YoutubeSource_QualityMap */
  409.  $g_RegEx_Haystack = $YoutubeSource_All;                       
  410.  $g_RegEx_Needles = quote("url_encoded_fmt_stream_map"": ""[^""]*", "0")."~"."\w+=[^,]+";
  411.  $g_RegEx_Marker = "~";
  412.  sub "_RegEx_Iso";
  413.  $YoutubeSource_QualityMap = $g_RegEx_Result;
  414.  
  415. /* Isolate available qualities */
  416.  foreach ($Quality, $YoutubeSource_QualityMap, "|"){
  417.   // Decode URL and replace \\u0026 and "sig"
  418.   $Quality = urldecode ($Quality, "1");
  419.   $Quality = regexreplace ($Quality, "\\u0026", "&", "0");
  420.   $Quality = regexreplace ($Quality, "sig", "signature", "0");
  421.  
  422.   // Youtube URL generation is dynamic. First make sure "http://..." is at start of URL
  423.   // Note that http://...?parameter=xyz will contain 1 URL parameter that does not start with &
  424.   $Quality = regexreplace ($Quality, "[&]?url=", "", "0");
  425.   $Http = regexmatches ($Quality, "http:[^&]+", "|", "0");
  426.   $Quality = $Http.regexreplace ($Quality, "http:[^&]+", "", "0");
  427.  
  428.   // Find URL specific itag value, isolate, and replace with single occurence of "itag=..."
  429.   $Itag = regexreplace (regexmatches ("$Quality", "[&]?itag=\d{1,3}", "@", "0"),"[&]?itag=|@[&]?itag=\d+","","0");
  430.   $Quality = regexreplace ($Quality, "[&]?(type|quality|itag|fallback_host)=[^&]+", "", "0")."&itag=$Itag";
  431.  
  432.   $ParsedQualities = $ParsedQualities.$Quality."|";
  433.   $g_AvailableQualities = $g_AvailableQualities.$Itag."|";
  434.  }
  435.  
  436.  sub "_IdentItag";
  437.  $Video = regexmatches($g_Menu, "^[^|]+", "", "0"); //We pick the highest available quality here
  438.  
  439.  $Itag = replacelist(regexmatches ($Video, "\[\d+\]", "", "0"), "[,]", "", "", "0");
  440.  $Url = regexmatches ($ParsedQualities, "[^|]*itag=$Itag[^|]*", "", "0");
  441.  
  442.  $VLCcommand = quote("$p_VLC", "0")." --sout=#transcode{vcodec=none,acodec=mp3,ab=192,channels=2,samplerate=48000}:file{dst=""$VideoTitle.mp3""} :sout-keep ".quote("$Url", "0")." vlc://quit";
  443.  run($VLCcommand, , "1", "1");
  444.  }
  445.  
  446.  
  447.  
  448. "_RegEx_Iso"
  449.  {
  450. /*
  451.  _RegEx_Iso is a sub script that will recursively search a text source.
  452.  By using sequenced regular expressions it is able to isolate embedded text that you
  453.  can not isolate using just a single regular expression.
  454.  
  455.  You must define global variables Haystack, Needles, and Marker in your script as the "arguments"
  456.  to the "method" _RegEx_Iso.
  457.  
  458.  E.g:
  459.  
  460.  $g_RegEx_Haystack = $Source;
  461.  $g_RegEx_Needles = "www\.youtube\.com\/user\/[^""]+"."~"."[^\/]+$";
  462.  $g_RegEx_Marker = "~";
  463.  sub "_RegEx_Iso";
  464.  
  465.  text $g_RegEx_Result;
  466. */  
  467.  
  468.  global $g_RegEx_Haystack;                      // Text source to search in
  469.  global $g_RegEx_Needles;                       // List of recursive regex to be used
  470.  global $g_RegEx_Marker;                        // Delimiting character used to sequence list of regex
  471.  global $g_RegEx_Result;                        // Result of the search are demarked by "|"
  472.  
  473.  $j = $g_RegEx_Haystack;
  474.  $k = $g_RegEx_Needles;
  475.  $l = $g_RegEx_Marker;
  476.  
  477.  foreach ($i, $k, $l){
  478.   $j = regexmatches ("$j", "$i", "|", "0");
  479.  }
  480.  $g_RegEx_Result = $j;
  481.  
  482. /*
  483. */
  484.  }
  485.  
  486. "_DEBUGRegEx_Iso"
  487.  {
  488. /*
  489.  _DEBUGRegEx_Iso will do exactly the same as "_RegEx_Iso".
  490.  In addition it will show the Haystack, Needle, Marker and Result for each
  491.  recursive regular expression cycle. Useful to identify buggy behavior.
  492. */  
  493.  
  494.  global $g_RegEx_Haystack;
  495.  global $g_RegEx_Needles;
  496.  global $g_RegEx_Marker;
  497.  global $g_RegEx_Result;
  498.  
  499.  $j = $g_RegEx_Haystack;
  500.  $k = $g_RegEx_Needles;
  501.  $l = $g_RegEx_Marker;
  502.  
  503.  foreach ($i, $k, $l){
  504.   text "$j";
  505.   $j = regexmatches ("$j", "$i", "|", "0");
  506.   text "$j <crlf 2>$i <crlf 2>$l";
  507.  }
  508.  $g_RegEx_Result = $j;  
  509.  
  510. /*
  511. */
  512.  }
  513.  
  514. "_IdentItag"
  515.  {
  516. /*
  517.  IdentItag searches a local database for the requested itag and returns a list that is used in the
  518.  quality selection menu
  519. */
  520.  
  521.  global $g_Menu;
  522.  global $g_AvailableQualities;
  523.  
  524.  $ThreeGP =
  525.  "
  526. >[36] 240p - 3GP
  527. >[17] 144p - 3GP
  528. >[13] Unknown - 3GP
  529. ";
  530.  
  531.  $Flv =
  532.  "
  533. >[35] 480p - FLV
  534. >[34] 360p - FLV
  535. >[06] 270p - FLV
  536. >[05] 240p - FLV
  537. ";
  538.  
  539.  $Webm =
  540.  "
  541. >[46] 1080p - WebM
  542. >[45] 720p - WebM
  543. >[44] 480p - WebM
  544. >[43] 360p - WebM
  545. ";
  546.  
  547.  $Mp4 =
  548.  "
  549. >[38] 3072p - MP4
  550. >[37] 1080p - MP4
  551. >[22] 720p - MP4
  552. >[18] 360p - MP4
  553. ";
  554.  
  555.  $Db = replace($ThreeGP.$Flv.$Webm.$Mp4, " >", "", "0", , );
  556.  $g_Menu = "";
  557.  foreach ($Option, $g_AvailableQualities, "|"){
  558.   $g_Menu = $g_Menu.regexmatches($Db, "\[[0]?$Option\][^\[]+", "", "0")."|";
  559.  }
  560.  
  561. /*
  562. */
  563.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement