Skip to content

Commit

Permalink
Changed retrieving of Scribd original titles
Browse files Browse the repository at this point in the history
  • Loading branch information
jo1gi committed Dec 30, 2021
1 parent 7cf6b62 commit 6f6861c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 7 additions & 7 deletions audiobookdl/download.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .utils import output
from .utils import logging
from .utils import metadata
from .utils.source import Source
from .utils.exceptions import UserNotAuthenticated
import os
import shutil
from typing import Dict, List, Optional


def download(source,
def download(source: Source,
combine: bool = False,
output_template: str = "{title}",
output_format: Optional[str] = None):
Expand Down Expand Up @@ -39,21 +40,20 @@ def download(source,
add_metadata_to_dir(source, filenames, output_dir, meta)


def combined_audiobook(source,
def combined_audiobook(source: Source,
filenames: List[str],
output_dir: str,
output_format: Optional[str],
meta: Dict[str, str]):
"""Combines audiobook into a single audio file and embeds metadata"""
output_file = f"{output_dir}.{output_format}"
if len(filenames) > 1:
combine_files(source, filenames, output_dir, output_file)
combine_files(filenames, output_dir, output_file)
embed_metadata_in_file(source, meta, output_file)
shutil.rmtree(output_dir)


def combine_files(source,
filenames: List[str],
def combine_files(filenames: List[str],
output_dir: str,
output_file: str):
"""Combines audiobook files and cleanes up afterward"""
Expand All @@ -64,7 +64,7 @@ def combine_files(source,
exit()


def embed_metadata_in_file(source,
def embed_metadata_in_file(source: Source,
meta: Dict[str, str],
output_file: str):
"""Embed metadata into combined audiobook file"""
Expand All @@ -80,7 +80,7 @@ def embed_metadata_in_file(source,
metadata.add_chapters(output_file, chapters)


def add_metadata_to_dir(source,
def add_metadata_to_dir(source: Source,
filenames: List[str],
output_dir: str,
meta: Dict[str, str]):
Expand Down
6 changes: 3 additions & 3 deletions audiobookdl/sources/scribd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..utils.source import Source
from PIL import Image
import io

import json

class ScribdSource(Source):
match = [
Expand Down Expand Up @@ -83,9 +83,9 @@ def before(self, *args):
self.url,
r'(?<=("jwt_token":"))[^"]+')
self._stream_url = f"https://audio.production.scribd.com/audiobooks/{book_id[7:]}/192kbps.m3u8"
self._title = self.find_in_page(
self._title = self.find_all_in_page(
self.url,
r'(?<=("title":"))[^"]+')
r'(?:("title":"))([^"]+)')[1][1]
self._cover = self.find_in_page(
self.url,
r'(?<=("cover_url":"))[^"]+')
Expand Down
5 changes: 3 additions & 2 deletions audiobookdl/utils/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ def gen_output_location(template: str, metadata: Dict[str, str]) -> str:
audiobook"""
if metadata is None:
metadata = {}
metadata["title"] = fix_output(metadata["title"])
metadata = {**LOCATION_DEFAULTS, **metadata}
return template.format(**metadata)


def fix_output(title) -> str:
def fix_output(title: str) -> str:
"""Returns title without characters system can't handle"""
title = title.replace("/", "-")
if platform.system() == "Windows":
title = remove_chars(title, ':*\\?<>|"')
return title


def remove_chars(s, chars) -> str:
def remove_chars(s: str, chars: str) -> str:
"""Removes `chars` from `s`"""
for i in chars:
s = s.replace(i, "")
Expand Down

0 comments on commit 6f6861c

Please sign in to comment.