Add support for Python 3.9 (#60)
This commit is contained in:
parent
f7f90ac400
commit
415a239d82
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
|
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
|
||||||
steps:
|
steps:
|
||||||
- name: Check out ${{ github.sha }} from repository ${{ github.repository }}
|
- name: Check out ${{ github.sha }} from repository ${{ github.repository }}
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -11,11 +11,17 @@ import time
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from six.moves.html_parser import HTMLParser # pylint: disable=wrong-import-order
|
|
||||||
|
|
||||||
from resources.lib.kodiutils import STREAM_DASH, STREAM_HLS
|
from resources.lib.kodiutils import STREAM_DASH, STREAM_HLS
|
||||||
from resources.lib.viervijfzes import CHANNELS, ResolvedStream
|
from resources.lib.viervijfzes import CHANNELS, ResolvedStream
|
||||||
|
|
||||||
|
try: # Python 3
|
||||||
|
from html import unescape
|
||||||
|
except ImportError: # Python 2
|
||||||
|
from HTMLParser import HTMLParser
|
||||||
|
|
||||||
|
unescape = HTMLParser().unescape
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CACHE_AUTO = 1 # Allow to use the cache, and query the API if no cache is available
|
CACHE_AUTO = 1 # Allow to use the cache, and query the API if no cache is available
|
||||||
@ -193,12 +199,11 @@ class ContentApi:
|
|||||||
raw_html = self._get_url(CHANNELS[channel]['url'])
|
raw_html = self._get_url(CHANNELS[channel]['url'])
|
||||||
|
|
||||||
# Parse programs
|
# Parse programs
|
||||||
parser = HTMLParser()
|
|
||||||
regex_programs = re.compile(r'<a class="program-overview__link" href="(?P<path>[^"]+)">\s+'
|
regex_programs = re.compile(r'<a class="program-overview__link" href="(?P<path>[^"]+)">\s+'
|
||||||
r'<span class="program-overview__title">\s+(?P<title>[^<]+)</span>.*?'
|
r'<span class="program-overview__title">\s+(?P<title>[^<]+)</span>.*?'
|
||||||
r'</a>', re.DOTALL)
|
r'</a>', re.DOTALL)
|
||||||
data = {
|
data = {
|
||||||
item.group('path').lstrip('/'): parser.unescape(item.group('title').strip())
|
item.group('path').lstrip('/'): unescape(item.group('title').strip())
|
||||||
for item in regex_programs.finditer(raw_html)
|
for item in regex_programs.finditer(raw_html)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +256,7 @@ class ContentApi:
|
|||||||
|
|
||||||
# Extract JSON
|
# Extract JSON
|
||||||
regex_program = re.compile(r'data-hero="([^"]+)', re.DOTALL)
|
regex_program = re.compile(r'data-hero="([^"]+)', re.DOTALL)
|
||||||
json_data = HTMLParser().unescape(regex_program.search(page).group(1))
|
json_data = unescape(regex_program.search(page).group(1))
|
||||||
data = json.loads(json_data)['data']
|
data = json.loads(json_data)['data']
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -285,7 +290,6 @@ class ContentApi:
|
|||||||
# Load webpage
|
# Load webpage
|
||||||
page = self._get_url(CHANNELS[channel]['url'] + '/' + path)
|
page = self._get_url(CHANNELS[channel]['url'] + '/' + path)
|
||||||
|
|
||||||
parser = HTMLParser()
|
|
||||||
program_json = None
|
program_json = None
|
||||||
episode_json = None
|
episode_json = None
|
||||||
|
|
||||||
@ -294,7 +298,7 @@ class ContentApi:
|
|||||||
regex_video_data = re.compile(r'data-video="([^"]+)"', re.DOTALL)
|
regex_video_data = re.compile(r'data-video="([^"]+)"', re.DOTALL)
|
||||||
result = regex_video_data.search(page)
|
result = regex_video_data.search(page)
|
||||||
if result:
|
if result:
|
||||||
video_id = json.loads(parser.unescape(result.group(1)))['id']
|
video_id = json.loads(unescape(result.group(1)))['id']
|
||||||
video_json_data = self._get_url('%s/video/%s' % (self.SITE_APIS[channel], video_id))
|
video_json_data = self._get_url('%s/video/%s' % (self.SITE_APIS[channel], video_id))
|
||||||
video_json = json.loads(video_json_data)
|
video_json = json.loads(video_json_data)
|
||||||
return dict(video=video_json)
|
return dict(video=video_json)
|
||||||
@ -303,14 +307,14 @@ class ContentApi:
|
|||||||
regex_program = re.compile(r'data-hero="([^"]+)', re.DOTALL)
|
regex_program = re.compile(r'data-hero="([^"]+)', re.DOTALL)
|
||||||
result = regex_program.search(page)
|
result = regex_program.search(page)
|
||||||
if result:
|
if result:
|
||||||
program_json_data = parser.unescape(result.group(1))
|
program_json_data = unescape(result.group(1))
|
||||||
program_json = json.loads(program_json_data)['data']
|
program_json = json.loads(program_json_data)['data']
|
||||||
|
|
||||||
# Extract episode JSON
|
# Extract episode JSON
|
||||||
regex_episode = re.compile(r'<script type="application/json" data-drupal-selector="drupal-settings-json">(.*?)</script>', re.DOTALL)
|
regex_episode = re.compile(r'<script type="application/json" data-drupal-selector="drupal-settings-json">(.*?)</script>', re.DOTALL)
|
||||||
result = regex_episode.search(page)
|
result = regex_episode.search(page)
|
||||||
if result:
|
if result:
|
||||||
episode_json_data = parser.unescape(result.group(1))
|
episode_json_data = unescape(result.group(1))
|
||||||
episode_json = json.loads(episode_json_data)
|
episode_json = json.loads(episode_json_data)
|
||||||
|
|
||||||
return dict(program=program_json, episode=episode_json)
|
return dict(program=program_json, episode=episode_json)
|
||||||
@ -404,8 +408,6 @@ class ContentApi:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_programs(html, channel):
|
def _extract_programs(html, channel):
|
||||||
""" Extract Programs from HTML code """
|
""" Extract Programs from HTML code """
|
||||||
parser = HTMLParser()
|
|
||||||
|
|
||||||
# Item regexes
|
# Item regexes
|
||||||
regex_item = re.compile(r'<a[^>]+?href="(?P<path>[^"]+)"[^>]+?>'
|
regex_item = re.compile(r'<a[^>]+?href="(?P<path>[^"]+)"[^>]+?>'
|
||||||
r'.*?<h3 class="poster-teaser__title"><span>(?P<title>[^<]*)</span></h3>.*?'
|
r'.*?<h3 class="poster-teaser__title"><span>(?P<title>[^<]*)</span></h3>.*?'
|
||||||
@ -418,7 +420,7 @@ class ContentApi:
|
|||||||
if path.startswith('/video'):
|
if path.startswith('/video'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
title = parser.unescape(item.group('title'))
|
title = unescape(item.group('title'))
|
||||||
|
|
||||||
# Program
|
# Program
|
||||||
programs.append(Program(
|
programs.append(Program(
|
||||||
@ -432,8 +434,6 @@ class ContentApi:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_videos(html, channel):
|
def _extract_videos(html, channel):
|
||||||
""" Extract videos from HTML code """
|
""" Extract videos from HTML code """
|
||||||
parser = HTMLParser()
|
|
||||||
|
|
||||||
# Item regexes
|
# Item regexes
|
||||||
regex_item = re.compile(r'<a[^>]+?href="(?P<path>[^"]+)"[^>]+?>.*?</a>', re.DOTALL)
|
regex_item = re.compile(r'<a[^>]+?href="(?P<path>[^"]+)"[^>]+?>.*?</a>', re.DOTALL)
|
||||||
|
|
||||||
@ -453,7 +453,7 @@ class ContentApi:
|
|||||||
|
|
||||||
# Extract title
|
# Extract title
|
||||||
try:
|
try:
|
||||||
title = parser.unescape(regex_episode_title.search(item_html).group(1))
|
title = unescape(regex_episode_title.search(item_html).group(1))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ class ContentApi:
|
|||||||
_LOGGER.warning('Found no episode_video_id for %s', title)
|
_LOGGER.warning('Found no episode_video_id for %s', title)
|
||||||
episode_video_id = None
|
episode_video_id = None
|
||||||
try:
|
try:
|
||||||
episode_image = parser.unescape(regex_episode_image.search(item_html).group(1))
|
episode_image = unescape(regex_episode_image.search(item_html).group(1))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
_LOGGER.warning('Found no episode_image for %s', title)
|
_LOGGER.warning('Found no episode_image for %s', title)
|
||||||
episode_image = None
|
episode_image = None
|
||||||
|
Loading…
Reference in New Issue
Block a user