forked from add-ons/plugin.video.vrt.nu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vrtplayer.py
127 lines (109 loc) · 7.38 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
127
# -*- coding: utf-8 -*-
# GNU General Public License v2.0 (see COPYING or https://www.gnu.org/licenses/gpl-2.0.txt)
import os
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, addon_path, kodi_wrapper, stream_service, api_helper):
self._addon_path = addon_path
self._kodi_wrapper = kodi_wrapper
self._proxies = self._kodi_wrapper.get_proxies()
self._api_helper = api_helper
self._stream_service = stream_service
def show_main_menu_items(self):
main_items = [
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32080),
url_dict=dict(action=actions.LISTING_AZ_TVSHOWS),
is_playable=False,
art_dict=dict(thumb='DefaultMovieTitle.png', icon='DefaultMovieTitle.png', fanart='DefaultMovieTitle.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32081))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32082),
url_dict=dict(action=actions.LISTING_CATEGORIES),
is_playable=False,
art_dict=dict(thumb='DefaultGenre.png', icon='DefaultGenre.png', fanart='DefaultGenre.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32083))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32084),
url_dict=dict(action=actions.LISTING_LIVE),
is_playable=False,
art_dict=dict(thumb='DefaultAddonPVRClient.png', icon='DefaultAddonPVRClient.png', fanart='DefaultAddonPVRClient.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32085))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32086),
url_dict=dict(action=actions.LISTING_EPISODES, video_url='recent'),
is_playable=False,
art_dict=dict(thumb='DefaultYear.png', icon='DefaultYear.png', fanart='DefaultYear.png'),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32087))),
]
self._kodi_wrapper.show_listing(main_items, content_type='files')
def show_tvshow_menu_items(self, path):
tvshow_items = self._api_helper.get_tvshow_items(path)
self._kodi_wrapper.show_listing(tvshow_items, sort=sortmethod.ALPHABET, content_type='tvshows')
def show_category_menu_items(self):
joined_url = ''.join((self.VRTNU_BASE_URL, '/categorieen/'))
category_items = self.__get_category_menu_items(joined_url, {'class': 'nui-tile title'}, actions.LISTING_CATEGORY_TVSHOWS)
self._kodi_wrapper.show_listing(category_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(title=self._kodi_wrapper.get_localized_string(32101),
url_dict=dict(action=actions.PLAY, video_url=self._EEN_LIVESTREAM),
is_playable=True,
art_dict=dict(thumb=self.__get_media('een.png'), icon='DefaultAddonPVRClient.png', fanart=self._api_helper.get_live_screenshot('een')),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32101))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32102),
url_dict=dict(action=actions.PLAY, video_url=self._CANVAS_LIVESTREAM),
is_playable=True,
art_dict=dict(thumb=self.__get_media('canvas.png'), icon='DefaultAddonPVRClient.png', fanart=self._api_helper.get_live_screenshot('canvas')),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32102))),
helperobjects.TitleItem(title=self._kodi_wrapper.get_localized_string(32103),
url_dict=dict(action=actions.PLAY, video_url=self._KETNET_LIVESTREAM),
is_playable=True,
art_dict=dict(thumb=self.__get_media('ketnet.png'), icon='DefaultAddonPVRClient.png', fanart=self._api_helper.get_live_screenshot('ketnet')),
video_dict=dict(plot=self._kodi_wrapper.get_localized_string(32103))),
]
self._kodi_wrapper.show_listing(livestream_items, content_type='videos')
def show_episodes(self, path):
episode_items, sort = self._api_helper.get_episode_items(path)
self._kodi_wrapper.show_listing(episode_items, sort=sort, content_type='episodes')
def __get_media(self, file_name):
return os.path.join(self._addon_path, 'resources', 'media', file_name)
def __get_category_menu_items(self, url, soupstrainer_parser_selector, routing_action, video_dict_action=None):
response = requests.get(url, proxies=self._proxies)
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_dict = None
if video_dict_action is not None:
video_dict = video_dict_action(tile)
listing.append(helperobjects.TitleItem(title=title,
url_dict=dict(action=routing_action, video_url=category),
is_playable=False,
art_dict=dict(thumb=thumbnail, icon='DefaultGenre.png', fanart=thumbnail),
video_dict=video_dict))
return listing
@staticmethod
def __format_category_image_url(element):
raw_thumbnail = element.find(class_='nui-tile--image')['data-responsive-image']
return statichelper.add_https_method(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.strip_newlines(found_element.contents[0])
return thumbnail, title