Skip to content

Commit

Permalink
Fix CI (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Sep 16, 2024
1 parent d1e042e commit cabc420
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
if: contains(matrix.os, 'windows')
run: echo "PYTHONPATH=${env:PYTHONPATH};${env:GITHUB_WORKSPACE};${env:GITHUB_WORKSPACE}\resources\lib;${env:GITHUB_WORKSPACE}\tests" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf-8 -Append
- name: 'Set up Python ${{ matrix.python-version }}'
uses: actions/setup-python@v5
uses: MatteoH2O1999/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies (linux)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
push:
schedule:
- cron: '0/30 * * * *'
- cron: '*/30 * * * *'
jobs:
tests:
name: Checks
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ experiment/
nohup.out

# Userdata
tests/userdata/backup/
tests/cdm/
tests/userdata/cache/
tests/userdata/credentials.json
Expand Down
57 changes: 53 additions & 4 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,13 @@ def convert_episode(item, destination=None):
program_type = episode.get('program').get('programType')

# FIXME: Find a better way to determine mixed episodes
if destination in ('recent', 'favorites_recent', 'resumepoints_continue', 'featured'):
if destination in ('recent', 'favorites_recent', 'resumepoints_continue', 'featured', 'search_query'):
program_type = 'mixed_episodes'

episode_title = episode.get('title')
offtime = dateutil.parser.parse(episode.get('offTimeRaw'))
ontime = dateutil.parser.parse(episode.get('onTimeRaw'))

offtime = dateutil.parser.parse(episode.get('offTimeRaw') or '1970-01-01T00:00:00.000+00:00')
ontime = dateutil.parser.parse(episode.get('onTimeRaw') or '1970-01-01T00:00:00.000+00:00')
mpaa = episode.get('ageRaw') or ''
product_placement = episode.get('productPlacementShortValue') == 'pp'
region = episode.get('regionRaw')
Expand Down Expand Up @@ -1008,6 +1009,54 @@ def get_favorite_programs(end_cursor=''):
return programs


def get_search(keywords, end_cursor=''):
"""Get search items"""
import base64
from json import dumps
page_size = get_setting_int('itemsperpage', default=50)
query_string = None
destination = None

entity_types = ['video-program', 'video-episode']
programs = []
episodes = []
items = []

for entity_type in entity_types:
facets = []
if keywords:
destination = 'search_query'
query_string = keywords
facets.append({
'name': 'entitytype',
'values': [entity_type],
})
if entity_type == 'video-program':
result_type = 'watch'
else:
result_type = entity_type
search_dict = {
'facets': facets,
'resultType': result_type,
}
if query_string:
search_dict['q'] = query_string
encoded_search = base64.b64encode(dumps(search_dict).encode('utf-8'))

list_id = 'tl-pag-srch|{}#{}'.format(result_type, encoded_search.decode('utf-8'))
list_id = '#{}'.format(base64.b64encode(list_id.encode('utf-8')).decode('utf-8'))

if entity_type == 'video-program' and not end_cursor:
programs_data = get_paginated_programs(list_id=list_id, page_size=page_size, end_cursor=end_cursor)
programs = convert_programs(programs_data, destination=destination, keywords=keywords)
items.extend(programs)
elif entity_type == 'video-episode':
episodes_data = get_paginated_episodes(list_id=list_id, page_size=page_size, end_cursor=end_cursor)
episodes, _, _ = convert_episodes(episodes_data, destination=destination, keywords=keywords)
items.extend(episodes)
return items


def get_programs(category=None, channel=None, keywords=None, end_cursor=''):
"""Get programs"""
import base64
Expand Down Expand Up @@ -1046,7 +1095,7 @@ def get_programs(category=None, channel=None, keywords=None, end_cursor=''):
if query_string:
search_dict['q'] = query_string
encoded_search = base64.b64encode(dumps(search_dict).encode('utf-8'))
list_id = 'tl-pag-srch|watch#{}'.format(encoded_search.decode('utf-8'))
list_id = 'tl-pag-srch|{}#{}'.format('watch', encoded_search.decode('utf-8'))
list_id = '#{}'.format(base64.b64encode(list_id.encode('utf-8')).decode('utf-8'))

api_data = get_paginated_programs(list_id=list_id, page_size=page_size, end_cursor=end_cursor)
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
get_search_string, input_down, localize, ok_dialog, open_file,
show_listing, url_for)
from resumepoints import ResumePoints
from api import get_programs
from api import get_search


