/
luoo.py
64 lines (56 loc) · 1.65 KB
/
luoo.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
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import sys
import xml.etree.ElementTree as ET
import common
xml_url_1 = 'http://www.luoo.net/radio/radio%d/mp3.xml'
xml_url_2 = 'http://www.luoo.net/radio/radio%d/mp3player.xml'
referer = 'http://www.luoo.net/radio/radio%d/mp3player.html'
TARGET = '/home/spyth/Music/luoo/%d'
if common.os.sys.platform.find('win') != -1:
TARGET = 'E:\\Music\\luoo\\%d'
def extract(html):
if not html :
return
root = ET.fromstring(html)
li = []
for song in root:
title = song.get('title')
location = song.get('path')
li.append((title, location))
return li
def download_show(li):
for num in li:
if num > 296:
url = xml_url_1%num
else:
url = xml_url_2%num
xml_data = common.open_url(url)
if xml_data:
songlist = extract(xml_data)
target_dir = TARGET%num
for title, location in songlist:
ext = location.split('.')[-1]
common.download(location, target_dir, title, ext, Referer=referer%num)
def main():
if len(sys.argv) >= 2:
try:
li = map(int, sys.argv[1:])
except:
print 'Input Error!'
return
download_show(li)
else:
print u"输入期号下载,','分开.'q'退出"
while 1:
comm = raw_input('Select:')
if comm == 'q':
return
try:
li = map(int, comm.split(','))
except:
print 'Input Error!'
continue
download_show(li)
if __name__ == '__main__':
main()