Skip to content

Instantly share code, notes, and snippets.

@breadlesscode
Created July 29, 2020 21:02
Show Gist options
  • Save breadlesscode/72ad312d822bb3ca07242d37fdc0e13d to your computer and use it in GitHub Desktop.
Save breadlesscode/72ad312d822bb3ca07242d37fdc0e13d to your computer and use it in GitHub Desktop.
Finds all YouTube and YT Music IDs and create playlist links
<?php
$matches = [];
$content = file_get_contents('inputfile.txt');
$pattern = '#.*http[s]?:\/\/(music\.)?youtube\.com\/watch\?v=([[:alnum:]_-]{4,18}).*#';
preg_match_all($pattern, $content, $matches);
echo count($matches[2])." Videos found\n\n";
$chunks = array_chunk($matches[2], 50);
foreach ($chunks as $ids) {
echo "https://www.youtube.com/watch_videos?video_ids=".implode(',', $ids)."\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment