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

Providers cleanup #8604

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
29 changes: 29 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"

#Specify inspection profile for code analysis
profile:
name: qodana.starter

#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh

#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-python:latest
13 changes: 0 additions & 13 deletions sickchill/gui/slick/views/addShows_popularShows.mako
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
</div>
</div>
<div class="row">
<% imdb_tt = {show.imdb_id for show in settings.showList if show.imdb_id} %>
<div id="popularShows">
<div id="container">
% if not popular_shows:
Expand All @@ -56,18 +55,6 @@
</div>
% else:
% for current_result in popular_shows:
% if not current_result.getID():
<% continue %>
% endif

<% current_imdb_id = 'tt' + current_result.getID() %>
% if current_imdb_id in imdb_tt:
<% continue %>
% endif

<% current_result.setdefault('rating', '0.0') %>
<% current_result.setdefault('votes', '0') %>

<div class="trakt_show" data-name="${current_result['title']}" data-rating="${current_result['rating']}"
data-votes="${str(current_result['votes']).replace(',', '')}" data-rank="${current_result['popular tv 100 rank']}">
<div class="traktContainer">
Expand Down
400 changes: 148 additions & 252 deletions sickchill/gui/slick/views/config_providers.mako

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions sickchill/gui/slick/views/home.mako
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@

<%include file="/inc_home_menu.mako" />

% if settings.ANIME_SPLIT_HOME:
% if settings.ANIME_SPLIT_HOME_IN_TABS:
<!-- Split in tabs -->
<div id="showTabs">
<!-- Nav tabs -->
<ul>
% for curShowlist in sortedShowLists:
% if curShowlist[1]:
<li><a href="#${curShowlist[0].lower()}TabContent" id="${curShowlist[0].lower()}Tab">${curShowlist[0]}</a></li>
% endif
% endfor
</ul>
<!-- Tab panes -->
<div>
% endif
% for curShowlist in sortedShowLists:
% if curShowlist[1]:
<% curListType = curShowlist[0] %>
<div id=${("showsTabContent", "animeTabContent")[curListType == "Anime"]}>
<div class="row home-container">
<div class="col-md-12">
% if not settings.ANIME_SPLIT_HOME_IN_TABS:
<h1 class="header">${(_('Shows'), _('Anime'))[curListType == "Anime"]}</h1>
% endif
% if settings.HOME_LAYOUT == 'poster':
<div class="loading-spinner"></div>
% endif
<div class="row">
<div class="col-md-12">
<%include file="/inc_home_show_list.mako" args="curListType=curListType, myShowList=curShowlist[1]" />
</div>
</div>
</div>
</div>
</div>
% endif
% endfor
% if settings.ANIME_SPLIT_HOME_IN_TABS:
</div>
</div>
% endif
% else:
% if settings.ANIME_SPLIT_HOME:
% if settings.ANIME_SPLIT_HOME_IN_TABS:
<!-- Split in tabs -->
<div id="showTabs">
<!-- Nav tabs -->
<ul>
% for curShowlist in sortedShowLists:
% if curShowlist[1]:
<li><a href="#${curShowlist[0].lower()}TabContent" id="${curShowlist[0].lower()}Tab">${curShowlist[0]}</a></li>
% endif
% endfor
</ul>
<!-- Tab panes -->
<div>
% endif
% for curShowlist in sortedShowLists:
% if curShowlist[1]:
<% curListType = curShowlist[0] %>
<div id=${("showsTabContent", "animeTabContent")[curListType == "Anime"]}>
<div class="row home-container">
<div class="col-md-12">
% if not settings.ANIME_SPLIT_HOME_IN_TABS:
<h1 class="header">${(_('Shows'), _('Anime'))[curListType == "Anime"]}</h1>
% endif
% if settings.HOME_LAYOUT == 'poster':
<div class="loading-spinner"></div>
% endif
<div class="row">
<div class="col-md-12">
<%include file="/inc_home_show_list.mako" args="curListType=curListType, myShowList=curShowlist[1]" />
</div>
</div>
</div>
</div>
</div>
% endif
% endfor
% if settings.ANIME_SPLIT_HOME_IN_TABS:
</div>
</div>
% endif
% else:
<!-- no split -->
<div class="row home-container">
<div class="col-md-12">
Expand All @@ -61,7 +61,7 @@
% for curShowlist in sortedShowLists:
<div class="row">
<div class="col-md-12">
<%include file="/inc_home_show_list.mako" args="curListType=curShowlist[0], myShowList=curShowlist[1]" />
<%include file="/inc_home_show_list.mako" args="curListType=curShowlist[0], myShowList=curShowlist[1]" />
</div>
</div>
% endfor
Expand Down
17 changes: 7 additions & 10 deletions sickchill/gui/slick/views/home_massAddTable.mako
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@

