To-Slalom

GrabYoutubeID

Apr 5th, 2019
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. # https://github.com/eyecatchup/php-yt_downloader/blob/master/youtube-dl.class.php#L259
  3. # https://gist.github.com/ghalusa/6c7f3a00fd2383e5ef33
  4. # https://stackoverflow.com/questions/2936467/parse-youtube-video-id-using-preg-match
  5. # https://hotexamples.com/examples/-/-/parse_yturl/php-parse_yturl-function-examples.html
  6.  
  7. # Função simples para obter o id do video do Yoututbe
  8. function GrabYTID ( $url ) {
  9.     preg_match('%(?:m\.|)(?:yout.*)(?:[^\/]+\/|.*[?&]v=)([^"&?\/]{11})%i' , $url , $matches ) ;
  10.     return ( isset ( $matches[1] ) ) ? $matches[1] : $url ;
  11. }
  12.  
  13. $urls = array(
  14.     'http://www.youtube.com/watch?v=4heZkvPcd1M&feature=c4-overview-vl&list=PLbzoR-pLrL6qucl8-lOnzvhFc2UM1tcZA',
  15.     'http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/4heZkvPcd1M',
  16.     'http://www.youtube.com/embed/4heZkvPcd1M',
  17.     'http://www.youtube.com/user/username#p/u/11/4heZkvPcd1M',
  18.     'http://youtube.com/vi/4heZkvPcd1M?feature=youtube_gdata_player',
  19.     'http://www.youtube.com/?feature=player_embedded&v=4heZkvPcd1M',
  20.     'https://www.youtube.com/watch?v=4heZkvPcd1M&list=RDFZu097wb8wUx',
  21.     'http://www.youtube.com/watch?feature=player_embedded&v=4heZkvPcd1M',
  22.     'http://www.youtube.com/v/4heZkvPcd1M',
  23.     'http://www.youtube.com/e/4heZkvPcd1M',
  24.     'http://www.youtube.com/p/4heZkvPcd1M',
  25.     'http://www.youtube.com/?v=4heZkvPcd1M',
  26.     'youtu.be/watch?v=4heZkvPcd1M',
  27.     'youtube.com/watch?v=4heZkvPcd1M',
  28.     'm.youtu.be/watch?v=4heZkvPcd1M',
  29.     'm.youtube.com/watch?v=4heZkvPcd1M',
  30.     'http://www.youtube.com/watch?v=4heZkvPcd1M',
  31.     'http://www.m.youtube.com/watch?v=4heZkvPcd1M',
  32.     'http://www.m.youtu.be/watch?v=4heZkvPcd1M',
  33.     'http://youtu.be/4heZkvPcd1M',
  34.     'https://youtu.be/4heZkvPcd1M',
  35.     'youtu.be/watch?v=4heZkvPcd1M',
  36.     'youtube.com/watch?v=4heZkvPcd1M',
  37.     'https://youtu.be/4heZkvPcd1M',
  38.     'https://www.youtube.com/embed/4heZkvPcd1M',
  39.     'https://www.m.youtube.com/embed/4heZkvPcd1M',
  40.     'http://youtu.be/4heZkvPcd1M',
  41.     'http://www.youtube.com/embed/4heZkvPcd1M',
  42.     'http://www.youtube.com/watch?v=4heZkvPcd1M',
  43.     'http://www.youtube.com/watch?v=4heZkvPcd1M&feature=g-vrec',
  44.     'http://www.youtube.com/watch?v=4heZkvPcd1M&feature=player_embedded',
  45.     'http://www.youtube.com/v/4heZkvPcd1M?fs=1&hl=en_US',
  46.     'http://www.youtube.com/ytscreeningroom?v=4heZkvPcd1M',
  47.     'http://www.youtube.com/watch?NR=1&feature=endscreen&v=4heZkvPcd1M',
  48.     'https://m.youtu.be/4heZkvPcd1M',
  49. );
  50. echo count ( $urls ). "\n" ;
  51. foreach ( $urls as $url ) {
  52.     var_dump ( GrabYTID ($url) ). "\n";
  53. }
RAW Paste Data