from
os
import
listdir, remove, mkdir
from
requests
import
get
from
time
import
sleep
class
Category():
def
__init__(
self
, n):
self
.num
=
n
self
.title
=
None
self
.sound
=
None
self
.pic
=
None
self
.readcount
=
None
self
.
id
=
None
def
show(
self
):
print
(f
'#{self.num}/{self.readcount}/{self.title}/{self.title_cn}'
)
with
open
(f
'Homepage/#{self.num}-{self.title}.jpg'
,
'wb'
) as f:
img
=
get(
self
.pic).content
f.write(img)
def
download(
self
):
with
open
(f
'Download/{self.title}.mp3'
,
'wb'
) as f:
mp3
=
get(
'http://static.iyuba.cn/sounds/minutes/'
+
self
.sound).content
f.write(mp3)
url
=
'http://apps.iyuba.cn/minutes/titleNewApi.jsp?maxid={}&pages=1&pageNum=20&parentID=1&type=android&format=json'
r
=
get(url.
format
(
0
))
dic
=
r.json()[
'data'
]
banned
=
{
'/'
,
'\\', '
:
', '
?
', '
*
', '
"
', '
<
', '
>
', '
|'}
for
name
in
{
'Homepage'
,
'Download'
}:
try
: mkdir(name)
except
:
pass
target
=
[]
i
=
0
print
(
'#/Read Count/Title_EN/Title_CN (Picture in Homepage/)'
)
for
item
in
dic:
epi
=
Category(i)
title
=
item[
'Title'
]
for
b
in
banned: title
=
title.replace(b, '')
epi.title
=
title
epi.title_cn
=
item[
'Title_cn'
]
epi.sound
=
item[
'Sound'
]
epi.pic
=
item[
'Pic'
]
epi.readcount
=
item[
'ReadCount'
]
epi.
id
=
item[
'BbcId'
]
epi.show()
target.append(epi)
i
+
=
1
print
(
'Input number to get one, and "next" to get a next page.'
)
while
True
:
t
=
input
(
'I want #'
)
if
t
=
=
'next'
:
r
=
get(url.
format
(target[
len
(target)
-
1
].
id
))
dic
=
r.json()[
'data'
]
for
item
in
dic:
epi
=
Category(i)
title
=
item[
'Title'
]
for
b
in
banned: title
=
title.replace(b, '')
epi.title
=
title
epi.title_cn
=
item[
'Title_cn'
]
epi.sound
=
item[
'Sound'
]
epi.pic
=
item[
'Pic'
]
epi.readcount
=
item[
'ReadCount'
]
epi.
id
=
item[
'BbcId'
]
epi.show()
target.append(epi)
i
+
=
1
else
:
try
: n
=
int
(t)
except
:
break
else
: target[n].download()
print
(
'Cleaning cache...'
)
target
=
listdir(
'Homepage'
)
for
item
in
target:
remove(
'Homepage/'
+
item)
sleep(
1
)