<table id="addRootDirTable" class="sickchillTable tablesorter">
<thead>
<tr>
<th class="col-checkbox"><input type="checkbox" id="checkAll" checked></th>
<th>${_('Directory')}</th>
<th width="20%">${_('Show Name (tvshow.nfo)')}
<th width="20%">${_('Indexer')}</th>
</tr>
<tr>
<th class="col-checkbox"><input type="checkbox" id="checkAll" checked></th>
<th>${_('Directory')}</th>
<th width="20%">${_('Show Name (tvshow.nfo)')}
<th width="20%">${_('Indexer')}</th>
</tr>
</thead>
<tbody>
% for curDir in dirList:
% for curDir in filter(lambda x: x["added_already"], dirList):
<%
if curDir['added_already']:
continue

indexer = 0
show_id = curDir['dir']
if curDir['existing_info'][0]:
Expand Down
36 changes: 17 additions & 19 deletions sickchill/gui/slick/views/inc_home_show_list_poster.mako
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%!
from sickchill import settings
import calendar
from sickchill.oldbeard.filters import filter_shows_being_removed
from sickchill.oldbeard import scdatetime, network_timezones
from sickchill.helper.common import pretty_file_size
import os
Expand Down Expand Up @@ -45,23 +46,20 @@
</div>
</div>
% endfor
% for curShow in myShowList:
<%
if settings.showQueueScheduler.action.is_in_remove_queue(curShow) or settings.showQueueScheduler.action.is_being_removed(curShow):
continue

cur_airs_next = ''
cur_snatched = 0
cur_downloaded = 0
cur_total = 0
download_stat_tip = ''
display_status = curShow.status

if display_status:
if re.search(r'(?i)(?:new|returning)\s*series', curShow.status):
display_status = 'Continuing'
elif re.search(r'(?i)(?:nded)', curShow.status):
display_status = 'Ended'
% for curShow in filter_shows_being_removed(myShowList):
<%
cur_airs_next = ''
cur_snatched = 0
cur_downloaded = 0
cur_total = 0
download_stat_tip = ''
display_status = curShow.status

if display_status:
if re.search(r'(?i)(?:new|returning)\s*series', curShow.status):
display_status = 'Continuing'
elif re.search(r'(?i)(?:nded)', curShow.status):
display_status = 'Ended'

if curShow.paused:
display_status = _(display_status) + ' ' + _('Paused')
Expand Down Expand Up @@ -95,8 +93,8 @@

