alxhotel / chromecast-api

:tv: Chromecast Node.js module
MIT License
155 stars 49 forks source link

Allow music.youtube links #69

Closed Araxeus closed 3 years ago

Araxeus commented 3 years ago

added the option to use music.youtube links (which have the same id as normal youtube) by adding (?:music\.)? to the regex full new regex:

/http(?:s?):\/\/(?:www\.)?(?:music\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?/

Example:

this capture id JYC8aINHFxc from https://music.youtube.com/watch?v=JYC8aINHFxc&list=PLtkJ7CALZYL9rGWDQ7V_PX60Kth5Nq3Ry which is the same as https://www.youtube.com/watch?v=JYC8aINHFxc

alxhotel commented 3 years ago

Nice @Araxeus!

Thank you :+1:

Araxeus commented 3 years ago

@alxhotel by the way, whats the point of the other capture group? (&(amp;)?‌​[\w\?‌​=]*)?

It seems only the first group is used anyways. maybe its a leftover from somewhere?

Could maybe remove it, shortened version would be:

/http(?:s?):\/\/(?:www\.)?(?:music\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)/`

Also i think http/s should maybe be optional with (?:http(?:s?):\/\/)?. final result:

/(?:http(?:s?):\/\/)?(?:www\.)?(?:music\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)/
alxhotel commented 3 years ago

The (&(amp;)?‌​[\w\?‌​=]*)? group is so that the regex can match the whole string and not just a part of it. But I guess that we can get rid of it if we allow a partial match.

Yep, we can also make the http prefix optional if you want :)