Skip to content

Instantly share code, notes, and snippets.

@JTBrinkmann
Created June 6, 2020 20:39
Show Gist options
  • Save JTBrinkmann/d0145014ea2b4e98003cc863ba57b800 to your computer and use it in GitHub Desktop.
Save JTBrinkmann/d0145014ea2b4e98003cc863ba57b800 to your computer and use it in GitHub Desktop.
very small webapp to create an anonymous youtube playlist from a few videos
<!DOCTYPE html>
<body style="font-family: sans-serif;">
<p>
<label>
Youtube URLs:<br>
<textarea id="input" style="box-sizing: content-box; width: 100%; min-height: 8em; line-height: 1.4em; padding: 0.2em"></textarea>
</label>
</p>
<p>
<label>
<input type="checkbox" id="removeDuplicates" /> Remove duplicates
</label>
</p>
<p>
<label>
Playlist URL:<br>
<input id="output" disabled style="box-sizing: border-box; width: 100%;" />
</label>
</p>
<script>
const INPUT_LINE_HEIGHT = 1.4 // em
const INPUT_PADDING = 0.2 // em
const $input = document.getElementById('input')
const $output = document.getElementById('output')
const $removeDuplicates = document.getElementById('removeDuplicates')
const ytIdRx = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/gi;
const update = () => {
let matches = Array.from($input.value.matchAll(ytIdRx))
.map(([_, id]) => id)
if (matches.length === 0) {
matches = ['id1', 'id2', '...']
} else if ($removeDuplicates.checked) {
matches = matches.filter(
(id, i) => matches.indexOf(id) === i
)
}
$output.value = `https://www.youtube.com/watch_videos?video_ids=${matches.join(',')}`
// resize input textarea
const lineCount = $input.value.match(/^/gm).length
$input.style.height = `${lineCount*INPUT_LINE_HEIGHT + 2*INPUT_PADDING}em`
}
$input.addEventListener('input', update)
$removeDuplicates.addEventListener('input', update)
update()
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment