-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusicforprogramming
executable file
·46 lines (39 loc) · 1.34 KB
/
musicforprogramming
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
45
46
#! /usr/bin/env python3
import click
import re
import requests
from urllib.parse import urlparse
import subprocess
"""
Simple downloader for music tracks from http://musicforprogramming.net
author: Granitosaurus, bernardas.alisauskas@gmail.com
requires: python3 - requests, click
"""
def download(track_range, show=False):
resp = requests.get('http://musicforprogramming.net/rss.php')
urls = re.findall('<guid>(.+?)</guid>', resp.text)
for item in urls[::-1]:
index = re.findall('ming_(\d+)', item)
if not index or int(index[0]) not in track_range:
continue
filename = urlparse(item).path.split('programming_')[-1]
if show:
print(filename)
else:
subprocess.call('wget "{}" -O "{}" -q --show-progress'.format(item, filename), shell=True)
@click.command()
@click.argument('tracks')
@click.option('--show', help='just show available tracks without downloading', is_flag=True)
def cli(tracks, show):
"""
Download tracks from musicforprogramming.net,
track argument should be either a number or range, e.g. 1 or 1-5
"""
if '-' in tracks:
track_range = range(*[int(i) for i in tracks.split('-')])
else:
tracks = int(tracks)
track_range = range(tracks, tracks + 1)
download(track_range, show)
if __name__ == '__main__':
cli()