Skip to content

Commit

Permalink
Merge pull request s0faking#140 from Rechi/pylint
Browse files Browse the repository at this point in the history
pylint: fix reports & add workflow
  • Loading branch information
s0faking authored Jun 9, 2024
2 parents 2fd01c4 + 8b5e1dd commit bdc939b
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 72 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ jobs:
- name: Fail if autopep8 made changes
if: steps.autopep8.outputs.exit-code == 2
run: exit 1

pylint:
runs-on: ubuntu-latest
name: pylint
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Run pylint
id: pylint
run: pylint resources/lib
45 changes: 45 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[MAIN]

# Add paths to the list of the source roots. Supports globbing patterns. The
# source root is an absolute path or a path relative to the current working
# directory used to determine a package namespace for modules located under the
# source root.
source-roots=resources/lib


[FORMAT]

# Maximum number of characters on a single line.
max-line-length=173


[MESSAGES CONTROL]

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=
consider-using-f-string,
consider-using-with,
dangerous-default-value,
import-error,
inconsistent-return-statements,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-locals,
too-many-nested-blocks,
too-many-public-methods,
too-many-return-statements,
too-many-statements,
unspecified-encoding,
use-implicit-booleaness-not-len,
36 changes: 20 additions & 16 deletions resources/lib/Addon.py → resources/lib/addon.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import re
import sys

from Kodi import *
import routing

settings_file = 'settings.json'
channel_map_file = 'channels.json'
search_history_file = 'search_history'
from directory import Directory
from kodi import Kodi
from orf_on import OrfOn

SETTINGS_FILE = 'settings.json'
CHANNEL_MAP_FILE = 'channels.json'
SEARCH_HISTORY_FILE = 'search_history'

route_plugin = routing.Plugin()
kodi_worker = Kodi(route_plugin)
if not sys.argv[0].startswith('plugin://' + kodi_worker.addon_id + '/dialog'):
channel_map, channel_map_cached = kodi_worker.get_cached_file(channel_map_file)
settings, settings_cached = kodi_worker.get_cached_file(settings_file)
channel_map, channel_map_cached = kodi_worker.get_cached_file(CHANNEL_MAP_FILE)
settings, settings_cached = kodi_worker.get_cached_file(SETTINGS_FILE)
api = OrfOn(channel_map=channel_map, settings=settings, useragent=kodi_worker.useragent, kodi_worker=kodi_worker)
api.set_pager_limit(kodi_worker.pager_limit)
api.set_segments_behaviour(kodi_worker.use_segments)
Expand All @@ -22,10 +26,10 @@

# Only overwrite if cache was invalidated
if not channel_map_cached:
kodi_worker.save_json(channel_map, channel_map_file)
kodi_worker.save_json(channel_map, CHANNEL_MAP_FILE)

if not settings_cached:
kodi_worker.save_json(settings, settings_file)
kodi_worker.save_json(settings, SETTINGS_FILE)


@route_plugin.route('/')
Expand Down Expand Up @@ -195,7 +199,7 @@ def get_search():
search_link = '/search/query'
search_dir = Directory(kodi_worker.get_translation(30131, 'Enter search ...', '%s ...'), "", search_link, translator=kodi_worker)
kodi_worker.render(search_dir)
directories = kodi_worker.get_stored_directories(search_history_file)
directories = kodi_worker.get_stored_directories(SEARCH_HISTORY_FILE)
for directory in directories:
kodi_worker.render(directory)
kodi_worker.list_callback()
Expand Down Expand Up @@ -237,7 +241,7 @@ def get_search_dialog():
def clear_search_history():
dialog = kodi_worker.get_progress_dialog(kodi_worker.get_translation(30132, 'Clearing search history'))
dialog.update(0, kodi_worker.get_translation(30133, 'Clearing ...', '%s ...'))
kodi_worker.clear_stored_directories(search_history_file)
kodi_worker.clear_stored_directories(SEARCH_HISTORY_FILE)
dialog.update(100, kodi_worker.get_translation(30134, 'Done'))
dialog.close()

Expand All @@ -247,19 +251,19 @@ def clear_cache():
dialog = kodi_worker.get_progress_dialog('Reloading cache')
dialog.update(0, kodi_worker.get_translation(30136, 'Reloading cache ...', '%s ...'))
kodi_worker.log("Reloading channel/settings cache", 'route')
tmp_channel_map, tmp_channel_map_cached = kodi_worker.get_cached_file(channel_map_file)
tmp_settings, tmp_settings_cached = kodi_worker.get_cached_file(settings_file)
kodi_worker.remove_file(settings_file)
kodi_worker.remove_file(channel_map_file)
tmp_channel_map, _ = kodi_worker.get_cached_file(CHANNEL_MAP_FILE)
tmp_settings, _ = kodi_worker.get_cached_file(SETTINGS_FILE)
kodi_worker.remove_file(SETTINGS_FILE)
kodi_worker.remove_file(CHANNEL_MAP_FILE)
tmp_api = OrfOn(channel_map=tmp_channel_map, settings=tmp_settings, useragent=kodi_worker.useragent, kodi_worker=kodi_worker)
tmp_api.channel_map = False
tmp_api.settings = False
dialog.update(33, kodi_worker.get_translation(30137, 'Loading channels'))
tmp_channel_map = tmp_api.get_channel_map()
kodi_worker.save_json(tmp_channel_map, channel_map_file)
kodi_worker.save_json(tmp_channel_map, CHANNEL_MAP_FILE)
dialog.update(66, kodi_worker.get_translation(30138, 'Loading settings'))
tmp_settings = tmp_api.get_settings()
kodi_worker.save_json(tmp_settings, settings_file)
kodi_worker.save_json(tmp_settings, SETTINGS_FILE)
dialog.update(100, kodi_worker.get_translation(30134, 'Done'))
dialog.close()

