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.

 
  1. The setup: Notepad++ and pretty much any browser (and a very rudimentary understanding of regular expressions)
  2. Get the source code for the thread (Ctrl + U on Chrome). Paste on new document on Notepad++
  3. Pop up Search and replace
    Ctrl + H
    and check "Regular expression" and ". matches newline" options

  4. Strip all href's from "a" tags. Search
    .*?<a href="(.*?)"
    and replace with
    $1\n

  5. Manually Look for the last youtube link and delete everything after it

  6. 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)

  7. Get only the video IDs (which on youtube are 11 alphanumeric characters with "-" and "_" added. Search for
    .*?([\w-]{11}.*?)\n
    and replace with
    $1,

  8. 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

  9. In your browser, type
    https://youtube.com/watch_videos?video_ids=
    and paste all your IDs at the end of the URL so you get
    video_ids=ID1,ID2...
    and press enter

  10. You should get a new untitled playlist containing all the videos specified. This apparently works even if you're not signed in. Enjoy!

As I said, this is a very inelegant workaround, but I'm sure it's something more people could benefit from. It would be nice to have some sort of auto-playlist for these threads the way radd.it does for reddit threads, but I don't think it's a high priority request for a feature.

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
posted by andycyca to MetaFilter-Related at 11:07 PM (5 comments total) 7 users marked this as a favorite

Great job in doing this and in writing the explanation. As someone familiar with regexes I can tell you that you definitely can do this in fewer steps but your process was very sound.

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]


I believe that the following regex (assuming that notepad++ supports it) would do all the work for you:

.+?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


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
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


« Older State of MetaFilter, 2017   |   Metatalktail Hour: The Last First Time Newer »

You are not logged in, either login or create an account to post comments