mirror of
https://github.com/Mak5er/Downloader-Bot
synced 2026-11-26 09:08:08 +08:00
Add Spotify track resolution through YouTube audio sources with oEmbed fallback, caching, routing, analytics, and user-facing support. Normalize MP3 filenames, ID3 tags, JPEG cover art, Telegram thumbnails, and duplicate artist metadata across Spotify, YouTube Music, and SoundCloud. Extend regression coverage for provider parsing, delivery, metadata, covers, cache behavior, and link dispatch.
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
from services.links.detection import detect_supported_service, extract_supported_link, extract_supported_links
|
|
|
|
|
|
def test_detect_supported_service_covers_all_supported_group_guard_links():
|
|
assert detect_supported_service("https://www.instagram.com/p/demo") == "instagram"
|
|
assert detect_supported_service("https://www.threads.com/@demo/post/Abc_123") == "threads"
|
|
assert detect_supported_service("https://www.tiktok.com/@demo/video/1") == "tiktok"
|
|
assert detect_supported_service("https://soundcloud.com/artist/track") == "soundcloud"
|
|
assert detect_supported_service("https://open.spotify.com/track/abc123?si=demo") == "spotify"
|
|
assert detect_supported_service("https://pin.it/demo123") == "pinterest"
|
|
assert detect_supported_service("https://youtu.be/demo") == "youtube"
|
|
assert detect_supported_service("https://music.youtube.com/watch?v=abc123") == "youtube"
|
|
assert detect_supported_service("https://x.com/demo/status/1") == "twitter"
|
|
|
|
|
|
def test_extract_supported_links_preserves_order_and_deduplicates():
|
|
text = (
|
|
"first https://youtu.be/demo "
|
|
"then https://www.instagram.com/reel/abc/ "
|
|
"again https://youtu.be/demo"
|
|
)
|
|
|
|
assert extract_supported_links(text) == [
|
|
("youtube", "https://youtu.be/demo"),
|
|
("instagram", "https://www.instagram.com/reel/abc/"),
|
|
]
|
|
|
|
|
|
def test_extract_supported_links_canonicalizes_threads_domain_and_tracking():
|
|
assert extract_supported_link("https://threads.net/@demo/post/Abc_123?utm_source=share") == (
|
|
"threads",
|
|
"https://threads.net/@demo/post/Abc_123",
|
|
)
|
|
|
|
|
|
def test_extract_supported_link_strips_trailing_sentence_punctuation():
|
|
assert extract_supported_link("watch this https://youtu.be/demo.") == (
|
|
"youtube",
|
|
"https://youtu.be/demo",
|
|
)
|
|
|
|
|
|
def test_extract_spotify_link_strips_tracking_query():
|
|
assert extract_supported_link("https://open.spotify.com/track/abc123?si=tracking") == (
|
|
"spotify",
|
|
"https://open.spotify.com/track/abc123",
|
|
)
|
|
|
|
|
|
def test_extract_supported_links_canonicalizes_tracking_query_params():
|
|
text = (
|
|
"https://www.instagram.com/reel/abc/?utm_source=ig_web_copy_link "
|
|
"https://www.youtube.com/watch?v=abc123&si=noise&utm_source=test&t=30"
|
|
)
|
|
|
|
assert extract_supported_links(text) == [
|
|
("instagram", "https://www.instagram.com/reel/abc/"),
|
|
("youtube", "https://www.youtube.com/watch?v=abc123&t=30"),
|
|
]
|