Expand Down
4 changes: 2 additions & 2 deletions resources/lib/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import Addon
import addon

Addon.run()
addon.run()
22 changes: 11 additions & 11 deletions resources/lib/Directory.py → resources/lib/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Directory:
def __init__(self, title, description, link, content_id="", content_type="", thumbnail="", backdrop="", poster="", source={}, translator=None, proxy=False):
def __init__(self, title, description, link, content_id="", content_type="", thumbnail="", backdrop="", poster="", source={}, translator=None):
self.translator = translator
self.title = title
if description:
Expand Down Expand Up @@ -70,8 +70,8 @@ def get_context_menu(self) -> list:
def translate_string(self, translation_id, fallback, replace=None):
if self.translator:
return self.translator.get_translation(translation_id, fallback, replace)
else:
return fallback

return fallback

@staticmethod
def build_meta(item) -> dict:
Expand Down Expand Up @@ -245,8 +245,8 @@ def get_channel_logo(self):
def get_resolution(self):
if self.meta.get('uhd'):
return 3840, 2160
else:
return 1280, 720

return 1280, 720

def set_stream(self, sources):
self.videos = sources
Expand All @@ -266,8 +266,8 @@ def time(self):
def get_description(self) -> str:
if self.description is not None:
return self.description
else:
return ""

return ""

def get_meta_description(self):
meta_description = {}
Expand Down Expand Up @@ -353,7 +353,7 @@ def get_cast(self):
try:
if part is not None and len(part) > 1:
matches = re.findall(cast_extract_pattern, part[1], re.DOTALL)
for name, dirty_role, role in matches:
for name, _, role in matches:
if name.strip() != "":
if '\r\n' in name.strip() or 'Regie:' in name.strip():
break
Expand All @@ -362,7 +362,7 @@ def get_cast(self):
else:
cast.append(name.strip())
return cast
except re.error as e:
except re.error:
return cast

def url(self) -> str:
Expand Down Expand Up @@ -414,8 +414,8 @@ def debug(self):
self.log('Thumbnail: %s' % self.thumbnail)
self.log('Backdrop: %s' % self.backdrop)
self.log('Poster: %s' % self.poster)
for item in self.meta:
self.log("%s: %s" % (item.capitalize().replace("_", " "), self.meta[item]))
for (key, value) in self.meta.items():
self.log("%s: %s" % (key.capitalize().replace("_", " "), value))

for context_menu_item in self.context_menu:
self.log('Context Menu Item: %s' % context_menu_item.get('title'))
Expand Down
31 changes: 14 additions & 17 deletions resources/lib/Kodi.py → resources/lib/kodi.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import json
import os
import re
import sys
import time
from urllib.parse import unquote

import xbmcaddon
from xbmc import PlayList, PLAYLIST_VIDEO, Player, Keyboard, executebuiltin, log, LOGDEBUG
from xbmcgui import ListItem, Dialog, DialogProgress
from xbmcaddon import Addon
from xbmcplugin import addDirectoryItem, endOfDirectory, setContent, setResolvedUrl, addSortMethod, SORT_METHOD_VIDEO_TITLE, SORT_METHOD_DATE
import xbmcvfs
import sys
import os
import time
import inputstreamhelper
from urllib.parse import unquote

try:
from OrfOn import *
except ModuleNotFoundError:
from resources.lib.OrfOn import *
from directory import Directory


class Kodi:
Expand Down Expand Up @@ -58,8 +58,8 @@ def get_translation(self, translation_id, fallback, replace=None):
if translation:
if replace is not None:
return replace % translation
else:
return translation

return translation
return fallback

def is_geo_locked(self) -> bool:
Expand Down Expand Up @@ -95,10 +95,7 @@ def render(self, item):
list_item = self.render_video(item)
link = item.url()
route = self.plugin.url_for_path(link)
if self.use_segments and self.show_segments and item.has_segments():
folder = True
else:
folder = False
folder = self.use_segments and self.show_segments and item.has_segments()
addDirectoryItem(self.plugin.handle, url=route, listitem=list_item, isFolder=folder)
else:
list_item = self.render_directory(item)
Expand Down Expand Up @@ -219,7 +216,7 @@ def render_video(self, teaser) -> ListItem:
context_menu.append(self.build_context_menu(context_menu_item))
list_item.addContextMenuItems(context_menu, replaceItems=True)
return list_item
elif not teaser.get_stream():
if not teaser.get_stream():
Dialog().notification('No Stream available', 'Unable to find a stream for %s' % title, xbmcaddon.Addon().getAddonInfo('icon'))
elif not is_helper.check_inputstream():
Dialog().notification('Inputstream Adaptive not available', 'Install Inputstream Adaptive and Inputstream Helper', xbmcaddon.Addon().getAddonInfo('icon'))
Expand Down Expand Up @@ -259,8 +256,8 @@ def build_context_menu(self, item):
route = self.plugin.url_for_path(item.get('url'))
if item.get('type') == 'run':
return item.get('title'), 'RunPlugin(%s)' % route
else:
return item.get('title'), 'Container.Update(%s)' % route

return item.get('title'), 'Container.Update(%s)' % route

def list_callback(self, content_type="movies", sort=False) -> None:
if content_type:
Expand Down
Loading

0 comments on commit bdc939b

Please sign in to comment.