-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Hi,
I am too lazy for a pull request (sorry for that)
main.py with updated URLs and json paths. The old cookie still works π
import requests
import json
from pprint import pprint as pp
import urllib
import config as cfg
import os
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print('Error: Creating directory. ' + directory)
def getAllAudiobooks():
audiobooks = []
url = "https://iceportal.de/api1/rs/page/hoerbuecher"
response = requests.get(url, headers=cfg.headers)
# extract titles
json_data = json.loads(response.text)
items = json_data["teaserGroups"][0]["items"]
for item in items:
name = str(item["navigation"]["href"])[len("/hoerbuecher/"):]
audiobooks.append(name)
return audiobooks
def downloadAudiobook(title):
print("Downloading audiobook: {}".format(title))
url = "https://iceportal.de/api1/rs/page/hoerbuecher/{}".format(
title)
responseChapter = requests.get(url, headers=cfg.headers)
# extract chapters
json_data = json.loads(responseChapter.text)
playlist = json_data["files"]
# extract downloadPath for each chapter
downloadPath = []
for chapter in playlist:
chapterPath = chapter["path"]
url = "https://iceportal.de/api1/rs/audiobooks/path{}".format(
chapterPath)
responseDownloadPath = requests.get(
url, headers=cfg.headers, cookies=cfg.cookies)
path = json.loads(responseDownloadPath.text)["path"]
downloadPath.append(path)
createFolder('./audiobooks/{}'.format(title))
# download each track
for counter, track in enumerate(downloadPath):
print("{}/{}".format(counter+1, len(downloadPath)))
url = "https://iceportal.de{}".format(track)
audio = requests.get(url)
savePath = "audiobooks/{}/{}_".format(title,
title)+str(counter+1)+".m4a"
with open(savePath, "wb+") as code:
code.write(audio.content)
# MAIN
# extract all audiobooks
audiobooks = getAllAudiobooks()
createFolder('./audiobooks')
# download all audibooks
for book in audiobooks:
downloadAudiobook(str(book))
Nowadays lots of podcasts may spam the disk. So I tried to make a really simple version to load individual audiobooks. Little bit hacky but it works...
import requests
import json
from pprint import pprint as pp
import urllib
import config as cfg
import os
import argparse
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print('Error: Creating directory. ' + directory)
def getAllAudiobooks(books, allbooks):
audiobooks = []
booklist = {}
count = 1
url = "https://iceportal.de/api1/rs/page/hoerbuecher"
response = requests.get(url, headers=cfg.headers)
# extract titles
json_data = json.loads(response.text)
items = json_data["teaserGroups"][0]["items"]
for item in items:
name = str(item["navigation"]["href"])[len("/hoerbuecher/"):]
if count in books or allbooks:
audiobooks.append(name)
booklist[count] = item["title"] + " - " + item["subtitle"]
count+=1
return audiobooks, booklist
def downloadAudiobook(title):
print("Downloading audiobook: {}".format(title))
url = "https://iceportal.de/api1/rs/page/hoerbuecher/{}".format(
title)
responseChapter = requests.get(url, headers=cfg.headers)
# extract chapters
json_data = json.loads(responseChapter.text)
playlist = json_data["files"]
# extract downloadPath for each chapter
downloadPath = []
for chapter in playlist:
chapterPath = chapter["path"]
url = "https://iceportal.de/api1/rs/audiobooks/path{}".format(
chapterPath)
responseDownloadPath = requests.get(
url, headers=cfg.headers, cookies=cfg.cookies)
path = json.loads(responseDownloadPath.text)["path"]
downloadPath.append(path)
createFolder('./audiobooks/{}'.format(title))
# download each track
for counter, track in enumerate(downloadPath):
print("{}/{}".format(counter+1, len(downloadPath)))
url = "https://iceportal.de{}".format(track)
audio = requests.get(url)
savePath = "audiobooks/{}/{}_".format(title,
title)+str(counter+1)+".m4a"
with open(savePath, "wb+") as code:
code.write(audio.content)
parser = argparse.ArgumentParser(description='ICE Portal Audiobook Loader')
parser.add_argument('-i','--index', nargs='*', help='Interactive mode; without additional parameters: list all books; use -i 42 3 5 to load these numbers.', required=False)
args = parser.parse_args()
# MAIN
# extract all audiobooks
allbooks = not args.index
books = args.index if args.index else []
audiobooks, booklist = getAllAudiobooks(books, allbooks)
if not allbooks:
for key, value in booklist.items():
print(f"{key} {value}")
createFolder('./audiobooks')
# download all audibooks
for book in audiobooks:
downloadAudiobook(str(book))
Hint: The codec seems to be m4a for now.
Disclaimer: For educational purpose! Do not use it. Listen to the audiobooks during your journey or buy them π
Metadata
Metadata
Assignees
Labels
No labels