Skip to content

Commit

Permalink
Added more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
jo1gi committed Dec 29, 2021
1 parent 8d6dbae commit 7cf6b62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
8 changes: 4 additions & 4 deletions audiobookdl/utils/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
}


def gen_output_filename(booktitle, file, template):
def gen_output_filename(booktitle: str, file: Dict[str, str], template: str) -> str:
"""Generates an output filename based on different attributes of the
file"""
arguments = {**file, **{"booktitle": booktitle}}
filename = template.format(**arguments)
return fix_output(filename)


def combine_audiofiles(filenames, tmp_dir, output_path):
def combine_audiofiles(filenames: List[str], tmp_dir: str, output_path: str):
"""Combines the given audiofiles in `path` into a new file"""
combine_file = os.path.join(tmp_dir, "combine.txt")
with open(combine_file, "a") as f:
Expand Down Expand Up @@ -59,15 +59,15 @@ def gen_output_location(template: str, metadata: Dict[str, str]) -> str:
return template.format(**metadata)


def fix_output(title):
def fix_output(title) -> 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):
def remove_chars(s, chars) -> str:
"""Removes `chars` from `s`"""
for i in chars:
s = s.replace(i, "")
Expand Down
12 changes: 4 additions & 8 deletions audiobookdl/utils/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,30 @@ def before(self):
"""Operations to be run before the audiobook is downloaded"""
pass

def after(self):
"""Operations to be run after the audiobook is downloaded"""
pass

def get_title(self) -> str:
return ""

@property
def title(self) -> str:
return self.get_title()

def get_metadata(self):
def get_metadata(self) -> Dict[str, str]:
"""Returns metadata of the audiobook"""
return {}

@property
def metadata(self):
def metadata(self) -> Dict[str, str]:
return {"title": self.title, **self.get_metadata()}

def get_cover(self):
"""Returns the image data for the audiobook"""
pass

def get_cover_extension(self):
def get_cover_extension(self) -> str:
"""Returns the filetype of the cover from `get_cover`"""
return "jpg"

def get_files(self):
def get_files(self) -> List[Dict[str, str]]:
pass

def get_chapters(self):
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mkShell {
(python3.withPackages(ps: with ps; [
mutagen
requests
types-requests
rich
lxml
pydub
Expand Down

0 comments on commit 7cf6b62

Please sign in to comment.