Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of the various YouTube url formats
http://www.youtube.com/watch?v=-wtIMTCHWuI
http://www.youtube.com/v/-wtIMTCHWuI?version=3&autohide=1
http://youtu.be/-wtIMTCHWuI
http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D-wtIMTCHWuI&format=json
http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare
https://www.youtube.com/attribution_link?a=8g8kPrPIi-ecwIsS&u=/watch%3Fv%3DyZv2daTWRZU%26feature%3Dem-uploademail
https://www.youtube.com/watch?v=yZv2daTWRZU&feature=em-uploademail
https://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index
https://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o
https://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0
https://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s
https://www.youtube.com/embed/0zM3nApSvMg?rel=0
//www.youtube-nocookie.com/embed/up_lNV-yoK4?rel=0
https://www.youtube-nocookie.com/embed/up_lNV-yoK4?rel=0
http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo
http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel
http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub
http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I
http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be
http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo?rel=0
http://www.youtube.com/embed/nas1rJpm7wY?rel=0
https://www.youtube.com/watch?v=peFZbP64dsU
http://youtube.com/v/dQw4w9WgXcQ?feature=youtube_gdata_player
http://youtube.com/?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/vi/dQw4w9WgXcQ?feature=youtube_gdata_player
http://youtu.be/dQw4w9WgXcQ?feature=youtube_gdata_player
http://www.youtube.com/user/SilkRoadTheatre#p/a/u/2/6dwqZw0j_jY
https://www.youtube.com/watch?v=ishbTyLs6ps&list=PLGup6kBfcU7Le5laEaCLgTKtlDcxMqGxZ&index=106&shuffle=2655
http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0
http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index
http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s
http://www.youtube.com/embed/dQw4w9WgXcQ
http://www.youtube.com/v/dQw4w9WgXcQ
http://www.youtube.com/e/dQw4w9WgXcQ
http://www.youtube.com/?v=dQw4w9WgXcQ
http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ
http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ
http://www.youtube.com/user/IngridMichaelsonVEVO#p/u/11/KdwsulMb8EQ
http://www.youtube-nocookie.com/v/6L3ZvIMwZFM?version=3&hl=en_US&rel=0
http://www.youtube.com/user/dreamtheater#p/u/1/oTJRivZTMLs
https://youtu.be/oTJRivZTMLs?list=PLToa5JuFMsXTNkrLJbRlB--76IAOjRM9b
http://www.youtube.com/watch?v=oTJRivZTMLs&feature=youtu.be
http://youtu.be/oTJRivZTMLs&feature=channel
http://www.youtube.com/ytscreeningroom?v=oTJRivZTMLs
http://www.youtube.com/embed/oTJRivZTMLs?rel=0
http://youtube.com/vi/oTJRivZTMLs&feature=channel
http://youtube.com/?v=oTJRivZTMLs&feature=channel
http://youtube.com/?feature=channel&v=oTJRivZTMLs
http://youtube.com/?vi=oTJRivZTMLs&feature=channel
http://youtube.com/watch?v=oTJRivZTMLs&feature=channel
http://youtube.com/watch?vi=oTJRivZTMLs&feature=channel
https://m.youtube.com/watch?v=m_kbvp0_8tc
https://www.youtube.com/watch?app=desktop&v=dQw4w9WgXcQ
https://m.youtube.com/watch?app=desktop&v=dQw4w9WgXcQ
@rodrigoborgesdeoliveira
Copy link
Author

👍

@VladimirSlavik
Copy link

@gustavoja your last variant (as of now) is pretty great, but there's a catch. It doesn't work too well in some more greedy implementations of regular expression engines. More specifically, it silently fails to grab anything but the last ID when using it to scan a large body of text (eg. dumped page). The reason is that you have .* twice there. I think the first one (after the domain part) could be safely replaced by [^\s] which would still stay universal. I have no idea about the second one.

@gitzec
Copy link

gitzec commented Feb 11, 2021

(?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$)
has no .* 🤔

@VladimirSlavik
Copy link

VladimirSlavik commented Feb 11, 2021

edit: Oh, I see what you mean. You missed this part: "scan a large body of text (eg. dumped page)" Unfortunately I don't see your version as guaranteeing it will grab just the right parts, for me. If I already had an URL, it would be a serious contender, but my inputs are a few kB of HTML.

