Run black on all Python scripts!
This commit is contained in:
parent
fb6cfce656
commit
cd9cbcaa28
30 changed files with 1027 additions and 704 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# pylint: disable=C0103,W0621
|
||||
|
||||
# pip install tmdbv3api
|
||||
|
@ -20,8 +20,8 @@ Episode = typing.Any # TODO
|
|||
|
||||
# Constants
|
||||
|
||||
API_KEY_PASS_PATH = 'http/themoviedb.org'
|
||||
VIDEO_EXTENSIONS = {'mp4', 'mkv', 'avi', 'webm'}
|
||||
API_KEY_PASS_PATH = "http/themoviedb.org"
|
||||
VIDEO_EXTENSIONS = {"mp4", "mkv", "avi", "webm"}
|
||||
|
||||
# Functions
|
||||
|
||||
|
@ -31,12 +31,12 @@ def get_pass_data(path: str) -> typing.Dict[str, str]:
|
|||
Returns the data stored in the Unix password manager
|
||||
given its path.
|
||||
"""
|
||||
run = subprocess.run(['pass', path], stdout=subprocess.PIPE, check=True)
|
||||
lines = run.stdout.decode().split('\n')
|
||||
run = subprocess.run(["pass", path], stdout=subprocess.PIPE, check=True)
|
||||
lines = run.stdout.decode().split("\n")
|
||||
data = dict()
|
||||
data['pass'] = lines[0]
|
||||
data["pass"] = lines[0]
|
||||
for line in lines[1:]:
|
||||
match = re.match(r'(\w+): ?(.+)', line)
|
||||
match = re.match(r"(\w+): ?(.+)", line)
|
||||
if match:
|
||||
data[match[1]] = match[2]
|
||||
return data
|
||||
|
@ -44,24 +44,27 @@ def get_pass_data(path: str) -> typing.Dict[str, str]:
|
|||
|
||||
def confirm(text: str) -> bool:
|
||||
res = input(text + " [yn] ")
|
||||
while res not in ('y', 'n'):
|
||||
while res not in ("y", "n"):
|
||||
res = input("Please answer with y or n: ")
|
||||
return res == 'y'
|
||||
return res == "y"
|
||||
|
||||
|
||||
def episode_identifier(episode: typing.Any) -> str:
|
||||
return f"S{episode['season_number']:02d}E" + \
|
||||
f"{episode['episode_number']:02d} {episode['name']}"
|
||||
return (
|
||||
f"S{episode['season_number']:02d}E"
|
||||
+ f"{episode['episode_number']:02d} {episode['name']}"
|
||||
)
|
||||
|
||||
dryrun = '-n' in sys.argv
|
||||
|
||||
dryrun = "-n" in sys.argv
|
||||
if dryrun:
|
||||
dryrun = True
|
||||
sys.argv.remove('-n')
|
||||
sys.argv.remove("-n")
|
||||
|
||||
|
||||
# Connecting to TMBDB
|
||||
tmdb = tmdbv3api.TMDb()
|
||||
tmdb.api_key = get_pass_data(API_KEY_PASS_PATH)['api']
|
||||
tmdb.api_key = get_pass_data(API_KEY_PASS_PATH)["api"]
|
||||
tmdb.language = sys.argv[1]
|
||||
|
||||
# Searching the TV show name (by current directory name)
|
||||
|
@ -71,8 +74,8 @@ if len(sys.argv) >= 3:
|
|||
show_name = sys.argv[2]
|
||||
else:
|
||||
show_name = os.path.split(os.path.realpath(os.path.curdir))[1]
|
||||
if '(' in show_name:
|
||||
show_name = show_name.split('(')[0].strip()
|
||||
if "(" in show_name:
|
||||
show_name = show_name.split("(")[0].strip()
|
||||
|
||||
search = tv.search(show_name)
|
||||
|
||||
|
@ -86,15 +89,14 @@ for res in search:
|
|||
break
|
||||
|
||||
if not show:
|
||||
print("Could not find a matching " +
|
||||
f"show on TheMovieDatabase for {show_name}.")
|
||||
print("Could not find a matching " + f"show on TheMovieDatabase for {show_name}.")
|
||||
sys.exit(1)
|
||||
|
||||
# Retrieving all the episode of the show
|
||||
episodes: typing.List[Episode] = list()
|
||||
|
||||
print(f"List of episodes for {show.name}:")
|
||||
for season_number in range(0, show.number_of_seasons+1):
|
||||
for season_number in range(0, show.number_of_seasons + 1):
|
||||
season_details = season.details(show.id, season_number)
|
||||
|
||||
try:
|
||||
|
@ -119,22 +121,22 @@ for root, dirs, files in os.walk(os.path.curdir):
|
|||
print(f"- {filename}")
|
||||
|
||||
|
||||
def get_episode(season_number: int, episode_number: int
|
||||
) -> typing.Optional[Episode]:
|
||||
def get_episode(season_number: int, episode_number: int) -> typing.Optional[Episode]:
|
||||
# TODO Make more efficient using indexing
|
||||
for episode in episodes:
|
||||
if episode['season_number'] == season_number \
|
||||
and episode['episode_number'] == episode_number:
|
||||
if (
|
||||
episode["season_number"] == season_number
|
||||
and episode["episode_number"] == episode_number
|
||||
):
|
||||
return episode
|
||||
return None
|
||||
|
||||
|
||||
# Matching movie files to episode
|
||||
associations: typing.List[typing.Tuple[typing.Tuple[str,
|
||||
str], Episode]] = list()
|
||||
associations: typing.List[typing.Tuple[typing.Tuple[str, str], Episode]] = list()
|
||||
for video in videos:
|
||||
root, filename = video
|
||||
match = re.search(r'S(\d+)E(\d+)', filename)
|
||||
match = re.search(r"S(\d+)E(\d+)", filename)
|
||||
print(f"Treating file: {root}/{filename}")
|
||||
episode = None
|
||||
season_number = 0
|
||||
|
@ -155,7 +157,8 @@ for video in videos:
|
|||
episode = get_episode(season_number, episode_number)
|
||||
if not episode:
|
||||
print(
|
||||
f" could not find episode S{season_number:02d}E{episode_number:02d} in TMBD")
|
||||
f" could not find episode S{season_number:02d}E{episode_number:02d} in TMBD"
|
||||
)
|
||||
|
||||
# Skip
|
||||
if not episode:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue