Skip to content

Commit

Permalink
Some cleanup (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Oct 22, 2024
1 parent f7668e7 commit e65fa2e
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 53 deletions.
4 changes: 0 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ disable=
fixme,
import-outside-toplevel,
line-too-long,
no-init,
old-style-class,
too-few-public-methods,
too-many-arguments,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 0 additions & 2 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
""" Addon code """

from __future__ import absolute_import, division, unicode_literals

import logging

from routing import Plugin
Expand Down
1 change: 0 additions & 1 deletion resources/lib/goplay/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
""" GoPlay API """
from __future__ import absolute_import, division, unicode_literals

STREAM_DICT = {
'codec': 'h264',
Expand Down
6 changes: 2 additions & 4 deletions resources/lib/goplay/auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
""" AUTH API """

from __future__ import absolute_import, division, unicode_literals

import json
import logging
import os
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions resources/lib/goplay/content.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
""" AUTH API """

from __future__ import absolute_import, division, unicode_literals
""" CONTENT API """

import json
import logging
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions resources/lib/kodilogging.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
"""Log handler for Kodi"""

from __future__ import absolute_import, division, unicode_literals

import logging

import xbmc
Expand Down
4 changes: 1 addition & 3 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)


Expand Down
2 changes: 0 additions & 2 deletions resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions resources/lib/modules/channels.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
""" Channels module """

from __future__ import absolute_import, division, unicode_literals

import logging

from resources.lib import kodiutils
Expand Down
2 changes: 0 additions & 2 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions resources/lib/modules/player.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
""" Player module """

from __future__ import absolute_import, division, unicode_literals

import logging

from resources.lib import kodiutils
Expand Down
2 changes: 0 additions & 2 deletions resources/lib/modules/search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
""" Search module """

from __future__ import absolute_import, division, unicode_literals

import logging

from resources.lib import kodiutils
Expand Down
2 changes: 0 additions & 2 deletions resources/lib/service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 2 additions & 6 deletions tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
19 changes: 14 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -41,13 +41,15 @@ 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)
self.assertIsInstance(program.seasons, dict)

@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)
Expand All @@ -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)
Expand All @@ -70,29 +73,35 @@ 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:
self.assertIsInstance(my_list[0], Program)

@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)

Expand Down
6 changes: 2 additions & 4 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tests/test_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e65fa2e

Please sign in to comment.