@NavinAT
Copy link

NavinAT commented Feb 17, 2021

@zec-github I looked at your Regex, is it possible to take Video Id without using that {11} character condition (?:\/|%3D|v=|vi=)([0-9A-z-_]{11})(?:[%#?&]|$) because in future the character length of the Id probably increase.

@deunlee
Copy link

deunlee commented Aug 30, 2021

I made a JavaScript version of the video id extractor.
The full code is here.

function getYouTubeVideoIdByUrl(url) {
    const reg = /^(https?:)?(\/\/)?((www\.|m\.)?youtube(-nocookie)?\.com\/((watch)?\?(feature=\w*&)?vi?=|embed\/|vi?\/|e\/)|youtu.be\/)([\w\-]{10,20})/i
    const match = url.match(reg);
    if (match) {
        return match[9];
    } else {
        return null;
    }
}

ps. I removed 'ytscreeningroom' because it seems deprecated.

@mlatushko
Copy link

mlatushko commented Oct 31, 2021

————————————————————————————————————————
(?-s)^https?\W+(?:www\.|m\.|music\.)*youtu\.?be(?:\.com\/|watch|o?embed(?:\/|\?url=\S+?)?|shorts|attribution_link\?[&\w\-=]*[au]=\/?|ytsc\w+|[\?&]*[ve]i?\b|\?feature=\w+|-nocookie|%[23][56FD])*(?:[\/=]|%2F|%3D)([a-z\d\-_]{11})[\?&#% \t ]? *.*$
or
(?-s)^(?:(?!https?[:\/]|www\.|m\.|youtu|watch\W|embed\W)\V)*(?:https?[:\/]+|www\.|m\.|music\.)+youtu\.?be(?:\.com\/|watch|o?embed(?:\/|\?url=\S+?)?|shorts|attribution_link\?[&\w\-=]*[au]=\/?|ytsc\w+|[\?&]*[ve]i?\b|\?feature=\w+|-nocookie|%[23][56FD])*(?:[\/=]|%2F|%3D)([a-z\d\-_]{11})[\?&#% \t ]? *.*$
(replace to \1)
————————————————————————————————————————

http//www.youtube-nocookie.com/embed/I1I1i1i1I1I?rel=0
http://www.youtube-nocookie.com/v/I1I1i1i1I1I?version=3&hl=en_US&rel=0
http://www.youtube.com/?feature=player_embedded&v=I1I1i1i1I1I
http://www.youtube.com/?v=I1I1i1i1I1I
http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DI1I1i1i1I1I%26feature%3Dshare
http://www.youtube.com/attribution_link?u=/watch?v=I1I1i1i1I1I&feature=share
https://www.youtube.com/attribution_link?a=8g8kPrPIi-ecwIsS&u=/watch%3Fv%3DI1I1i1i1I1I%26feature%3Dem-uploademail
http://www.youtube.com/e/I1I1i1i1I1I
http://www.youtube.com/embed/watch?feature=player_embedded&v=I1I1i1i1I1I
http://www.youtube.com/embed/I1I1i1i1I1I
http://www.youtube.com/embed/I1I1i1i1I1I?rel=0
http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3DI1I1i1i1I1I&format=json
http://www.youtube.com/v/I1I1i1i1I1I
http://www.youtube.com/v/I1I1i1i1I1I?fs=1&hl=en_US&rel=0
http://www.youtube.com/v/I1I1i1i1I1I?version=3&autohide=1
http://www.youtube.com/watch?feature=player_embedded&v=I1I1i1i1I1I
http://www.youtube.com/watch?v=I1I1i1i1I1I
http://www.youtube.com/watch?v=I1I1i1i1I1I#t=0m10s
http://www.youtube.com/watch?v=I1I1i1i1I1I&feature=channel
http://www.youtube.com/watch?v=I1I1i1i1I1I&feature=feedrec_grec_index
http://www.youtube.com/watch?v=I1I1i1i1I1I&feature=related
http://www.youtube.com/watch?v=I1I1i1i1I1I&feature=youtu.be
http://www.youtube.com/watch?v=I1I1i1i1I1I&feature=youtube_gdata_player
http://www.youtube.com/watch?v=I1I1i1i1I1I&playnext_from=TL&videos=osPknwzXEas&feature=sub
http://www.youtube.com/ytscreeningroom?v=I1I1i1i1I1I
http://youtu.be/I1I1i1i1I1I
http://youtu.be/I1I1i1i1I1I&feature=channel
http://youtu.be/I1I1i1i1I1I?feature=youtube_gdata_player
http://youtube.com/?feature=channel&v=I1I1i1i1I1I
http://youtube.com/?v=I1I1i1i1I1I&feature=channel
http://youtube.com/?v=I1I1i1i1I1I&feature=youtube_gdata_player
http://youtube.com/?vi=I1I1i1i1I1I&feature=channel
http://youtube.com/?vi=I1I1i1i1I1I&feature=youtube_gdata_player
http://youtube.com/embed/I1I1i1i1I1I
http://youtube.com/v/I1I1i1i1I1I?feature=youtube_gdata_player
http://youtube.com/vi/I1I1i1i1I1I&feature=channel
http://youtube.com/vi/I1I1i1i1I1I?feature=youtube_gdata_player
http://youtube.com/watch?v=I1I1i1i1I1I&feature=channel
http://youtube.com/watch?v=I1I1i1i1I1I&feature=youtube_gdata_player
http://youtube.com/watch?vi=I1I1i1i1I1I&feature=channel
http://youtube.com/watch?vi=I1I1i1i1I1I&feature=youtube_gdata_player
https://m.youtube.com/watch?v=I1I1i1i1I1I
https://www.youtube-nocookie.com/embed/I1I1i1i1I1I?rel=0
https://www.youtube.com/attribution_link?a=8g8kPrPIi-ecwIsS&u=/watch%3Fv%3DI1I1i1i1I1I%26feature%3Dem-uploademail
https://www.youtube.com/embed/v=I1I1i1i1I1I
https://www.youtube.com/embed/watch?feature=player_embedded&v=I1I1i1i1I1I
https://www.youtube.com/embed/watch?v=I1I1i1i1I1I
https://www.youtube.com/embed/I1I1i1i1I1I?rel=0
https://www.youtube.com/v/I1I1i1i1I1I?fs=1&hl=en_US&rel=0
https://www.youtube.com/watch/I1I1i1i1I1I
https://www.youtube.com/watch?v=I1I1i1i1I1I
https://www.youtube.com/watch?v=I1I1i1i1I1I#t=0m10s
https://www.youtube.com/watch?v=I1I1i1i1I1I&feature=em-uploademail
https://www.youtube.com/watch?v=I1I1i1i1I1I&feature=feedrec_grec_index
https://www.youtube.com/watch?v=I1I1i1i1I1I&feature=share
https://www.youtube.com/watch?v=I1I1i1i1I1I&list=PLGup6kBfcU7Le5laEaCLgTKtlDcxMqGxZ&index=106&shuffle=2655
https://youtu.be/I1I1i1i1I1I
https://youtu.be/I1I1i1i1I1I?list=PLToa5JuFMsXTNkrLJbRlB--76IAOjRM9b
https://youtube.com/shorts/I1I1i1i1I1I?feature=share
www.youtube.com/watch?v=I1I1i1i1I1I
youtu.be/I1I1i1i1I1I
youtube.com/watch?v=I1I1i1i1I1I

/// will not match
http://www.youtube.com/user/IiIiIiIVEVO#p/u/1/I1I1i1i1I1I
http://www.youtube.com/user/IiIiIiIVEVO#p/u/1/I1I1i1i1I1I?rel=0
https://www.youtube.com/feed/subscriptions
https://www.youtube.com/channel/UCgc00bfF_PvO_2AvqJZHXFg
https://www.youtube.com/c/IiIiIiIVEVO/videos
http://www.youtube.com/user/IiIiIiIVEVO#p/u/11/I1I1i1i1I1I
https://www.youtube.com/user/IiIiIiIVEVO#p/a/u/1/I1I1i1i1I1I
http://www.youtube.com/user/IiIiIiIVEVO#p/a/u/2/I1I1i1i1I1I
http://www.youtube.com/user/IiIiIiIVEVO#p/u/1/I1I1i1i1I1I

https://youtu.be/x26ANNC3C-8 𝕳𝕰𝕽𝕰𝕿𝕳𝕰𝖄𝕮𝕺𝕸𝕰 - 𝔩𝔢𝔞𝔳𝔢 𝔪𝔢 𝔞𝔩𝔬𝔫𝔢 • 7:15

————————————————————————————————————————

(форматирование YouTube)█^(?! (<a id="video-ti|</ytd-thumbnail><div id="det|\d+:|htt))\V+\v|^\s+
V█(?-s)^ (?:[\d:]+\r\n)^(\d+:\d+:?\d*)\v+</y\V+?href="/watch?v=([a-z\d_-]{11})["&][^\r\n<>]>([^\r\n<>]+)<\V+(?!\d+:\d\d:?)(?s:.)
V█(?-s)^ (?:\d[\d:]+)\v+</y\V+?href="/watch?v=([a-z\d_-]{11})["&][^\r\n<>]>([^\r\n<>]+)<\V+(?!\d+:\d\d:?)(?s:.*)

█https://youtu.be/\2 • \1 • \3

(YT NEW ALL VIDEOS \4=Автор)█\A(?:(?! (?:</ytd-thumbn\V+-label=|\d+:\d|В ЭФИРЕ|<a id="video-ti|htt|[^<>\r\n\/\\]{1,100}/watch?))\V\v+)+|^(?:(?! (?:(?:<a id="video-ti|</ytd-thumbn)\V+(?:href=|-label=)|\d+:\d|В ЭФИРЕ|<a id="video-ti|htt|</ytd-thumbnail><div id="det|[^<>\r\n\/\\]{1,100}(?:/watch?| Автор: )))\V+\v)|(?<=\d) (?=\d\S+ просм)|(?<=&)amp;
v█(?-s)^\s*(\d+:[\d:]+|В ЭФИРЕ)\v+^(?:(?! (?:(?:<a id="video-ti|</ytd-thumbn)\V+(?:href=|-label=)|\d+:|В ЭФИРЕ|htt|[^<>\r\n\/\\]{1,100}/watch?))\V+\v+){0,30}?</ytd-thumbnai\V+?aria-label="(.{1,150}?)(?:\v+(.{0,150}?))? Автор: ([^\r\n<>]{1,150}?)(?: \d+ (?:(?:год|лет|месяц|недел|де?н[яеь]й?)\w )(?:назад|час|минут|секунд)\w)* (\d+,?\d*(?: млн| тыс.|\d+)* просмотр\w*)" ti.{1,150}?(?:\v+(?! *(?:<a i|</|\d+:|В ЭФИРЕ|htt)).{0,150}?)?" href\W+watch?v=([a-z\d_-]{11})["&][^\r\n<>]{0,10}>.{1,150}?(?:\v+(?! (?:<a i|</|\d+:|В ЭФИРЕ|htt)).{0,150}?)?</\V
(с просмотрами)>█https://youtu.be/\6 \5 • \2\3 • \1

█https://youtu.be/\6 —— \4 —— \2\3 • \1

(форматирование из плейлиста)v█(?-s)(?s)^\s*(\d+:\d+:?\d*)\r\n.{100,1700}?<a id="video-title\V+?(?: title="([^\r\n<>]{1,300})" )?href="/watch?v=([a-z\d_-]{11})["&].+?(?: Автор: (.{1,200}) (?:\d+ (?:год\w*|лет|месяц\w*|недел\w+|де?н[яеь]й?) )+назад\V+le="(.{1,300}?)|label="([^\r\n<>]{1,300}?))?(?:">)?$

█• https://youtu.be/\3 • \4 ◘ \2\5\6 • \1\r\n
█^(?!• |[  ]http|\s\d+:\d:?\d*\s*$)\V*\r?\n?|^• +| +• *$

(список плейлистов из Исходного кода, в свойствах командной строки задать высоту буфера экрана 9900)
(--get-filename заменяет и добавляет некоторые символы, плюс YTID)
█^(?! *<a id="video-title| *http| *y -| *<div id="overl| *<yt-formatted-string (?:id="text"|title)(?=\V+complex-string|"? ?href=))\V+\v*|<span dir[^<\r\n>,]+?-string">|<\/\w+?>|<\/yt-formatted-string>
v█(?-s)^ *<div id="overl\V+-renderer">(\d+)\s+<a id="video-title\V+?title="(.{0,200}?)\v?" href="(?:\/watc\S+list=)([A-Z\d_\-]{15,60})">\2\v\s+<yt-formatted-s\V+>(\V*)$

y -s --flat-playlist --get-title --get-url --get-duration -F https:\/\/youtube\.com\/playlist\?list=\3 • \1 • \2

(форматирование после извлечения / YT format extracted playlist's links)
v█(?-si)^(?:(?:Microsoft W|Copyright ()\V+\v+)(?:[A-Z]:(\)[^\r\n>•\/\?=]+>((?:y|yt-|youtube-\S+)\b( )-\V+list=\V+(?:\v+WARNING: [youtube:tab\V+)?\r\n))?(?:(?'1'[(?:Deleted video|Private video)])|(.+?))\v+htt\S+v=([a-zA-Z-\d]{11})(?:#\S+)?(?('1')|\v+([\d:]+))$(?:\v+(?:(?:ERROR|WARNING): (?:[\w+]|')\V+|командой, исп|"\W?\w+\W?" не являетс)[^\r\n]+|\v+[A-Z]:\[^\r\n>•\/\?=]+>)$

█\1\1\1\3\2https://youtu.be/\6 • \4\5 • \7

(дублирование, фильтрация приставки с именем канала и номером строки, например ◘ 041 / YT Убрать дублирование м.треков с пометками ◘)
(1)v█(?-si)^ (https?\W+youtu.be/[\dA-z-]{11}) • (.{1,200}? •• )?(.{1,300}?) • ([\d:]{4,})( ◘ [A-z]?\d+)\r?\n \1 • (?:\2|(.{1,200}? •• ))?(?:\3|(.{1,300})) • \4( ◘ [A-z]?\d+)$(?:\v+ \1 •.{1,300}?$)

█ \1 • \6\2\3 • \4\5\8\r\n \7
(DEL)v█(?-si)^ (https?\W+youtu.be/[\dA-z-]{11}) • ([^\r\n]+ •• )?([^\r\n]+) • ([\d:]{4,})( ◘ [A-z]?\d+)\r?\n \1 • (?:\2|([^\r\n]+ •• ))?(?:\3|([^\r\n]+)) • \4( ◘ [A-z]?\d+)$(?:\v+ \1 •[^\r\n]+)

(2)v█(?-si)^ *(https?\W+youtu.be/[\dA-z-]{11}) +(• )?(.{1,300}?$)\v+ *\1 +(?:\2|(• ))?(.{1,300}?)$

█ \1 \2\4\3 ◘ \5

(YOUTUBE-DL) 249/250/139/251/140/17/18 --write-info-json███y -c -w -i --no-warnings --write-description --youtube-skip-dash-manifest --retries 20 --fragment-retries 20 --keep-fragments --max-filesize 30M -o "d:\Music For You%(id)s —— %(uploader)s —— %(title)s.%(ext)s" -f 251/250/249/140/139/17/18 -a "S:\0001.txt"
(AWGG YOUTUBE-DL)█-f 251/140/250/249/139/17/18 -o "%(id)s %(uploader)s -- %(title)s.%(ext)s"
opus (48000Hz) -f 251 (YT-dl webm audio 120k-180kbps) -f 249 (50k-75kbps) -f 250 (70k-90kbps) (Xrecode parameter: --comp 10 --framesize 10 --cvbr --downmix-mono --bitrate 18 --speech // // --comp 10 --framesize 5 --cvbr --downmix-stereo --music --bitrate 240)
m4a (-f 139 = 47kbps 22050Hz) (-f 140 128kbps 44100Hz)

(сортировать и отфильтровать уже скачанные файлы (webm|m4a), скопированные пути из TotalCmd в список youtube-ссылок / YT Filter links out of downloaded files)
█(?-s)^(?!(?:https?:/+|www.|m.|music.)youtu.?be|[a-z]:|[a-z\d-_]{11}[\r\Z ]).\v*|[a-z]:\\V+(?:.(?:part|ytdl|frag|description)\d*)
V█^[a-z]:\\V+\([a-z\d-_]{11})^a-z\d-_?(?<!.(?:part|ytdl|frag))(?<!description)$

█\1 •
(полный поиск YouTube ссылок)V█(?-s)^https?\W+(?:www.|m.|music.)youtu.?be(?:.com/|watch|o?embed(?:/|?url=\S+?)?|shorts|attribution_link?[&\w-=][au]=/?|ytsc\w+|[?&][ve]i?\b|?feature=\w+|-nocookie|%[23][56FD])(?:[/=]|%2F|%3D)([a-z\d-]{11})[?&#% \t ]? .$
█\1
(сортировать)
█(?-i)^([A-Za-z\d-
]{11})(?:\v+\1(?: •)?)* •$\v*|^(?!\V*(?:(?:https?\W+|www.|m.|music.)youtu|\w:\\V+\)?[A-Za-z\d-_]{11}.?(?:m4a|webm|mp4|opus|3gp| (\d+))$)\V+\v*
V█(?-i)^([A-Za-z\d-_]{11})(?:\v+\1)*$
█https://youtu.be/\1

перевернуть • местами 22 • <...> • 11)V█(?-s)^(.+?) +• +(.+)

█\2 • \1
(22 • 11 • <...>)V█(?-s)^(.+?) • (.+?)(?= • )
█\2 • \1
(11 ◘ 22)V█(?-s)^(.+) +◘ +(.+)$
█\2 ◘ \1

[YTv xxXxxXxxXxx].ext
V█(?i)^(?:\V+\)?*([^\r\n\\]+?)(?!\w) *(?:-|[[(]YTv[.= ])([a-z\d-]{11})(?:[)]]|)(?: (?\w{0,3})|.f\d+|-0\d\d| +[а-яa-z]+| \d)*(?=.[wmojaf][lebkvp4acgnu3]{2}[smpcg]?$)

█\1 [YTv \2\3]

@ve3
Copy link

ve3 commented Jan 25, 2022

You missed this one

https://www.youtube.com/playlist?list=PLXdaORVZTx4AZlYj-9LWJomnzGE6lthbJ

/playlist path with ?list query.

@TheaZane
Copy link

TheaZane commented Feb 14, 2022

Can you check this one, I have never seen such url

https://m.youtube.com/watch%3Fv%3DfKF0uaABJtc&ved=2ahUKEwjkrsSipPP1AhXsyjGHb0CDU4Qx8BegQIBRAF&usg=AOvVaw0A7aB50nUUeTwX_Haoteft

What kind of url it is anyway?

@mlatushko
Copy link

mlatushko commented Feb 14, 2022

This is for all your links

V1█
(?-s)^(?:(?!https?[:\/]|www\.|m\.yo|music\.yo|youtu\.?be[\/\.]|watch[\/\?]|embed\/)\V)*(?:https?[:\/]+|www\.|m\.|music\.)+youtu\.?be(?:\.com\/|watch|o?embed(?:\/|\?url=\S+?)?|shorts|attribution_link\?[&\w\-=]*[au]=\/?|ytsc\w+|[\?&]*[ve]i?\b|\?feature=\w+|[\?&]time_continue=\d+|-nocookie|%[23][56FD])*(?:[\/=]|%2F|%3D)([a-z\d\-_]{11})(?>\?[&#%a-z\-\d=;_\.]*)?

V2█
(?-s)^(?:(?!https?[:\/]|www\.|m\.yo|youtu\.?be[\/\.]|watch[\/\?]|embed\/)\V)*https?[:\/]+(?:www\.|m\.|music\.)*youtu\.?be(?:\.com\/|watch|o?embed(?:\/|\?url=\S+?)?|shorts|attribution_link\?[&\w\-=]*[au]=\/?|ytsc\w+|[\?&]*[ve]i?\b|\?feature=\w+|time_continue=\d+|-nocookie|%[23][56FD])*(?:[\/=]|%2F|%3D)([a-z\d\-_]{11})(?>\?[&#%a-z\-\d=;_\.]*)?

(replace to \1 or)█
https:\/\/youtu\.be\/\1

@rodrigoborgesdeoliveira
Copy link
Author

@TheaZane that one is the same as https://www.youtube.com/watch?v=fKF0uaABJtc. For whatever reason you got the ? and = encoded.

@EmuAnon34
Copy link

Here’s what you get when you use Request Desktop Website on mobile. https://www.youtube.com/watch?app=desktop&v=dQw4w9WgXcQ

@rodrigoborgesdeoliveira
Copy link
Author

Thanks, @EmuAnon34.

@VladimirSlavik
Copy link

The same format also appears when you open on desktop a mobile url (m.youtube.com).

@rodrigoborgesdeoliveira
Copy link
Author

Thanks, @VladimirSlavik. Added.

@VladimirSlavik
Copy link

VladimirSlavik commented Aug 22, 2022

Ah! Sorry for the confusion, that was not what I meant. Let me try again.

The m.y... mobile URL, when opened on a desktop browser, redirects to the www.y...?app=desktop... kind of URL.

At least, that's the part where I am certain. I never saw the format you added last.

@rodrigoborgesdeoliveira
Copy link
Author

Got it. Yeah, the https://m.youtube.com/watch?app=desktop&v=dQw4w9WgXcQ turns out to be a valid URL, just not the final URL, since it redirects to youtube.com.

@EmuAnon34
Copy link

@rodrigoborgesdeoliveira @VladimirSlavik Pretty much every www. url has an m. equivalent.

@Watn3y
Copy link

Watn3y commented Oct 20, 2022

I made a little regex that matches the video ID in 99% of those examples. It's not bulletproof but probably good enough for most usecases.

/(?<=[=\/&])[a-zA-Z0-9_\-]{11}(?=[=\/&?#\n\r]|$)/

Be sure to improve on this if you can.

It can be tested here

@asdfletcher-yesler
Copy link

asdfletcher-yesler commented Dec 13, 2022

Is there an example link with prefix https://youtube.com ? Seems like this might be missing from the examples

(And http://m.youtube.com?)

@rodrigoborgesdeoliveira
Copy link
Author

@NebularNerd
Copy link

Thanks for this list, it's come in handy for a couple of little projects 🙂

@rodrigoborgesdeoliveira
Copy link
Author

Thanks for this list, it's come in handy for a couple of little projects 🙂

🙂

@wu-lee
Copy link

wu-lee commented Jan 30, 2023

Are the URLs like this one valid?

https://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/QdK8U-VIH_o

In that, yes, they go to a You Tube user's channel, but I suspect everything after the # is ignored, so the video ID isn't used. In fact that anchor suffix could be anything at all, and it would be correct not to parse the video ID.

@wu-lee
Copy link

wu-lee commented Jan 30, 2023

Likewise, I wonder about these URLs with a vi in place of a v. They all either go to a 404-not-found or are redirected to youtube.com's front page. Even if I insert an ID I know works with other URLs - so it's not simply the video has been taken down.

http://youtube.com/?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player
http://youtube.com/vi/dQw4w9WgXcQ?feature=youtube_gdata_player
http://youtube.com/vi/oTJRivZTMLs&feature=channel
http://youtube.com/watch?vi=oTJRivZTMLs&feature=channel

@wu-lee
Copy link

wu-lee commented Jan 30, 2023

And URLs like this, with a v= parameter and no watch:

http://youtube.com/?v=XXXXXXXXXXX&feature=youtube_gdata_player
http://www.youtube.com/?v=XXXXXXXXXXX
http://www.youtube.com/?feature=player_embedded&v=XXXXXXXXXXX
http://youtube.com/?v=XXXXXXXXXXX&feature=channel
http://youtube.com/?feature=channel&v=XXXXXXXXXXX

I've not made an exhaustive test, but it does seem to find a lot of questionable URLs. It's quite possible these work for someone else, but has anyone evidence these URLs ever did link to a video?

@NebularNerd
Copy link

I've tried a couple and it seems some of the weirder looking ones may or do not work, I've left them in my regex for potential matches if I ever find one in the wild and want to quickly get the ID

@rodrigoborgesdeoliveira
Copy link
Author

Thanks for reporting these @wu-lee. I'm going to do some tests over the weekend and leave some comments in the list for any of the links that don't work anymore. It might be the case that YouTube has deprecated these URLs.

@wu-lee
Copy link

wu-lee commented Jan 31, 2023

I think these URLs with vi components may be for thumbnail images associated with videos. For example, this is one:

https://i.ytimg.com/vi/XXXXXXXXXXX/default.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment