-
Notifications
You must be signed in to change notification settings - Fork 20
/
vrtplayer.py
126 lines (109 loc) · 6.82 KB
/
vrtplayer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
# GNU General Public License v2.0 (see COPYING or https://www.gnu.org/licenses/gpl-2.0.txt)
import requests
from bs4 import BeautifulSoup, SoupStrainer
from resources.lib.helperobjects import helperobjects
from resources.lib.kodiwrappers import sortmethod
from resources.lib.vrtplayer import actions, statichelper
class VRTPlayer:
# URLs van https://services.vrt.be/videoplayer/r/live.json
_EEN_LIVESTREAM = 'https://www.vrt.be/vrtnu/kanalen/een/'
_CANVAS_LIVESTREAM = 'https://www.vrt.be/vrtnu/kanalen/canvas/'
_KETNET_LIVESTREAM = 'https://www.vrt.be/vrtnu/kanalen/ketnet/'
VRT_BASE = 'https://www.vrt.be/'
VRTNU_BASE_URL = ''.join((VRT_BASE, '/vrtnu'))
def __init__(self, kodi_wrapper, stream_service, api_helper):
self._kodi_wrapper = kodi_wrapper
self._api_helper = api_helper
self._stream_service = stream_service
def show_main_menu_items(self):
menu_items = [
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32080),
dict(action=actions.LISTING_AZ_TVSHOWS),
is_playable=False,
thumb='DefaultMovieTitle.png',
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32081)),
icon='DefaultMovieTitle.png'),
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32082),
dict(action=actions.LISTING_CATEGORIES),
is_playable=False,
thumbnail='DefaultGenre.png',
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32083)),
icon='DefaultGenre.png'),
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32084),
dict(action=actions.LISTING_LIVE),
is_playable=False,
thumbnail='DefaultAddonPVRClient.png',
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32085)),
icon='DefaultAddonPVRClient.png'),
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32086),
dict(action=actions.LISTING_EPISODES, video_url='recent'),
is_playable=False,
thumbnail='DefaultYear.png',
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32087)),
icon='DefaultYear.png'),
]
self._kodi_wrapper.show_listing(menu_items, content_type='files')
def show_tvshow_menu_items(self, path):
menu_items = self._api_helper.get_tvshow_items(path)
self._kodi_wrapper.show_listing(menu_items, sortmethod.ALPHABET, content_type='tvshows')
def show_category_menu_items(self):
joined_url = ''.join((self.VRTNU_BASE_URL, '/categorieen/'))
menu_items = self.__get_category_menu_items(joined_url, {'class': 'nui-tile title'}, actions.LISTING_CATEGORY_TVSHOWS)
self._kodi_wrapper.show_listing(menu_items, sort=sortmethod.ALPHABET, content_type='files')
def play(self, video):
stream = self._stream_service.get_stream(video)
if stream is not None:
self._kodi_wrapper.play(stream)
def show_livestream_items(self):
livestream_items = [
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32101),
dict(action=actions.PLAY, video_url=self._EEN_LIVESTREAM),
is_playable=True,
thumbnail=self._api_helper.get_live_screenshot('een'),
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32101)),
icon='DefaultAddonPVRClient.png'),
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32102),
dict(action=actions.PLAY, video_url=self._CANVAS_LIVESTREAM),
is_playable=True,
thumbnail=self._api_helper.get_live_screenshot('canvas'),
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32102)),
icon='DefaultAddonPVRClient.png'),
helperobjects.TitleItem(self._kodi_wrapper.get_localized_string(32103),
dict(action=actions.PLAY, video_url=self._KETNET_LIVESTREAM),
is_playable=True,
thumbnail=self._api_helper.get_live_screenshot('ketnet'),
video_dictionary=dict(plot=self._kodi_wrapper.get_localized_string(32103)),
icon='DefaultAddonPVRClient.png'),
]
self._kodi_wrapper.show_listing(livestream_items, content_type='videos')
def show_episodes(self, path):
title_items, sort = self._api_helper.get_episode_items(path)
self._kodi_wrapper.show_listing(title_items, sort=sort, content_type='episodes')
def __get_category_menu_items(self, url, soupstrainer_parser_selector, routing_action, video_dictionary_action=None):
response = requests.get(url)
tiles = SoupStrainer('a', soupstrainer_parser_selector)
soup = BeautifulSoup(response.content, 'html.parser', parse_only=tiles)
listing = []
for tile in soup.find_all(class_='nui-tile title'):
category = tile['href'].split('/')[-2]
thumbnail, title = self.__get_category_thumbnail_and_title(tile)
video_dictionary = None
if video_dictionary_action is not None:
video_dictionary = video_dictionary_action(tile)
item = helperobjects.TitleItem(title, {'action': routing_action, 'video_url': category},
False, thumbnail, video_dictionary)
listing.append(item)
return listing
@staticmethod
def __format_category_image_url(element):
raw_thumbnail = element.find(class_='nui-tile--image')['data-responsive-image']
return statichelper.replace_double_slashes_with_https(raw_thumbnail)
@staticmethod
def __get_category_thumbnail_and_title(element):
thumbnail = VRTPlayer.__format_category_image_url(element)
found_element = element.find('h2')
title = ''
if found_element is not None:
title = statichelper.replace_newlines_and_strip(found_element.contents[0])
return thumbnail, title