Skip to content

Instantly share code, notes, and snippets.

@mva-one
Last active March 14, 2022 21:24
Show Gist options
  • Save mva-one/b6426b7469faa7c572c3d1be93082c6c to your computer and use it in GitHub Desktop.
Save mva-one/b6426b7469faa7c572c3d1be93082c6c to your computer and use it in GitHub Desktop.
RADIO1.HU WorldIsMine RadioShow Downloader Script
# original made by a-sync: https://gist.github.com/a-sync/e8c1f1d01b8ff8ce0181051cb72bda04
# python version by mva-one: https://gist.github.com/mva-one/b6426b7469faa7c572c3d1be93082c6c
from os import getcwd
import re
import shutil
import urllib3
from unidecode import unidecode
urllist = [
"https://radio1.hu/tracklista/metzker-viktoria-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-jauri-mix/",
"https://radio1.hu/tracklista/bricklake-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-willcox-mix/",
"https://radio1.hu/tracklista/purebeat-mix/",
"https://radio1.hu/tracklista/loving-arms-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-stadium-x-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-antonyo-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-joerjunior-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-regan-lili-mix/",
"https://radio1.hu/tracklista/andro-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-nigel-stately-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-yamina-mix/",
"https://radio1.hu/tracklista/newik-mix/",
"https://radio1.hu/tracklista/world-is-mine-radio-show-lotfi-begi-mix/"
]
# repeat for all desired mixes
for url in urllist:
# get the html, and parse the audio elements
http = urllib3.PoolManager()
html = http.request('GET', url).data.decode('utf-8')
# nice RegEx made by https://github.com/a-sync
pattern = """<audio data-artist="(.*?)" data-title="(.*?)".*?>\n.*?<source src="(.*?)" type="audio/mp3">"""
matches = re.findall(pattern, html, re.IGNORECASE)
# for each audio, download the file and name it like desired
for match in matches:
title = match[0]
datetime = match[1]
source = "https://www.radio1.hu" + match[2]
dlheaders = urllib3._collections.HTTPHeaderDict()
dlheaders.add("Referer", url)
dlheaders.add("Connection", "keep-alive")
dlheaders.add("Host", "radio1.hu")
titlesplit = title.split("-",1)
if len(titlesplit) == 2:
artist = unidecode(title.split("-",1)[1].replace(" ", ""))
else:
artist = "ERROR"
date = unidecode(datetime.split(":")[0].replace(" ",""))
filename = getcwd() + "\\R1_WIM_" + artist + "_" + date + ".mp3"
print("Filename: " + filename + " Title: " + title + " Date: " + datetime + " Source: " + source)
# Download file(s)
try:
with http.request('GET', source, headers=dlheaders, preload_content=False) as r, open(filename, "wb") as file:
print("STATUS = " + str(r.status))
shutil.copyfileobj(r, file)
except:
print("An exception occured!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment