-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrj_downloader.py
44 lines (36 loc) · 1.17 KB
/
rj_downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import logging
import requests
import json
import re
from subprocess import call
import validators
def get_download_link(link):
media_type = re.split(r"/", link)[3]
file_name = re.split(r"/", link)[5]
session = requests.Session()
response = session.get(f"https://www.radiojavan.com/{media_type}/{media_type[:-1]}_host/?id={file_name}")
base_url = str(json.loads(response.text)["host"])
if media_type == "podcasts":
return f"{base_url}/media/podcast/mp3-256/{file_name}.mp3"
elif media_type == "mp3s":
return f"{base_url}/media/mp3/{file_name}.mp3"
elif media_type == "videos":
return f"{base_url}/media/music_video/hq/{file_name}.mp4"
else:
return None
if __name__ == "__main__":
while True:
media_link = input("Enter a link: ")
if not validators.url(media_link):
print("Please input a valid URL")
continue
break
download_link = None
try:
download_link = get_download_link(media_link)
except Exception as e:
logging.exception(e)
if download_link:
call(["wget", download_link])
else:
print("Sorry, unsupported link!")