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 8 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
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Build develop branch

on:
workflow_run:
workflows: [Python Packaging]
branches: |
- develop
types:
- completed
workflows: [ Python Packaging ]
branches: [ develop ]
types: [ completed, requested ]

jobs:
version:
Comment on lines 2 to 10
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [21-21]

Using cache: 'yarn' with actions/setup-node@v4 while running npm install -g yarn seems redundant. If Yarn is being used, consider removing the npm install -g yarn command or clarify the necessity of this approach.

Expand Down
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.

12 changes: 6 additions & 6 deletions sickchill/gui/slick/views/displayShow.mako
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@
(season_number, episode_number) = (default_season, default_episode)
default_episode_numbering = True

epLoc = epResult["location"]
if epLoc and show._location and epLoc.lower().startswith(show._location.lower()):
epLoc = epLoc[len(show._location)+1:]
episode_location = epResult["location"]
if episode_location and show.get_location and episode_location.lower().startswith(show.get_location.lower()):
episode_location = episode_location[len(show.get_location)+1:]
%>
% if int(epResult["season"]) != curSeason:
% if epResult["season"] != sql_results[0]["season"]:
Expand Down Expand Up @@ -485,8 +485,8 @@
<td class="text-center episode">
<%
text = str(epResult['episode'])
if epLoc:
text = '<span title="' + epLoc + '" class="addQTip">' + text + "</span>"
if episode_location:
text = '<span title="' + episode_location + '" class="addQTip">' + text + "</span>"
Comment on lines +488 to +489
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable episode_location is used within an HTML attribute without proper escaping, potentially leading to Cross-Site Scripting (XSS) vulnerabilities. Ensure to escape episode_location before embedding it into the HTML.

%>
${text}
</td>
Expand Down Expand Up @@ -523,7 +523,7 @@
% endif
${epResult["name"]}
</td>
<td class="col-name location">${epLoc}</td>
<td class="col-name location">${episode_location}</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

The display of episode_location directly in the HTML could lead to Cross-Site Scripting (XSS) vulnerabilities if the variable contains untrusted data. Ensure episode_location is properly sanitized or escaped before being rendered.

<td class="col-ep size">
% if epResult["file_size"]:
${pretty_file_size(epResult["file_size"])}
Expand Down
2 changes: 1 addition & 1 deletion sickchill/gui/slick/views/editShow.mako
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</div>
<div class="col-lg-9 col-md-8 col-sm-7 col-xs-12 component-desc">
<input type="hidden" name="show" id="showID" value="${show.indexerid}" />
<input type="text" name="location" id="location" value="${show._location}"
<input type="text" name="location" id="location" value="${show.get_location}"
class="form-control input-sm input350"
autocapitalize="off" title="Location" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion sickchill/gui/slick/views/layouts/main.mako
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
% if resource:
<span class="footer-item">${_('Memory used')}: <span class="footerhighlight">${pretty_file_size(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss*1024)}</span></span> |
% endif
<span class="footer-item">${_('Load time')}: <span class="footerhighlight">${"{:.4f}".format(time() - sbStartTime)}s</span></span> |
<span class="footer-item">${_('Load time')}: <span class="footerhighlight">${"{:.4f}".format(time() - scStartTime)}s</span></span> |
<span class="footer-item">Mako: <span class="footerhighlight">${"{:.4f}".format(time() - makoStartTime)}s</span></span> |
<span class="footer-item">${_('Version')}: <span class="footerhighlight">${get_current_version()}</span></span> |
<span class="footer-item">${_('Now')}: <span class="footerhighlight">${datetime.datetime.now().strftime(settings.DATE_PRESET+" "+settings.TIME_PRESET)}</span></span>
Expand Down
2 changes: 1 addition & 1 deletion sickchill/gui/slick/views/manage.mako
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<td class="text-center">${statusStrings[curShow.default_ep_status]}</td>
<td class="text-center">${_(curShow.status)}</td>

