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

mass refactor tv.py #8706

Merged
merged 31 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
83e529a
refactor: lowercase and typo function, parameter, and variable names …
miigotu Feb 3, 2024
a3055a7
fix: use property decorators instead of accessors to avoid type check…
miigotu Feb 3, 2024
e36b6fb
black
miigotu Feb 3, 2024
8a67418
chore: update release workflow
miigotu Feb 3, 2024
89546f4
refactor: missed changes
miigotu Feb 3, 2024
6989d8c
additional time error capture
BKSteve Feb 3, 2024
7ba09ac
refactor: more renaming and fixing types
miigotu Feb 3, 2024
0bcd73f
fix: can't add init to tornado base class? causes PageTemplate initia…
miigotu Feb 3, 2024
6850259
fix: try to fix airdate modify timestamp, remove some unneded mako co…
miigotu Feb 4, 2024
846aa4a
chore:black formatting
miigotu Feb 4, 2024
754e34f
air date tm_isdst
BKSteve Feb 4, 2024
c20da34
air date tm_isdst clean
BKSteve Feb 4, 2024
ae3e0ff
Merge branch 'develop' into wtf-is-wrong-with-me-lol
miigotu Feb 6, 2024
cb4c31b
backlog page variables - log reduction
BKSteve Feb 11, 2024
2a6deff
backlog page variables lowercase 2
BKSteve Feb 11, 2024
4735005
trending add - redirectable
BKSteve Feb 11, 2024
9614388
searchBacklog needs int
BKSteve Feb 11, 2024
0ac7c4c
subtitles remove legendastv
BKSteve Feb 11, 2024
7b58831
add shows redirect allowed
BKSteve Feb 12, 2024
18c4a7d
regex single char alternation - Qodana
BKSteve Feb 12, 2024
b44dc29
docstring parameters - Qodana
BKSteve Feb 12, 2024
6340a58
fstring logs
BKSteve Feb 12, 2024
212444f
fstring logs 2
BKSteve Feb 12, 2024
dacdd68
wordle
BKSteve Feb 12, 2024
140482a
remove show get*
BKSteve Feb 12, 2024
8e44069
snaking vars
BKSteve Feb 12, 2024
735ea0a
home unused var removal
BKSteve Feb 12, 2024
0fb6c6b
t.render layout
BKSteve Feb 12, 2024
bae210c
Failed download + params
BKSteve Feb 12, 2024
a6ed3a4
revert (_(f
BKSteve Feb 12, 2024
b96ea86
Merge branch 'develop' into wtf-is-wrong-with-me-lol
miigotu Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions SickChill.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import datetime
import mimetypes
import os
import platform
import shutil
Expand Down Expand Up @@ -28,14 +29,12 @@

setup_gettext()

import mimetypes

mimetypes.add_type("text/css", ".css")
mimetypes.add_type("application/sfont", ".otf")
mimetypes.add_type("application/sfont", ".ttf")
mimetypes.add_type("application/javascript", ".js")
mimetypes.add_type("application/font-woff", ".woff")
# Not sure about this one, but we also have halflings in .woff so I think it wont matter
# Not sure about this one, but we also have halflings in .woff, so I think it won't matter
# mimetypes.add_type("application/font-woff2", ".woff2")

from configobj import ConfigObj
Expand Down Expand Up @@ -67,6 +66,8 @@ def __init__(self):
self.run_as_daemon = False

# web server constants
self.flask_server = None

self.web_server = None
self.forced_port = None
self.no_launch = False
Expand Down Expand Up @@ -253,7 +254,7 @@ def load_shows_from_db():
for sql_show in sql_results:
try:
cur_show = TVShow(sql_show["indexer"], sql_show["indexer_id"])
cur_show.nextEpisode()
cur_show.next_episode()
settings.showList.append(cur_show)
except Exception as error:
logger.exception("There was an error creating the show in {}: Error {}".format(sql_show["location"], error))
Expand Down Expand Up @@ -301,7 +302,7 @@ def shutdown(self, event):
"""
if settings.started:
sickchill.start.halt() # stop all tasks
sickchill.start.saveAll() # save all shows to DB
sickchill.start.save_all() # save all shows to DB

# shutdown web server
if self.web_server:
Expand Down
68 changes: 34 additions & 34 deletions sickchill/gui/slick/views/config_providers.mako

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sickchill/oldbeard/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def make_result(cls, result_dict):
return show[0]

show = show[1]
episode_objects = [show.getEpisode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]
episode_objects = [show.get_episode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method call get_episode should be getEpisode to match the updated naming convention.

-        episode_objects = [show.get_episode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]
+        episode_objects = [show.getEpisode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
episode_objects = [show.get_episode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]
episode_objects = [show.getEpisode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]

result = cls(episode_objects)
result.from_json(result_dict)
result.show = show
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/dailysearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(self, force=False):
if air_time > curTime:
continue

ep = show.getEpisode(sqlEp["season"], sqlEp["episode"])
ep = show.get_episode(sqlEp["season"], sqlEp["episode"])
with ep.lock:
prefix = _("New episode {episode_string} airs today,").format(episode_string=ep.pretty_name)
if ep.season == 0:
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/failedProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def process(self):
self._log(f"{parsed.air_date}", logger.DEBUG)

for episode in parsed.episode_numbers:
segment = parsed.show.getEpisode(parsed.season_number, episode)
segment = parsed.show.get_episode(parsed.season_number, episode)

cur_failed_queue_item = search_queue.FailedQueueItem(parsed.show, [segment])
settings.searchQueueScheduler.action.add_item(cur_failed_queue_item)
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def get_all_episodes_from_absolute_number(show, absolute_numbers, indexer_id=Non
show = Show.find(settings.showList, indexer_id)

for absolute_number in absolute_numbers if show else []:
ep = show.getEpisode(None, None, absolute_number=absolute_number)
ep = show.get_episode(None, None, absolute_number=absolute_number)
BKSteve marked this conversation as resolved.
Show resolved Hide resolved
if ep:
episodes.append(ep.episode)
season = ep.season # this will always take the last found season so eps that cross the season border are not handeled well
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/nzbSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ def split_result(obj):

want_ep = True
for ep_num in parsed_obj.episode_numbers:
if not obj.show.wantEpisode(season, ep_num, obj.quality):
if not obj.show.want_episode(season, ep_num, obj.quality):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method call want_episode should be wantEpisode to match the updated naming convention.

-            if not obj.show.want_episode(season, ep_num, obj.quality):
+            if not obj.show.wantEpisode(season, ep_num, obj.quality):

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if not obj.show.want_episode(season, ep_num, obj.quality):
if not obj.show.wantEpisode(season, ep_num, obj.quality):

logger.debug("Ignoring result: " + new_nzb)
want_ep = False
break
if not want_ep:
continue

# get all the associated episode objects
ep_obj_list = [obj.show.getEpisode(season, ep) for ep in parsed_obj.episode_numbers]
ep_obj_list = [obj.show.get_episode(season, ep) for ep in parsed_obj.episode_numbers]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method call get_episode should be getEpisode to match the updated naming convention.

-        ep_obj_list = [obj.show.get_episode(season, ep) for ep in parsed_obj.episode_numbers]
+        ep_obj_list = [obj.show.getEpisode(season, ep) for ep in parsed_obj.episode_numbers]

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
ep_obj_list = [obj.show.get_episode(season, ep) for ep in parsed_obj.episode_numbers]
ep_obj_list = [obj.show.getEpisode(season, ep) for ep in parsed_obj.episode_numbers]


# make a result
cur_obj = classes.NZBDataSearchResult(ep_obj_list)
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def _get_ep_obj(self, show, season, episodes):

# now that we've figured out which episode this file is just load it manually
try:
curEp = show.getEpisode(season, cur_episode)
curEp = show.get_episode(season, cur_episode)
BKSteve marked this conversation as resolved.
Show resolved Hide resolved
if not curEp:
raise EpisodeNotFoundException()
except EpisodeNotFoundException as error:
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def process(self):
raise EpisodePostProcessingFailedException(_("Unable to create the show directory: ") + episode_object.show._location)

# get metadata for the show (but not episode because it hasn't been fully processed)
episode_object.show.writeMetadata(True)
episode_object.show.write_metadata(True)
BKSteve marked this conversation as resolved.
Show resolved Hide resolved

# update the ep info before we rename so the quality & release name go into the name properly
sql_l = []
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/properFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _download_propers(self, proper_list):
continue

# get the episode object
episode_object = proper.show.getEpisode(proper.season, proper.episode)
episode_object = proper.show.get_episode(proper.season, proper.episode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method call get_episode should be getEpisode to match the updated naming convention.

-                episode_object = proper.show.get_episode(proper.season, proper.episode)
+                episode_object = proper.show.getEpisode(proper.season, proper.episode)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
episode_object = proper.show.get_episode(proper.season, proper.episode)
episode_object = proper.show.getEpisode(proper.season, proper.episode)


# make the result object
result = proper.provider.get_result([episode_object])
Expand Down
4 changes: 1 addition & 3 deletions sickchill/oldbeard/providers/bjshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@


class Provider(TorrentProvider):
"""
BJ-Share Torrent provider.
"""
"""BJ-Share Torrent provider."""

def __init__(self):
"""Initialize the class."""
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/scene_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def set_scene_numbering(indexer_id, indexer, season=None, episode=None, absolute

# Reload data from DB so that cache and db are in sync
show = Show.find(settings.showList, indexer_id)
show.flushEpisodes()
show.flush_episodes()


def find_xem_numbering(indexer_id, indexer, season, episode):
Expand Down
8 changes: 4 additions & 4 deletions sickchill/oldbeard/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def wanted_episodes(show, from_date):
elif quality in allowed_qualities:
continue

episode_object = show.getEpisode(result["season"], result["episode"])
episode_object = show.get_episode(result["season"], result["episode"])
episode_object.wantedQuality = [i for i in all_qualities if i > quality and i != common.Quality.UNKNOWN]
wanted.append(episode_object)

Expand Down Expand Up @@ -526,7 +526,7 @@ def search_providers(show, episodes, manual=False, downCurQuality=False):
some_wanted = False
for episode_number in all_episodes:
for season in (x.season for x in episodes):
if not show.wantEpisode(season, episode_number, season_quality, downCurQuality):
if not show.want_episode(season, episode_number, season_quality, downCurQuality):
all_wanted = False
else:
some_wanted = True
Expand All @@ -537,7 +537,7 @@ def search_providers(show, episodes, manual=False, downCurQuality=False):
episode_objects = []
for episode_number in all_episodes:
for season in {x.season for x in episodes}:
episode_objects.append(show.getEpisode(season, episode_number))
episode_objects.append(show.get_episode(season, episode_number))
best_season_result.episodes = episode_objects

# Remove provider from thread name before return results
Expand Down Expand Up @@ -575,7 +575,7 @@ def search_providers(show, episodes, manual=False, downCurQuality=False):
episode_objects = []
for episode_number in all_episodes:
for season in {x.season for x in episodes}:
episode_objects.append(show.getEpisode(season, episode_number))
episode_objects.append(show.get_episode(season, episode_number))
best_season_result.episodes = episode_objects

if MULTI_EP_RESULT in found_results[curProvider.name]:
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/searchBacklog.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_segments(show, fromDate):
elif cur_quality in allowed_qualities:
continue

episode_object = show.getEpisode(sql_result["season"], sql_result["episode"])
episode_object = show.get_episode(sql_result["season"], sql_result["episode"])

if episode_object.season not in wanted:
wanted[episode_object.season] = [episode_object]
Expand Down
42 changes: 21 additions & 21 deletions sickchill/oldbeard/show_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def run(self):
self.show.load_imdb_info()

try:
self.show.saveToDB()
self.show.save_to_db()
except Exception as error:
logger.exception(f"Error saving the show to the database: {error}")
logger.debug(traceback.format_exc())
Expand All @@ -492,7 +492,7 @@ def run(self):
settings.showList.append(self.show)

try:
self.show.loadEpisodesFromIndexer(force_all=True)
self.show.load_episodes_from_indexer(force_all=True)
except Exception as error:
logger.exception(f"Error with {self.show.idxr.name}, not creating episode list: {error}")
logger.debug(traceback.format_exc())
Expand All @@ -501,7 +501,7 @@ def run(self):
name_cache.build_name_cache(self.show)

try:
self.show.loadEpisodesFromDir()
self.show.load_episodes_from_dir()
except Exception as error:
logger.exception(f"Error searching dir for episodes: {error}")
logger.debug(traceback.format_exc())
Expand All @@ -512,11 +512,11 @@ def run(self):
logger.info("Launching backlog for this show since its episodes are WANTED")
settings.backlogSearchScheduler.action.searchBacklog([self.show])

self.show.writeMetadata()
self.show.updateMetadata()
self.show.populateCache()
self.show.write_metadata()
self.show.update_metadata()
self.show.populate_cache()

self.show.flushEpisodes()
self.show.flush_episodes()

if settings.USE_TRAKT:
# if there are specific episodes that need to be added by trakt
Expand Down Expand Up @@ -565,11 +565,11 @@ def run(self):

logger.info(f"Performing refresh on {self.show.name}")

self.show.refreshDir()
self.show.writeMetadata()
self.show.refresh_dir()
self.show.write_metadata()
if self.force:
self.show.updateMetadata()
self.show.populateCache()
self.show.update_metadata()
self.show.populate_cache()

# Load XEM data to DB for show
scene_numbering.xem_refresh(self.show.indexerid, self.show.indexer)
Expand Down Expand Up @@ -597,7 +597,7 @@ def run(self):

ep_obj_rename_list = []

ep_obj_list = self.show.getAllEpisodes(has_location=True)
ep_obj_list = self.show.get_all_episodes(has_location=True)
for cur_ep_obj in ep_obj_list:
# Only want to rename if we have a location
if cur_ep_obj.location:
Expand Down Expand Up @@ -655,27 +655,27 @@ def run(self):

# have to save show before reading episodes from db
try:
self.show.saveToDB()
self.show.save_to_db()
except Exception as error:
logger.exception(f"Error saving show info to the database: {error}")
logger.debug(traceback.format_exc())

# get episode list from DB
DBEpList = self.show.loadEpisodesFromDB()
DBEpList = self.show.load_episodes_from_db()

# get episode list from TVDB
logger.debug(f"Loading all episodes from {self.show.idxr.name}")
try:
IndexerEpList = self.show.loadEpisodesFromIndexer(self.force)
IndexerEpList = self.show.load_episodes_from_indexer(self.force)
except Exception as error:
logger.exception(f"Unable to get info from {self.show.idxr.name}, the show info will not be refreshed: {error}")
IndexerEpList = None

if IndexerEpList:
for curSeason in IndexerEpList:
for curEpisode in IndexerEpList[curSeason]:
curEp = self.show.getEpisode(curSeason, curEpisode)
curEp.saveToDB()
curEp = self.show.get_episode(curSeason, curEpisode)
curEp.save_to_db()

if curSeason in DBEpList and curEpisode in DBEpList[curSeason]:
del DBEpList[curSeason][curEpisode]
Expand All @@ -684,15 +684,15 @@ def run(self):
for curSeason in DBEpList:
for curEpisode in DBEpList[curSeason]:
logger.info("Permanently deleting episode {0:02d}E{1:02d} from the database".format(curSeason, curEpisode))
curEp = self.show.getEpisode(curSeason, curEpisode)
curEp = self.show.get_episode(curSeason, curEpisode)
try:
curEp.deleteEpisode()
curEp.delete_episode()
except EpisodeDeletedException:
pass

# save show again, in case episodes have changed
try:
self.show.saveToDB()
self.show.save_to_db()
except Exception as error:
logger.exception(f"Error saving show info to the database: {error}")
logger.debug(traceback.format_exc())
Expand All @@ -716,7 +716,7 @@ def __init__(self, show=None, full=False):
def run(self):
super(QueueItemRemove, self).run()
logger.info(f"Removing {self.show.name}")
self.show.deleteShow(full=self.full)
self.show.delete_show(full=self.full)

if settings.USE_TRAKT:
try:
Expand Down
2 changes: 1 addition & 1 deletion sickchill/oldbeard/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def dhm(td):
logger.debug(f"Show with ID {ep_show_id} not found in the database")
continue

episode_object = show_object.getEpisode(ep_season, ep_episode)
episode_object = show_object.get_episode(ep_season, ep_episode)
if isinstance(episode_object, str):
logger.debug(f"{ep_show_name} {ep_string} not found in the database")
continue
Expand Down
4 changes: 2 additions & 2 deletions sickchill/oldbeard/traktChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def _set_episode_to_wanted(show, season, episode):
"""
Sets an episode to wanted, only if it is currently skipped
"""
episode_object = show.getEpisode(season, episode)
episode_object = show.get_episode(season, episode)
if episode_object:
with episode_object.lock:
if episode_object.status != SKIPPED or episode_object.airdate == datetime.date.min:
Expand All @@ -604,7 +604,7 @@ def _set_episode_to_wanted(show, season, episode):
# figure out what segment the episode is in and remember it, so we can backlog it

episode_object.status = WANTED
episode_object.saveToDB()
episode_object.save_to_db()

cur_backlog_queue_item = search_queue.BacklogQueueItem(show, [episode_object])
settings.searchQueueScheduler.action.add_item(cur_backlog_queue_item)
Expand Down
6 changes: 3 additions & 3 deletions sickchill/oldbeard/tvcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def list_propers(self, date=None):
propers_results = cache_db_con.select(sql, [self.provider_id])
return [x for x in propers_results if x["indexerid"]]

def find_needed_episodes(self, episode, manualSearch=False, downCurQuality=False):
def find_needed_episodes(self, episode, manual_search=False, down_cur_quality=False):
needed_eps = {}
cl = []

Expand Down Expand Up @@ -477,11 +477,11 @@ def find_needed_episodes(self, episode, manualSearch=False, downCurQuality=False
cur_version = cur_result["version"]

# if the show says we want that episode then add it to the list
if not show_obj.wantEpisode(cur_season, cur_ep, cur_quality, manualSearch, downCurQuality):
if not show_obj.want_episode(cur_season, cur_ep, cur_quality, manual_search, down_cur_quality):
logger.debug("Ignoring " + cur_result["name"])
continue

episode_object = show_obj.getEpisode(cur_season, cur_ep)
episode_object = show_obj.get_episode(cur_season, cur_ep)

# build a result object
title = cur_result["name"]
Expand Down
Loading