Skip to content

Commit

Permalink
Add support for YouTube shorts in the YouTube regexp (#619)
Browse files Browse the repository at this point in the history
* Add support for YouTube shorts in the YouTube regexp

* Add YouTube shorts URLs in the test file
  • Loading branch information
Zingzy authored Oct 5, 2024
1 parent 16fb0dd commit ec8cf28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/api/src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Supported_Filetype(str, Enum):


class URL_Regex(str, Enum):
YOUTUBE = r"^(?:(?:https?://(?:www\.)?(?:m\.)?youtube\.com))/(?:(?:oembed\?url=https?%3A//(?:www\.)youtube.com/watch\?(?:v%3D)(?P<video_id_1>[A-Za-z0-9_\-]{11}))|(?:attribution_link\?a=.*watch(?:%3Fv%3D|%3Fv%3D)(?P<video_id_2>[A-Za-z0-9_\-]{11}))).*|(?:https?:)?(?:\/\/)?(?:(?:www\.|m\.)?youtube(?:-nocookie)?\.com\/(?:(?:watch)?\?(?:app=desktop&)?(?:feature=\w*&)?v=|embed\/|v\/|e\/)|youtu\.be\/)(?P<video_id_3>[A-Za-z0-9_\-]{11}).*$"
YOUTUBE = r"^(?:(?:https?://(?:www\.)?(?:m\.)?youtube\.com))/(?:(?:oembed\?url=https?%3A//(?:www\.)youtube.com/watch\?(?:v%3D)(?P<video_id_1>[A-Za-z0-9_\-]{11}))|(?:attribution_link\?a=.*watch(?:%3Fv%3D|%3Fv%3D)(?P<video_id_2>[A-Za-z0-9_\-]{11}))).*|(?:https?:)?(?:\/\/)?(?:(?:www\.|m\.)?youtube(?:-nocookie)?\.com\/(?:(?:watch)?\?(?:app=desktop&)?(?:feature=\w*&)?v=|embed\/|v\/|e\/|shorts\/)|youtu\.be\/)(?P<video_id_3>[A-Za-z0-9_\-]{11}).*$"
"""Matches all valid youtube url formats in this list: https://gist.github.com/Snailedlt/d54514e37dda68fefe15e6e056b30747"""
VIMEO = r"(https?://)?(www.)?(player.)?vimeo.com/([a-z]*/)*(.*/)?(?P<video_id>[0-9]{6,11})[?]?.*"

Expand Down
12 changes: 12 additions & 0 deletions apps/api/tests/data_for_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@
("https://www.youtube.com/e/dQw4w9WgXcQ", "dQw4w9WgXcQ"),
("https://youtube.com/e/dQw4w9WgXcQ", "dQw4w9WgXcQ"),
("https://m.youtube.com/e/dQw4w9WgXcQ", "dQw4w9WgXcQ"),
("http://www.youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("http://youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("http://m.youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("https://www.youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("https://youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("https://m.youtube.com/shorts/j9rZxAF3C0I", "j9rZxAF3C0I"),
("http://www.youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
("http://youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
("http://m.youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
("https://www.youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
("https://youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
("https://m.youtube.com/shorts/j9rZxAF3C0I?app=desktop", "j9rZxAF3C0I"),
]

active_vimeo_array_url_formats = [
Expand Down

0 comments on commit ec8cf28

Please sign in to comment.