Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request: Script updated #5

Open
Ritterbrater opened this issue May 25, 2022 · 1 comment
Open

Pull Request: Script updated #5

Ritterbrater opened this issue May 25, 2022 · 1 comment

Comments

@Ritterbrater
Copy link

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 👍

@gratuxri
Copy link

Disclaimer: For educational purpose! Do not use it. Watch the videos and read the journals during your journey or buy them +1
curl -s -L https://api.filme-serien.iceportal.de/api/portal-teasers |jq -r '."hydra:member"[].slug' |while read a ; do curl -o ${a}.m4s "https://assets.filme-serien.iceportal.de/contents/media/videos/${a}/t/dash_vp9/video-stream-1080p-vp9-2200.m4s" ; done
curl -L https://www.iceportal.de/api1/rs/page/zeitungskiosk |jq -r '.teaserGroups[].items[].navigation.href' |sed 's#^/zeitungskiosk/##g' |while read a ; do curl -o ${a}.pdf https://www.iceportal.de/api1/rs/magazines/file/freeCopy/$a/82d9cebe.5e94809b0d92d/$a.pdf ; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants