-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
clypdown.py
45 lines (41 loc) · 1.66 KB
/
clypdown.py
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
#!/usr/bin/python2
# coding: utf-8
from clint.textui import progress
import requests
import json
import sys
def download(mp3_url, title):
filename = "%s.mp3" %(title)
print "{*} Saving file to %s" %(filename)
try:
r = requests.get(url=mp3_url, stream=True)
with open(filename, 'wb') as f:
total_length = int(r.headers.get('content-length'))
for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1):
if chunk:
f.write(chunk)
f.flush()
except Exception, e:
print "{-} Something has gone horribly wrong! Please report on the github issue tracker with the following backtrace: \n%s" %(e)
print "{*} Done!"
def get_mp3_url(url):
content_id = url.replace("https://clyp.it/", "")
try:
r = requests.get(url="https://api.clyp.it/%s" %(content_id))
except Exception, e:
print "{-} Something has gone horribly wrong! Please report on the github issue tracker with the following backtrace: \n%s" %(e)
fucking_json = json.loads(r.text)
song_title = fucking_json['Title']
mp3_url = fucking_json['Mp3Url']
if fucking_json['Status'] == "DownloadDisabled":
print "{i} Uploader has disabled downloading. Who fucking cares."
print "{*} Got song title: %s" %(song_title)
print "{*} Got mp3 url: %s" %(mp3_url)
return song_title, mp3_url
def main(args):
if len(args) != 2:
sys.exit("%s https://clyp.it/lolwat" %(args[0]))
song_title, mp3_url = get_mp3_url(url=args[1])
download(mp3_url=mp3_url, title=song_title)
if __name__ == "__main__":
main(args=sys.argv)