Last active
March 14, 2022 21:24
-
-
Save mva-one/b6426b7469faa7c572c3d1be93082c6c to your computer and use it in GitHub Desktop.
Revisions
-
mva-one revised this gist
Mar 14, 2022 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ # 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 -
mva-one revised this gist
Mar 14, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ from os import getcwd import re import shutil import urllib3 @@ -21,7 +22,6 @@ "https://radio1.hu/tracklista/world-is-mine-radio-show-lotfi-begi-mix/" ] # repeat for all desired mixes for url in urllist: @@ -52,7 +52,7 @@ date = unidecode(datetime.split(":")[0].replace(" ","")) filename = getcwd() + "\\R1_WIM_" + artist + "_" + date + ".mp3" print("Filename: " + filename + " Title: " + title + " Date: " + datetime + " Source: " + source) -
mva-one created this gist
Jan 23, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ 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/" ] # urllist = [ "https://radio1.hu/tracklista/world-is-mine-radio-show-nigel-stately-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 = "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!")