diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-07 16:56:58 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-08 09:48:32 +0300 |
| commit | 6ca8b8991a72ec5600aa1732acd170ba5ffeb853 (patch) | |
| tree | 4fd4ef3c9fbd27348a8256d14b787fee33e96466 /components | |
| parent | 53e5473b464bd1ba789b78a6a8f64d54cedfa8dd (diff) | |
| download | csca5028-6ca8b8991a72ec5600aa1732acd170ba5ffeb853.tar.gz csca5028-6ca8b8991a72ec5600aa1732acd170ba5ffeb853.zip | |
Add URL type identification functionality
Diffstat (limited to 'components')
| -rw-r--r-- | components/extractor/check_url.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/components/extractor/check_url.py b/components/extractor/check_url.py new file mode 100644 index 0000000..b574b22 --- /dev/null +++ b/components/extractor/check_url.py @@ -0,0 +1,29 @@ +from re import search +from urllib.parse import urlparse, parse_qs, ParseResult + +def is_youtube(url: str) -> bool: + """ + Affirm the YouTube domain and that there is something after the domain. + """ + return bool(search(r'^(?:http|//).*(?:youtube\.com|youtu\.be)/.+', url)) + +def is_video(url: str) -> bool: + if not is_youtube(url): + return False + parsed_url = urlparse(url) + if parsed_url.path in ('/watch', '/shorts/', '/embed/'): + return True + return parsed_url.netloc == 'youtu.be' + +def is_playlist(url: str) -> bool: + if not is_youtube(url): + return False + parsed_url = urlparse(url) + query_params = parse_qs(parsed_url.query) + return 'list' in query_params + +def is_channel(url: str) -> bool: + if not is_youtube(url): + return False + parsed_url = urlparse(url) + return parsed_url.path.startswith(('/c/', '/user/', '/channel/', '/@')) |
