-
Notifications
You must be signed in to change notification settings - Fork 2
/
downloadXimalaya.py
executable file
·47 lines (37 loc) · 1.22 KB
/
downloadXimalaya.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
#! /Users/yxj/env3/bin/python
# coding=utf-8
import requests
import re
import io
from bs4 import BeautifulSoup
# 罗辑思维,晓松奇谈
fm_list = ['http://m.ximalaya.com/10936615/album/321701',
# 'http://m.ximalaya.com/1412917/album/239463',
]
def requests_file(file_url, filename):
r = requests.get(file_url)
if r.status_code == requests.codes.ok:
with io.open(filename, 'wb') as file:
file.write(r.content)
file.flush()
file.close()
def main():
for fm in fm_list:
r = requests.get(fm)
r1 = r'sound_url="(.*?\.m4a)"'
r1_comp = re.compile(r1)
soup = BeautifulSoup(r.text)
soup_result = soup.find(attrs={'class':'block title ellipsis'})
# print(soup_result.text)
first_mp3_url = re.findall(r1_comp, r.text)[0]
final_filename = soup_result.text + '.mp3'
f = open('latest.txt', 'r+')
if (final_filename + '\n') not in f.readlines():
print("downloading " + final_filename)
requests_file(first_mp3_url, final_filename)
f.write(final_filename + '\n')
f.flush()
f.close()
print("done")
if __name__ == '__main__':
main()