From e65fa2e76613d255b9548085b4bb10e2613da3da Mon Sep 17 00:00:00 2001 From: mediaminister <45148099+mediaminister@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:28:29 +0200 Subject: [PATCH] Some cleanup (#16) --- .pylintrc | 4 ---- Makefile | 2 +- resources/lib/addon.py | 2 -- resources/lib/goplay/__init__.py | 1 - resources/lib/goplay/auth.py | 6 ++---- resources/lib/goplay/content.py | 8 +++----- resources/lib/kodilogging.py | 2 -- resources/lib/kodiutils.py | 4 +--- resources/lib/modules/catalog.py | 2 -- resources/lib/modules/channels.py | 2 -- resources/lib/modules/menu.py | 2 -- resources/lib/modules/player.py | 2 -- resources/lib/modules/search.py | 2 -- resources/lib/service.py | 2 -- tests/run.py | 8 ++------ tests/test_api.py | 19 ++++++++++++++----- tests/test_auth.py | 6 ++---- tests/test_service.py | 4 ---- 18 files changed, 25 insertions(+), 53 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7fc785a..bc6dc1f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -6,7 +6,6 @@ disable= fixme, import-outside-toplevel, line-too-long, - no-init, old-style-class, too-few-public-methods, too-many-arguments, @@ -16,9 +15,6 @@ disable= too-many-locals, too-many-public-methods, too-many-statements, - use-maxsplit-arg, - consider-using-from-import, - unspecified-encoding, broad-exception-raised, super-with-arguments, # Python 2.7 compatibility raise-missing-from, # Python 2.7 compatibility diff --git a/Makefile b/Makefile index 136b4ad..2c633eb 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ check-translations: check-addon: build @printf ">>> Running addon checks\n" $(eval TMPDIR := $(shell mktemp -d)) - @unzip dist/plugin.video.viervijfzes-*+matrix.1.zip -d ${TMPDIR} + @unzip dist/plugin.video.goplay-*.zip -d ${TMPDIR} cd ${TMPDIR} && kodi-addon-checker --branch=matrix @rm -rf ${TMPDIR} diff --git a/resources/lib/addon.py b/resources/lib/addon.py index 90d98b4..51c022f 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Addon code """ -from __future__ import absolute_import, division, unicode_literals - import logging from routing import Plugin diff --git a/resources/lib/goplay/__init__.py b/resources/lib/goplay/__init__.py index cd3dbb5..c7b1b1d 100644 --- a/resources/lib/goplay/__init__.py +++ b/resources/lib/goplay/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- """ GoPlay API """ -from __future__ import absolute_import, division, unicode_literals STREAM_DICT = { 'codec': 'h264', diff --git a/resources/lib/goplay/auth.py b/resources/lib/goplay/auth.py index f32774e..f09541a 100644 --- a/resources/lib/goplay/auth.py +++ b/resources/lib/goplay/auth.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ AUTH API """ -from __future__ import absolute_import, division, unicode_literals - import json import logging import os @@ -36,7 +34,7 @@ def __init__(self, username, password, token_path): # Load tokens from cache try: - with open(os.path.join(self._token_path, self.TOKEN_FILE), 'r') as fdesc: + with open(os.path.join(self._token_path, self.TOKEN_FILE), 'r', encoding='utf-8') as fdesc: data_json = json.loads(fdesc.read()) self._id_token = data_json.get('id_token') self._refresh_token = data_json.get('refresh_token') @@ -80,7 +78,7 @@ def get_token(self): # Store new tokens in cache if not os.path.exists(self._token_path): os.makedirs(self._token_path) - with open(os.path.join(self._token_path, self.TOKEN_FILE), 'w') as fdesc: + with open(os.path.join(self._token_path, self.TOKEN_FILE), 'w', encoding='utf-8') as fdesc: data = json.dumps({ 'id_token': self._id_token, 'refresh_token': self._refresh_token, diff --git a/resources/lib/goplay/content.py b/resources/lib/goplay/content.py index 411c0da..da1f194 100644 --- a/resources/lib/goplay/content.py +++ b/resources/lib/goplay/content.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -""" AUTH API """ - -from __future__ import absolute_import, division, unicode_literals +""" CONTENT API """ import json import logging @@ -963,7 +961,7 @@ def _get_cache(self, key, allow_expired=False): if not allow_expired and os.stat(fullpath).st_mtime < time.time(): return None - with open(fullpath, 'r') as fdesc: + with open(fullpath, 'r', encoding='utf-8') as fdesc: try: _LOGGER.debug('Fetching %s from cache', filename) value = json.load(fdesc) @@ -979,7 +977,7 @@ def _set_cache(self, key, data, ttl): if not os.path.exists(self._cache_path): os.makedirs(self._cache_path) - with open(fullpath, 'w') as fdesc: + with open(fullpath, 'w', encoding='utf-8') as fdesc: _LOGGER.debug('Storing to cache as %s', filename) json.dump(data, fdesc) diff --git a/resources/lib/kodilogging.py b/resources/lib/kodilogging.py index f4c470d..bc61764 100644 --- a/resources/lib/kodilogging.py +++ b/resources/lib/kodilogging.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """Log handler for Kodi""" -from __future__ import absolute_import, division, unicode_literals - import logging import xbmc diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py index 88c5d7c..c8f917c 100644 --- a/resources/lib/kodiutils.py +++ b/resources/lib/kodiutils.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """All functionality that requires Kodi imports""" -from __future__ import absolute_import, division, unicode_literals - import logging import os import re @@ -155,7 +153,7 @@ def addon_profile(): def url_for(name, *args, **kwargs): """Wrapper for routing.url_for() to lookup by name""" - import resources.lib.addon as addon + from resources.lib import addon return addon.routing.url_for(getattr(addon, name), *args, **kwargs) diff --git a/resources/lib/modules/catalog.py b/resources/lib/modules/catalog.py index 2738795..514493d 100644 --- a/resources/lib/modules/catalog.py +++ b/resources/lib/modules/catalog.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Catalog module """ -from __future__ import absolute_import, division, unicode_literals - import logging from urllib.parse import unquote_plus diff --git a/resources/lib/modules/channels.py b/resources/lib/modules/channels.py index 6712a53..79b231a 100644 --- a/resources/lib/modules/channels.py +++ b/resources/lib/modules/channels.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Channels module """ -from __future__ import absolute_import, division, unicode_literals - import logging from resources.lib import kodiutils diff --git a/resources/lib/modules/menu.py b/resources/lib/modules/menu.py index 6930515..774f63f 100644 --- a/resources/lib/modules/menu.py +++ b/resources/lib/modules/menu.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Menu module """ -from __future__ import absolute_import, division, unicode_literals - import logging from urllib.parse import quote, quote_plus diff --git a/resources/lib/modules/player.py b/resources/lib/modules/player.py index d7ccf4f..576ffd5 100644 --- a/resources/lib/modules/player.py +++ b/resources/lib/modules/player.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Player module """ -from __future__ import absolute_import, division, unicode_literals - import logging from resources.lib import kodiutils diff --git a/resources/lib/modules/search.py b/resources/lib/modules/search.py index 09da8f2..ce15489 100644 --- a/resources/lib/modules/search.py +++ b/resources/lib/modules/search.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Search module """ -from __future__ import absolute_import, division, unicode_literals - import logging from resources.lib import kodiutils diff --git a/resources/lib/service.py b/resources/lib/service.py index 1e1018d..c3cea62 100644 --- a/resources/lib/service.py +++ b/resources/lib/service.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- """ Background service code """ -from __future__ import absolute_import, division, unicode_literals - import hashlib import logging from threading import Event, Thread diff --git a/tests/run.py b/tests/run.py index d082ffc..f542fc9 100755 --- a/tests/run.py +++ b/tests/run.py @@ -2,10 +2,6 @@ # -*- coding: utf-8 -*- """ Run any Kodi plugin:// URL on the commandline """ -# pylint: disable=invalid-name - -from __future__ import absolute_import, division, print_function, unicode_literals - import os import sys @@ -15,12 +11,12 @@ from resources.lib import addon # noqa: E402 pylint: disable=wrong-import-position if len(sys.argv) <= 1: - print("%s: URI argument missing\nTry '%s plugin://plugin.video.viervijfzes/' to test." % (sys.argv[0], sys.argv[0])) + print("%s: URI argument missing\nTry '%s plugin://plugin.video.goplay/' to test." % (sys.argv[0], sys.argv[0])) sys.exit(1) # Also support bare paths like /recent/2 if not sys.argv[1].startswith('plugin://'): - sys.argv[1] = 'plugin://plugin.video.viervijfzes' + sys.argv[1] + sys.argv[1] = 'plugin://plugin.video.goplay' + sys.argv[1] # Split path and args try: diff --git a/tests/test_api.py b/tests/test_api.py index 2af1773..8724477 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- """ Tests for Content API """ -# pylint: disable=missing-docstring,no-self-use - -from __future__ import absolute_import, division, print_function, unicode_literals - import logging import unittest -import resources.lib.kodiutils as kodiutils +from resources.lib import kodiutils from resources.lib.goplay import ResolvedStream from resources.lib.goplay.auth import AuthApi from resources.lib.goplay.content import ContentApi, GeoblockedException, Program, CACHE_PREVENT, Category @@ -17,21 +13,25 @@ class TestApi(unittest.TestCase): + """ Tests for Content Api """ def __init__(self, *args, **kwargs): super(TestApi, self).__init__(*args, **kwargs) auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) self._api = ContentApi(auth, cache_path=kodiutils.get_cache_path()) def test_programs(self): + """ Test getting programs""" programs = self._api.get_programs() self.assertIsInstance(programs, list) self.assertIsInstance(programs[0], Program) def test_recommendations(self): + """ Test getting recommendation categories """ categories = self._api.get_categories() self.assertIsInstance(categories, list) def test_categories(self): + """ Test getting categories """ categories = self._api.get_categories() self.assertIsInstance(categories, list) self.assertIsInstance(categories[0], Category) @@ -41,6 +41,7 @@ def test_categories(self): self.assertIsInstance(programs[0], Program) def test_episodes(self): + """ Test getting program season episodes """ for program in ['20cdf366-f7ac-4bf8-995a-2af53c89655d', '2e0768da-29b0-4945-821b-f76395f26876']: # Nonkels, Kiekenkotkwis program = self._api.get_program(program, cache=CACHE_PREVENT) self.assertIsInstance(program, Program) @@ -48,6 +49,7 @@ def test_episodes(self): @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_get_stream(self): + """ Test getting resolved stream """ try: program = self._api.get_program('20cdf366-f7ac-4bf8-995a-2af53c89655d') # Nonkels self.assertIsInstance(program, Program) @@ -59,6 +61,7 @@ def test_get_stream(self): @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_get_drm_stream(self): + """ Test getting DRM protected resolved stream """ try: program = self._api.get_program('022bd8fe-793e-4635-85da-4259d44950a3') # CSI Vegas self.assertIsInstance(program, Program) @@ -70,6 +73,7 @@ def test_get_drm_stream(self): @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_get_mylist(self): + """ Test getting favorite programs list """ my_list = self._api.get_mylist() self.assertIsInstance(my_list, list) if len(my_list) > 0: @@ -77,22 +81,27 @@ def test_get_mylist(self): @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_mylist_add(self): + """ Test adding a program to favorite programs list """ self._api.mylist_add('706542fa-dec9-4675-9b7c-b317720e8bd0') # Callboys @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_mylist_del(self): + """ Test removing a program from favorite programs list """ self._api.mylist_del('706542fa-dec9-4675-9b7c-b317720e8bd0') # Callboys def test_search(self): + """ Test searching for a program """ _, programs = self._api.search('de mol') self.assertIsInstance(programs, list) self.assertIsInstance(programs[0], Program) def test_search_empty(self): + """ Test searching with empty query """ _, programs = self._api.search('') self.assertIsInstance(programs, list) def test_search_space(self): + """ Test searching with space query """ _, programs = self._api.search(' ') self.assertIsInstance(programs, list) diff --git a/tests/test_auth.py b/tests/test_auth.py index 9d1f946..369ea4e 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- """ Tests for AUTH API """ -# pylint: disable=missing-docstring,no-self-use - -from __future__ import absolute_import, division, print_function, unicode_literals - import logging import unittest @@ -15,11 +11,13 @@ class TestAuth(unittest.TestCase): + """Tests for authentication """ def __init__(self, *args, **kwargs): super(TestAuth, self).__init__(*args, **kwargs) @unittest.skipUnless(kodiutils.get_setting('username') and kodiutils.get_setting('password'), 'Skipping since we have no credentials.') def test_login(self): + """ Test login procedure """ auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) # Clear any cache we have diff --git a/tests/test_service.py b/tests/test_service.py index 664fb5a..4a1467c 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- """ Tests for background service """ -# pylint: disable=invalid-name,missing-docstring - -from __future__ import absolute_import, division, print_function, unicode_literals - import os import signal import sys