if cur_airs_next:
data_date = calendar.timegm(scdatetime.scdatetime.convert_to_setting(network_timezones.parse_date_time(cur_airs_next, curShow.airs, curShow.network)).timetuple())
## elif cur_airs_prev:
## data_date = calendar.timegm(scdatetime.scdatetime.convert_to_setting(network_timezones.parse_date_time(cur_airs_prev, curShow.airs, curShow.network)).timetuple())
# elif cur_airs_prev:
# data_date = calendar.timegm(scdatetime.scdatetime.convert_to_setting(network_timezones.parse_date_time(cur_airs_prev, curShow.airs, curShow.network)).timetuple())
elif display_status:
if display_status.startswith('Continuing'):
data_date = '5000000000.0'
Expand Down
10 changes: 5 additions & 5 deletions sickchill/oldbeard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def __init__(self, config_obj):
1: "Custom naming",
2: "Sync backup number with version number",
3: "Rename omgwtfnzb variables",
4: "Add newznab catIDs",
4: "Add newznab categories",
5: "Metadata update",
6: "Convert from XBMC to new KODI variables",
7: "Use version 2 for password encryption",
Expand Down Expand Up @@ -1071,7 +1071,7 @@ def _migrate_v3(self):
settings.OMGWTFNZBS_USERNAME = check_setting_str(self.config_obj, "omgwtfnzbs", "omgwtfnzbs_uid")
settings.OMGWTFNZBS_APIKEY = check_setting_str(self.config_obj, "omgwtfnzbs", "omgwtfnzbs_key")

# Migration v4: Add default newznab catIDs
# Migration v4: Add default newznab categories
def _migrate_v4(self):
"""Update newznab providers so that the category IDs can be set independently via the config"""

Expand All @@ -1092,11 +1092,11 @@ def _migrate_v4(self):
key = "0"

if name == "NZBs.org":
catIDs = "5030,5040,5060,5070,5090"
categories = "5030,5040,5060,5070,5090"
else:
catIDs = "5030,5040,5060"
categories = "5030,5040,5060"

cur_provider_data_list = [name, url, key, catIDs, enabled]
cur_provider_data_list = [name, url, key, categories, enabled]
new_newznab_data.append("|".join(cur_provider_data_list))

settings.NEWZNAB_DATA = "!!!".join(new_newznab_data)
Expand Down
7 changes: 7 additions & 0 deletions sickchill/oldbeard/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from sickchill import settings


def hide(value):
return "hidden_value" if value else ""

Expand Down Expand Up @@ -28,3 +31,7 @@ def selected(condition: bool) -> str:
if condition:
return "selected"
return ""


def filter_shows_being_removed(show_list):
return {show for show in show_list if not (settings.showQueueScheduler.action.is_in_remove_queue(show) or settings.showQueueScheduler.action.is_being_removed(show))}
Copy link
Contributor

Choose a reason for hiding this comment

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

The filter_shows_being_removed function is well written and follows the set comprehension syntax. It filters out shows that are either in the remove queue or are being removed. However, it's a good practice to add a docstring to explain what the function does.

+   """
+   Filters out shows that are either in the remove queue or are being removed.
+   
+   :param show_list: List of shows to filter
+   :return: Set of shows not in the remove queue or being removed
+   """
def filter_shows_being_removed(show_list):
    return {show for show in show_list if not (settings.showQueueScheduler.action.is_in_remove_queue(show) or settings.showQueueScheduler.action.is_being_removed(show))}

Commitable suggestion (Beta)
Suggested change
def filter_shows_being_removed(show_list):
return {show for show in show_list if not (settings.showQueueScheduler.action.is_in_remove_queue(show) or settings.showQueueScheduler.action.is_being_removed(show))}
def filter_shows_being_removed(show_list):
"""
Filters out shows that are either in the remove queue or are being removed.
:param show_list: List of shows to filter
:return: Set of shows not in the remove queue or being removed
"""
return {show for show in show_list if not (settings.showQueueScheduler.action.is_in_remove_queue(show) or settings.showQueueScheduler.action.is_being_removed(show))}

12 changes: 8 additions & 4 deletions sickchill/oldbeard/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@
]


def sorted_provider_list(randomize=False) -> List[Union[TorrentProvider, NZBProvider, TorrentRssProvider, NZBProvider, GenericProvider]]:
initialList = settings.providerList + settings.newznab_provider_list + settings.torrent_rss_provider_list
provider_dict = {x.get_id(): x for x in initialList}
def sorted_provider_list(randomize=False, only_enabled=False) -> List[Union[TorrentProvider, NZBProvider, TorrentRssProvider, NZBProvider, GenericProvider]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

The return type of the function sorted_provider_list is too complex. Consider creating a type alias for the Union type to improve readability.

ProviderType = Union[TorrentProvider, NZBProvider, TorrentRssProvider, NZBProvider, GenericProvider]
def sorted_provider_list(randomize=False, only_enabled=False) -> List[ProviderType]:

initial_list = settings.providerList + settings.newznab_provider_list + settings.torrent_rss_provider_list

provider_dict = {x.get_id(): x for x in initial_list}

new_provider_list = []

Expand All @@ -145,14 +146,17 @@ def sorted_provider_list(randomize=False) -> List[Union[TorrentProvider, NZBProv

# add all enabled providers first
for current_module in provider_dict:
if provider_dict[current_module] not in new_provider_list and provider_dict[current_module].is_enabled:
if current_module not in new_provider_list and provider_dict[current_module].is_enabled:
new_provider_list.append(provider_dict[current_module])

# add any modules that are missing from that list
for current_module in provider_dict:
if provider_dict[current_module] not in new_provider_list:
new_provider_list.append(provider_dict[current_module])

miigotu marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for adding enabled providers to the new_provider_list and then adding any missing modules remains the same. However, the check current_module not in new_provider_list seems redundant because provider_dict is a dictionary where each key is unique. Therefore, the condition will always be true. This redundancy can be removed to simplify the code.

- if current_module not in new_provider_list and provider_dict[current_module].is_enabled:
+ if provider_dict[current_module].is_enabled:

- if provider_dict[current_module] not in new_provider_list:
+ new_provider_list.append(provider_dict[current_module])

Commitable suggestion (Beta)
Suggested change
# add all enabled providers first
for current_module in provider_dict:
if provider_dict[current_module] not in new_provider_list and provider_dict[current_module].is_enabled:
if current_module not in new_provider_list and provider_dict[current_module].is_enabled:
new_provider_list.append(provider_dict[current_module])
# add any modules that are missing from that list
for current_module in provider_dict:
if provider_dict[current_module] not in new_provider_list:
new_provider_list.append(provider_dict[current_module])
# add all enabled providers first
for current_module in provider_dict:
if provider_dict[current_module].is_enabled:
new_provider_list.append(provider_dict[current_module])
# add any modules that are missing from that list
for current_module in provider_dict:
new_provider_list.append(provider_dict[current_module])

if only_enabled:
new_provider_list = [provider for provider in new_provider_list if (provider.provider_type == GenericProvider.TORRENT and settings.USE_TORRENTS) or (provider.provider_type == GenericProvider.NZB and settings.USE_NZBS)]

if randomize:
shuffle(new_provider_list)
Comment on lines 166 to 167
Copy link
Contributor

Choose a reason for hiding this comment

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

The randomize parameter is used to shuffle the new_provider_list. This is a side effect that might not be expected by the caller. Consider removing this parameter and letting the caller shuffle the list if needed.


Expand Down
6 changes: 3 additions & 3 deletions sickchill/oldbeard/providers/eztv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def search(self, search_strings, episode_object=None):
logger.debug(_("Search Mode: {mode}").format(mode=mode))

if mode != "RSS":
if not (self.show and self.show.imdb_id):
if not (episode_object and episode_object.show and episode_object.show.imdb_id):
continue

search_params["imdb_id"] = self.show.imdb_id.strip("tt")
logger.debug("Search string: {}".format(self.show.imdb_id))
search_params["imdb_id"] = episode_object.show.imdb_id.strip("tt")
logger.debug("Search string: {}".format(episode_object.show.imdb_id))
else:
search_params.pop("imdb_id")

Expand Down
Loading