class Search:
Expand Down Expand Up @@ -85,7 +85,7 @@ def search(self, keywords=None, end_cursor='', edit=False):

self.add(keywords)

search_items = get_programs(keywords=keywords, end_cursor=end_cursor)
search_items = get_search(keywords=keywords, end_cursor=end_cursor)
if not search_items:
ok_dialog(heading=localize(30135), message=localize(30136, keywords=keywords))
end_of_directory()
Expand Down
11 changes: 11 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""Add paths for unittest"""
from __future__ import absolute_import, division, unicode_literals

import os
import sys
PROJECT_PATH = os.getcwd()
SOURCE_PATH = os.path.join(PROJECT_PATH, 'resources/lib')
TESTS_PATH = os.path.join(PROJECT_PATH, 'tests')
sys.path.append(SOURCE_PATH)
sys.path.append(TESTS_PATH)
13 changes: 7 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from api import (get_episodes, get_favorite_programs, get_latest_episode, get_next_info, get_online_categories,
get_offline_programs, get_programs, get_recent_episodes, get_single_episode, valid_categories)
get_offline_programs, get_programs, get_recent_episodes, get_search, get_single_episode, valid_categories)
from data import CATEGORIES
from xbmcextra import kodi_to_ansi

Expand Down Expand Up @@ -46,8 +46,8 @@ def test_get_api_data_specific_season(self):
"""Test listing episodes for a specific season (pano)"""
title_items, sort, ascending, content = get_episodes(program_name='pano', season_name='2020')
self.assertEqual(len(title_items), 15)
self.assertEqual(sort, 'episode')
self.assertTrue(ascending)
self.assertEqual(sort, 'dateadded') # Pano has 'daily' programType
self.assertFalse(ascending)
self.assertEqual(content, 'episodes')

def test_get_api_data_specific_season_without_broadcastdate(self):
Expand Down Expand Up @@ -91,7 +91,8 @@ def test_get_programs_channel(self):
def test_get_programs_keywords(self):
"""Test get programs using keywords"""
keywords = 'kaas'
program_items = get_programs(keywords=keywords)
program_items = get_search(keywords=keywords)
print(len(program_items))
self.assertTrue(program_items)

def test_get_favorite_programs(self):
Expand All @@ -109,8 +110,8 @@ def test_get_latest_episode(self):
def test_episode_plot(self):
"""Test getting an episode plot (thuis)"""
title_items, sort, ascending, content = get_episodes(program_name='thuis', season_name='28')
self.assertEqual(sort, 'episode')
self.assertTrue(ascending)
self.assertEqual(sort, 'dateadded') # Thuis has 'daily' programType
self.assertFalse(ascending)
self.assertEqual(content, 'episodes')
plot = title_items[0].info_dict['plot']
print(kodi_to_ansi(plot))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_streamservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_get_ondemand_stream_from_from_videoid_geoblocked(self):

@unittest.skipUnless(addon.settings.get('username'), 'Skipping as VRT username is missing.')
@unittest.skipUnless(addon.settings.get('password'), 'Skipping as VRT password is missing.')
def test_get_mpd_live_stream_from_url_does_not_crash_returns_stream_and_licensekey(self):
def test_get_mpd_live_stream_from_url_does_not_crash_returns_stream(self):
"""Test getting MPEG-DASH stream from URL"""
addon.settings['usedrm'] = True
addon.settings['useinputstreamadaptive'] = True
Expand All @@ -111,7 +111,7 @@ def test_get_mpd_live_stream_from_url_does_not_crash_returns_stream_and_licensek
# NOTE: Testing live streams only works within Europe
if os.environ.get('GITHUB_ACTIONS') != 'true':
self.assertTrue(stream is not None)
self.assertTrue(stream.license_key is not None)
self.assertTrue(stream.license_headers is not None)

@unittest.skipUnless(addon.settings.get('username'), 'Skipping as VRT username is missing.')
@unittest.skipUnless(addon.settings.get('password'), 'Skipping as VRT password is missing.')
Expand Down
9 changes: 0 additions & 9 deletions tests/userdata/backup/4.10.2449.0/LICENSE.txt

This file was deleted.

Binary file removed tests/userdata/backup/4.10.2449.0/libwidevinecdm.so
Binary file not shown.
13 changes: 0 additions & 13 deletions tests/userdata/backup/4.10.2449.0/manifest.json

This file was deleted.

0 comments on commit cabc420

Please sign in to comment.