How to extract YouTube IDs with Regex and getting poster images

Leaving this for others who might need it (as did I). Extracting the YouTube ID has many benefits, including easier access to the YouTube API functions as well as pulling the default poster image for the video.

To achieve this simply use “:Extract with Regex” and use the following expression:
(?<=watch?v=|/videos/|embed/|youtu.be/|/v/|watch?v%3D|%2Fvideos%2F|embed%2F|youtu.be%2F|%2Fv%2F)[^#&?\n]*

To get YouTube’s poster image (the image that is shown before playback). Just use this path: https://img.youtube.com/vi/{YouTube video ID}/0.jpg

It should work for over 90% of YouTube domains/path variations. You can test if this works for you here.

4 Likes

Bookmarked :smiley:

1 Like

I love me some regex.

Mine was this absurdity:

!(?:\[(.*)?\])\((?:(?:https:\/\/(?:youtu\.be\/)(.*?)(\?.+?)?)(?:\s\"(.*?)\")?)(?:\)(.+)?)|!(?:\[(.*)?\])\((?:https:\/\/www\.youtube\.com\/watch\?((?:.*)*?(?:v\=(.*?)(?:[\&|\#].+?)?))(?:\s\"(.*?)\")?)(?:\)(.+)?)
1 Like

Thanks for sharing your test data, too. FYI:

1 Like

Thanks @rico.trevisan did not know that!