mirror of https://github.com/afkcodes/zspotify.git
Improved podcast downloading
This commit is contained in:
parent
5838ea0ce1
commit
6c260e25ff
34
zspotify.py
34
zspotify.py
|
@ -182,29 +182,35 @@ def getEpisodeInfo(episode_id_str):
|
||||||
info = json.loads(requests.get("https://api.spotify.com/v1/episodes/" +
|
info = json.loads(requests.get("https://api.spotify.com/v1/episodes/" +
|
||||||
episode_id_str, headers={"Authorization": "Bearer %s" % token}).text)
|
episode_id_str, headers={"Authorization": "Bearer %s" % token}).text)
|
||||||
|
|
||||||
return info["show"]["name"], info["name"]
|
if "error" in info:
|
||||||
|
return None, None
|
||||||
|
else:
|
||||||
|
return info["show"]["name"], info["name"]
|
||||||
|
|
||||||
|
|
||||||
def downloadEpisode(episode_id_str):
|
def downloadEpisode(episode_id_str):
|
||||||
global ROOT_PODCAST_PATH
|
global ROOT_PODCAST_PATH
|
||||||
|
|
||||||
podcastName, episodeName = getEpisodeInfo(episode_id_str)
|
podcastName, episodeName = getEpisodeInfo(episode_id_str)
|
||||||
filename = podcastName + " - " + episodeName + ".wav"
|
if podcastName == None:
|
||||||
|
print("### SKIPPING: (EPISODE NOT FOUND) ###")
|
||||||
|
else:
|
||||||
|
filename = podcastName + " - " + episodeName + ".wav"
|
||||||
|
|
||||||
episode_id = EpisodeId.from_base62(episode_id_str)
|
episode_id = EpisodeId.from_base62(episode_id_str)
|
||||||
stream = SESSION.content_feeder().load(
|
stream = SESSION.content_feeder().load(
|
||||||
episode_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
episode_id, VorbisOnlyAudioQuality(QUALITY), False, None)
|
||||||
print("### DOWNLOADING ENTIRE PODCAST EPISODE - THIS MAY TAKE A WHILE ###")
|
print("### DOWNLOADING ENTIRE PODCAST EPISODE - THIS MAY TAKE A WHILE ###")
|
||||||
|
|
||||||
if not os.path.isdir(ROOT_PODCAST_PATH):
|
if not os.path.isdir(ROOT_PODCAST_PATH):
|
||||||
os.makedirs(ROOT_PODCAST_PATH)
|
os.makedirs(ROOT_PODCAST_PATH)
|
||||||
|
|
||||||
with open(ROOT_PODCAST_PATH + filename, 'wb') as file:
|
with open(ROOT_PODCAST_PATH + filename, 'wb') as file:
|
||||||
while True:
|
while True:
|
||||||
byte = stream.input_stream.stream().read(1024 * 1024)
|
byte = stream.input_stream.stream().read(1024 * 1024)
|
||||||
if byte == b'':
|
if byte == b'':
|
||||||
break
|
break
|
||||||
file.write(byte)
|
file.write(byte)
|
||||||
|
|
||||||
# related functions that do stuff with the spotify API
|
# related functions that do stuff with the spotify API
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue