Skip to content

Commit

Permalink
Providers cleanup (#8604)
Browse files Browse the repository at this point in the history
* rename variables for clarity in relation to providers
use has_option rather than hasattr
clean up mako, avoid continue if we can, filter the lists in python
add ability to only get enabled provider types from sorted_provider_lsits
add method to filter show list to remove shows that are being deleted
Signed-off-by: miigotu <[email protected]>

* fix a few mistakes

Signed-off-by: miigotu <[email protected]>

* Update sickchill/show/History.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix coderabitt screwup

Signed-off-by: miigotu <[email protected]>

* some fixes that didnt get into the last commit

Signed-off-by: miigotu <[email protected]>

* fix formatting

Signed-off-by: miigotu <[email protected]>

---------

Signed-off-by: miigotu <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
miigotu and coderabbitai[bot] authored Nov 3, 2023
1 parent 2b1c341 commit f8fd025
Show file tree
Hide file tree
Showing 17 changed files with 492 additions and 544 deletions.
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
396 changes: 146 additions & 250 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
11 changes: 11 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,11 @@ 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))
}
36 changes: 23 additions & 13 deletions sickchill/oldbeard/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,36 @@
]


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]]:
provider_types = List[Union[GenericProvider, TorrentProvider, NZBProvider, TorrentRssProvider]]
initial_list: provider_types = settings.providerList + settings.newznab_provider_list + settings.torrent_rss_provider_list

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

new_provider_list: provider_types = []

# add all modules in the priority list, in order
for current_module in settings.PROVIDER_ORDER:
if current_module in provider_dict:
new_provider_list.append(provider_dict[current_module])
for provider_id in settings.PROVIDER_ORDER:
if provider_id in provider_dict:
new_provider_list.append(provider_dict[provider_id])

# 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:
new_provider_list.append(provider_dict[current_module])
for module in provider_dict.values():
if module not in new_provider_list and module.is_active:
new_provider_list.append(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])
for module in provider_dict.values():
if module not in new_provider_list:
new_provider_list.append(module)

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

if randomize:
shuffle(new_provider_list)
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

0 comments on commit f8fd025

Please sign in to comment.