<td class="text-center">${curShow._location.rsplit('\\', 1)[0]}</td>
<td class="text-center">${curShow.get_location.rsplit('\\', 1)[0]}</td>
Copy link
Contributor

Choose a reason for hiding this comment

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

Use of get_location method without error handling or checking if the method exists.

<td class="text-center">
<% disabled = settings.showQueueScheduler.action.is_being_updated(curShow) or settings.showQueueScheduler.action.is_in_update_queue(curShow) %>
<label for="update-${curShow.indexerid}" class="sr-only">${_('Update')} ${curShow.name}</label>
Expand Down
4 changes: 2 additions & 2 deletions sickchill/gui/slick/views/testRename.mako
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@
% for current_episode in sorted(show.episodes[current_season], reverse=True):
<%
episode_object = show.episodes[current_season][current_episode]
if not (episode_object and episode_object._location):
if not (episode_object and episode_object.location):
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing error handling for episode_object.location and show.get_location calls.

continue

episode_list = episode_object.sorted_episode_list
if episode_object.episode != min(episode_list):
continue

location = episode_object.location[len(show._location)+1:]
location = episode_object.location[len(show.get_location)+1:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential performance issue: episode_object.location[len(show.get_location)+1:] could be inefficient if show.get_location is a costly operation.

- location = episode_object.location[len(show.get_location)+1:]
+ show_location_length = len(show.get_location)
+ location = episode_object.location[show_location_length+1:]

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
location = episode_object.location[len(show.get_location)+1:]
show_location_length = len(show.get_location)
location = episode_object.location[show_location_length+1:]

extension = location.split('.')[-1]
new_location = episode_object.proper_path() + '.' + extension
%>
Expand Down
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
32 changes: 16 additions & 16 deletions 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 Expand Up @@ -891,22 +891,22 @@ def _check_against_names(nameInQuestion, show, season=-1):
return False


def get_show(name, tryIndexers=False):
def get_show(name, try_indexers=False):
if not settings.showList:
return

showObj = None
fromCache = False
show_object = None
from_cache = False

if not name:
return showObj
return show_object

try:
# check cache for show
cache = sickchill.oldbeard.name_cache.get_id_from_name(name)
if cache:
fromCache = True
showObj = Show.find(settings.showList, int(cache))
from_cache = True
show_object = Show.find(settings.showList, int(cache))
else:
check_names = [full_sanitizeSceneName(name), name]
show_matches = [
Expand All @@ -917,31 +917,31 @@ def get_show(name, tryIndexers=False):
]

if len(show_matches) == 1:
showObj = show_matches[0]
show_object = show_matches[0]

# try indexers
if not showObj and tryIndexers:
if not show_object and try_indexers:
result = sickchill.indexer.search_indexers_for_series_id(name=full_sanitizeSceneName(name))[1]
if result:
showObj = Show.find(settings.showList, result.id)
show_object = Show.find(settings.showList, result.id)

# try scene exceptions
if not showObj:
if not show_object:
scene_exceptions = sickchill.oldbeard.scene_exceptions.get_scene_exception_by_name_multiple(name)
for scene_exception in scene_exceptions:
if scene_exception[0]:
showObj = Show.find(settings.showList, scene_exception[0])
if showObj:
show_object = Show.find(settings.showList, scene_exception[0])
if show_object:
break

# add show to cache
if showObj and not fromCache:
sickchill.oldbeard.name_cache.add_name(name, showObj.indexerid)
if show_object and not from_cache:
sickchill.oldbeard.name_cache.add_name(name, show_object.indexerid)
except Exception as error:
logger.debug(_("There was a problem when attempting to find {name} in SickChill. Error: {error}").format(name=name, error=error))
logger.debug(traceback.format_exc())

return showObj
return show_object


def is_hidden_folder(folder):
Expand Down
Loading
Loading