Skip to content

Commit

Permalink
python3: Mk song_dir before iterate songlist and strip spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
YongHaoHu committed Feb 16, 2017
1 parent c95bc7e commit bbb0b27
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
res = r'<li><a .*?>(.*?)</a></li>'
mm = re.findall(res, contents, re.S | re.M)

songdir = "songs_dir"
if not os.path.exists(songdir):
os.makedirs(songdir)

for value in mm:
url = 'http://sug.music.baidu.com/info/suggestion'
payload = {'word': value, 'version': '2', 'from': '0'}
Expand Down Expand Up @@ -49,12 +53,12 @@
continue
print songlink

songdir = "songs_dir"
if not os.path.exists(songdir):
os.makedirs(songdir)

songname = d["data"]["songList"][0]["songName"]
songname = "".join(songname.split())

artistName = d["data"]["songList"][0]["artistName"]
artistName = "".join(artistName.split())

filename = "./" + songdir + "/" + songname + "-" + artistName + ".flac"

f = urllib2.urlopen(songlink)
Expand Down

0 comments on commit bbb0b27

Please sign in to comment.