-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathluooder.py
89 lines (71 loc) · 2.49 KB
/
luooder.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# author: Nevermoi ([email protected])
# date: 15-Jan-2016
import os
import sys
import requests
#import songdetails
import unicodedata
from bs4 import BeautifulSoup
LUOO_URL = "http://www.luoo.net/music/{}"
MP3_URL = "http://luoo-mp3.kssws.ks-cdn.com/low/luoo/radio{}/{}.mp3"
TRACK_NAME = "{} -{}.mp3"
proxies = {}
reload(sys)
sys.setdefaultencoding('utf-8')
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def full2half(uc):
"""convert full-width character to half-width one
"""
return unicodedata.normalize('NFKC', uc)
def get_song_list(volumn):
r = requests.get(LUOO_URL.format(volumn))
r.encoding = 'utf-8'
bs = BeautifulSoup(r.content, 'html.parser')
songs = bs.find_all('div', 'player-wrapper')
print bcolors.OKBLUE + "song list of volumn {}:".format(volumn) + bcolors.ENDC
result = []
for song in songs:
meta = {}
meta['name'] = song.find('p', 'name').getText()
meta['artist'] = song.find('p', 'artist').getText()[7:]
meta['album'] = song.find('p', 'album').getText()[6:]
print bcolors.UNDERLINE + '{} by {}'.format(meta['name'], meta['artist']) + bcolors.ENDC
result.append(meta)
return result
def download_songs(volumn):
songs = get_song_list(volumn)
if len(songs) == 0:
print bcolors.WARNING + 'please make sure the volumn exists in luoo.net' + bcolors.ENDC
return
if not os.path.exists(str(volumn)):
os.makedirs(str(volumn))
os.chdir(str(volumn))
print bcolors.OKBLUE + 'downloading...' + bcolors.ENDC
index = 0
for song in songs:
index += 1
track = '%02d' % index
r = requests.get(MP3_URL.format(volumn,track), stream=True, proxies=proxies)
r.encoding = 'utf-8'
track_name = TRACK_NAME.format(song['name'], song['artist'])
with open(track_name, 'wb') as fd:
for chunk in r.iter_content():
fd.write(chunk)
fd.close()
print bcolors.OKGREEN + "{} is downloaded.".format(song['name']) + bcolors.ENDC
if __name__ == '__main__':
while True:
print bcolors.HEADER + "input the volumn number to download all songs within it!\n>" + bcolors.ENDC
vol = raw_input()
if str(vol).isdigit():
print bcolors.BOLD + 'initiating...' + bcolors.ENDC
download_songs(vol)
break