Disposable YouTube playlists from recommendation threads March 24, 2017 11:07 PM Subscribe
The other day I recommended some songs on an AskMeFi thread and, after some fiddling, I compiled almost all the links in two disposable YouTube playlists. Today, while catching up on a year of podcasts, I noticed that in Best of the Web Ep. 112 they talked about this exact issue and the partial solution that exists on Labs.
I figured I should share my notes with the rest of the class to figure out how to improve on this long-sought question.
First of all, I must say that this my solution is the very definition of a bodge. It does the job but it's inelegant, not optimized and prone to breaking if YouTube changes one thing. Here's how I did it, hoping you'll help me reach a better solution.
Summary: Get all the youtube links from the thread. Get all the youtube video IDs (either from a youtube.com/v=ID URL, or a youtu.be/ID shortened URL. String these IDs together with a comma and put them in a special URL to create an untitled YouTube playlist that works even if you're not signed in, with the caveat that it holds only up to 50 videos per playlist.
Help me improve this solution, please? (and for those who didn't know about this, enjoy!)
I emailed the admins and was told this was the appropriate place for this question. Please don't bite me
First of all, I must say that this my solution is the very definition of a bodge. It does the job but it's inelegant, not optimized and prone to breaking if YouTube changes one thing. Here's how I did it, hoping you'll help me reach a better solution.
Summary: Get all the youtube links from the thread. Get all the youtube video IDs (either from a youtube.com/v=ID URL, or a youtu.be/ID shortened URL. String these IDs together with a comma and put them in a special URL to create an untitled YouTube playlist that works even if you're not signed in, with the caveat that it holds only up to 50 videos per playlist.
- The setup: Notepad++ and pretty much any browser (and a very rudimentary understanding of regular expressions)
- Get the source code for the thread (Ctrl + U on Chrome). Paste on new document on Notepad++
- Pop up Search and replace
Ctrl + H
and check "Regular expression" and ". matches newline" options - Strip all href's from "a" tags. Search
.*?<a href="(.*?)"
and replace with$1\n
- Manually Look for the last youtube link and delete everything after it
- Get all the youtube.com or youtu.be links and list them. Search for
.*?(https\:\/\/www\.yo.*?|https\:\/\/yo.*?)\n
and replace with$1\n
(I suspect this step is unnecessary with proper regex skills, but I did it anyway to make sure I wasn't skipping any links) - Get only the video IDs (which on youtube are 11 alphanumeric characters with "-" and "_" added. Search for
.*?([\w-]{11}.*?)\n
and replace with$1,
- Get rid of all timestamps, if any (they are in the t= format), join lines (in updated Notepad++ versions, select all and use Ctrl + J or go to Edit → Line operations → Join lines) and eliminate spaces. You should have a single line of IDs divided only by a comma. If there are more than 50 IDs, you should divide them in chunks of up to 50 for the next part to work
- In your browser, type
https://youtube.com/watch_videos?video_ids=
and paste all your IDs at the end of the URL so you getvideo_ids=ID1,ID2...
and press enter - You should get a new untitled playlist containing all the videos specified. This apparently works even if you're not signed in. Enjoy!
Help me improve this solution, please? (and for those who didn't know about this, enjoy!)
I emailed the admins and was told this was the appropriate place for this question. Please don't bite me
I believe that the following regex (assuming that notepad++ supports it) would do all the work for you:
Replace with
The last item in the list will have all of the html following the last YouTube video id, which you can delete.
Please double check the regex. I am writing it out on the phone without the benefit of an actual editor to test it with.
posted by Deathalicious at 7:46 AM on March 25, 2017 [2 favorites]
.+?href="https://yout[^/]+/(?:watch\?v=)?(\w{11})
Replace with
$1,
The last item in the list will have all of the html following the last YouTube video id, which you can delete.
Please double check the regex. I am writing it out on the phone without the benefit of an actual editor to test it with.
posted by Deathalicious at 7:46 AM on March 25, 2017 [2 favorites]
this is an absolutely amazing topic and I would be so pleased if someone were to create a bookmarklet or plug-in that could do this!
Or, heh, maybe the MetaFilter youtube account (if one exists) could playlistify all threads?
posted by rebent at 8:25 PM on March 25, 2017
Or, heh, maybe the MetaFilter youtube account (if one exists) could playlistify all threads?
posted by rebent at 8:25 PM on March 25, 2017
Deathalicious: "so if you're interested and I can find it I'm happy to "lend" it to you."
I'm always more than happy to borrow books! (although a quick search suggests the shipping costs might be somewhat high). Let's do this!
Deathalicious: "I believe that the following regex (assuming that notepad++ supports it) would do all the work for you:"
This regex, applied to this AskMeFi thread source, under my Notepad++ setup, spits out only 3 IDs, namely
I figure I should "translate" your regex into a format accepted by Notepad++...
rebent: "I would be so pleased if someone were to create a bookmarklet or plug-in that could do this!"
I'm sure there's a a relatively easy way to do this, hence this post. However, I haven't figured out how to do it.
posted by andycyca at 11:51 PM on March 25, 2017
I'm always more than happy to borrow books! (although a quick search suggests the shipping costs might be somewhat high). Let's do this!
Deathalicious: "I believe that the following regex (assuming that notepad++ supports it) would do all the work for you:"
This regex, applied to this AskMeFi thread source, under my Notepad++ setup, spits out only 3 IDs, namely
6FidZlbZLCc,4XJxFAoiWSY,zoo9Vu1a9bU,,However, being the regex newbie that I am, I should point that, for some reason, a few hours ago Notepad++ refused to recognize \n as a valid string and would only accept "$" for a newline character. Maybe I inadvertently broke something in my computer, but I haven't figured out what. A simple restart made this problem go away.
I figure I should "translate" your regex into a format accepted by Notepad++...
rebent: "I would be so pleased if someone were to create a bookmarklet or plug-in that could do this!"
I'm sure there's a a relatively easy way to do this, hence this post. However, I haven't figured out how to do it.
posted by andycyca at 11:51 PM on March 25, 2017
>> .+?href="https://yout[^/]+/(?:watch\?v=)?(\w{11})
> This regex, applied to this AskMeFi thread source, under my Notepad++ setup, spits out only 3 IDs
It's missing HTTP links, links with www, and ones with - or _ in them. This appears to catch all those cases (but I'm still a regex newbie, and there may be more cases I didn't spot).
.+?href="https?://(www.)?yout[^/]+/(?:watch\?v=)?([\w_-]{11})
replace with
$2,
Also, note that in Notepad++, you must have checked the box ". matches newline" for this to work as expected. (Guess what I spent the last few minutes trying to diagnose...)
posted by yuwtze at 10:24 AM on March 27, 2017
> This regex, applied to this AskMeFi thread source, under my Notepad++ setup, spits out only 3 IDs
It's missing HTTP links, links with www, and ones with - or _ in them. This appears to catch all those cases (but I'm still a regex newbie, and there may be more cases I didn't spot).
.+?href="https?://(www.)?yout[^/]+/(?:watch\?v=)?([\w_-]{11})
replace with
$2,
Also, note that in Notepad++, you must have checked the box ". matches newline" for this to work as expected. (Guess what I spent the last few minutes trying to diagnose...)
posted by yuwtze at 10:24 AM on March 27, 2017
You are not logged in, either login or create an account to post comments
If you're interested in finding out more about what regular expressions can do I highly recommend the book Mastering Regular Expressions which is easily in my top ten list of programming books. One of the few that is genuinely enjoyable to read just for its own sake.
I may even have a copy lying around somewhere so if you're interested and I can find it I'm happy to "lend" it to you.
posted by Deathalicious at 7:33 AM on March 25, 2017 [1 favorite]