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.

Revisions

  1. mva-one revised this gist Mar 14, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions r1dl.py
    Original 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
  2. mva-one revised this gist Mar 14, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions r1dl.py
    Original 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/"
    ]

    # urllist = [ "https://radio1.hu/tracklista/world-is-mine-radio-show-nigel-stately-mix/" ]

    # repeat for all desired mixes
    for url in urllist:
    @@ -52,7 +52,7 @@

    date = unidecode(datetime.split(":")[0].replace(" ",""))

    filename = "R1_WIM_" + artist + "_" + date + ".mp3"
    filename = getcwd() + "\\R1_WIM_" + artist + "_" + date + ".mp3"

    print("Filename: " + filename + " Title: " + title + " Date: " + datetime + " Source: " + source)

  3. mva-one created this gist Jan 23, 2022.
    66 changes: 66 additions & 0 deletions r1dl.py
    Original 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!")