download from radio javan python

Solutions on MaxInterview for download from radio javan python by the best coders in the world

showing results for - "download from radio javan python"
Valentina
07 Nov 2016
1def get_download_link(link):
2	
3	# Get media type
4    media_type = re.split(r"/", link)[3]
5    
6    # Get File name
7    file_name = re.split(r"/", link)[5]
8	
9    # Start session
10    session = requests.Session()
11	
12    # get Response
13    response = session.get(f"https://www.radiojavan.com/{media_type}/{media_type[:-1]}_host/?id={file_name}")
14    base_url = str(json.loads(response.text)["host"])
15
16	# Check media data type
17    # podcasts
18    if media_type == "podcasts":
19        return f"{base_url}/media/podcast/mp3-256/{file_name}.mp3"
20
21	# mp3s
22    elif media_type == "mp3s":
23        return f"{base_url}/media/mp3/{file_name}.mp3"
24
25	# videos
26    elif media_type == "videos":
27        return f"{base_url}/media/music_video/hq/{file_name}.mp4"
28  
29    else:
30        return None
31        
32########## Test ###########
33
34get_download_link('https://www.radiojavan.com/mp3s/mp3/Shadmehr-Aghili-Avaz-Nemishi')
35          
36# Output :
37
38# https://host2.rj-mw1.com/media/mp3/Shadmehr-Aghili-Avaz-Nemishi.mp3
39