Browse Source

add soundcloud support

master
HayWo 2 years ago
parent
commit
f19d2bb7ca
Signed by: haywo GPG Key ID: CE8467F36EF907E4
  1. 10
      fridaydisco.py

10
fridaydisco.py

@ -119,6 +119,7 @@ youtube_base = "https://www.youtube.com/watch?v="
youtube_base_alt = "https://youtu.be/"
youtube_base_alt_2 = "youtu.be/"
bandcamp_regex = "https://[a-zA-Z0-9_-]*.bandcamp.com/[a-zA-Z0-9/_-]*"
soundcloud_regex = "https://soundcloud.com/[a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*"
print(f"Getting {requested_toots} newest Toots from: {instance}/api/v1/timelines/tag/{tag}")
response = requests.get(f"{instance}/api/v1/timelines/tag/{tag}?limit={requested_toots}")
@ -141,14 +142,20 @@ for post in posts:
while cursor_pos < content_length:
is_invidious = False
is_bandcamp = False
is_soundcloud = False
full_link = ""
link_start = content.find(youtube_base, cursor_pos, content_length)
if link_start == -1:
bandcamp_link = re.search(bandcamp_regex, content[cursor_pos:])
soundcloud_link = re.search(soundcloud_regex, content[cursor_pos:])
if bandcamp_link:
full_link = bandcamp_link.group()
link_start = content.find(full_link, cursor_pos, content_length)
is_bandcamp = True
elif soundcloud_link:
is_soundcloud = True
full_link = soundcloud_link.group()
link_start = content.find(full_link, cursor_pos, content_length)
else:
link_start = content.find("/watch?v=", cursor_pos, content_length)
is_invidious = True
@ -165,7 +172,8 @@ for post in posts:
})
failed_links.append(full_link)
else:
full_link = content[link_start:link_end]
if not is_soundcloud:
full_link = content[link_start:link_end]
if is_invidious:
full_link = "https://www.youtube.com" + full_link
if full_link.find("</span><span class=\"invisible\">", 0, len(full_link)) == -1:

Loading…
Cancel
Save