Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow direct playing from epg #74

Merged
merged 9 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Thumbs.db
.tox/
test/userdata/addon_settings.json
test/userdata/credentials.json
test/userdata/temp
test/cdm
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ clean:
find . -name '__pycache__' -type d -delete
rm -rf .pytest_cache/ .tox/
rm -f *.log
rm -rf test/userdata/temp
27 changes: 27 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ msgctxt "#30014"
msgid "Browse the TV Guide"
msgstr ""


### CODE
msgctxt "#30200"
msgid "Using a SOCKS proxy requires the PySocks library (script.module.pysocks) installed."
Expand Down Expand Up @@ -134,6 +135,32 @@ msgctxt "#30214"
msgid "[B]Next:[/B] {start} - {end}\n» {title}\n"
msgstr ""

msgctxt "#30215"
msgid "Browse the TV-Guide of [B]{channel}[/B]"
msgstr ""


### Dates
msgctxt "#30300"
msgid "2 days ago"
msgstr ""

msgctxt "#30301"
msgid "Yesterday"
msgstr ""

msgctxt "#30302"
msgid "Today"
msgstr ""

msgctxt "#30303"
msgid "Tomorrow"
msgstr ""

msgctxt "#30304"
msgid "In 2 days"
msgstr ""


### ERRORS
msgctxt "#30701"
Expand Down
27 changes: 27 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ msgctxt "#30014"
msgid "Browse the TV guide"
msgstr "Doorblader de tv-gids"


### CODE
msgctxt "#30200"
msgid "Using a SOCKS proxy requires the PySocks library (script.module.pysocks) installed."
Expand Down Expand Up @@ -134,6 +135,32 @@ msgctxt "#30214"
msgid "[B]Next:[/B] {start} - {end}\n» {title}\n"
msgstr "[B]Straks:[/B] {start} - {end}\n» {title}\n"

msgctxt "#30215"
msgid "Browse the TV-Guide of [B]{channel}[/B]"
msgstr "Doorblader de tv-gids van [B]{channel}[/B]"


### Dates
msgctxt "#30300"
msgid "2 days ago"
msgstr "Eergisteren"

msgctxt "#30301"
msgid "Yesterday"
msgstr "Gisteren"

msgctxt "#30302"
msgid "Today"
msgstr "Vandaag"

msgctxt "#30303"
msgid "Tomorrow"
msgstr "Morgen"

msgctxt "#30304"
msgid "In 2 days"
msgstr "Overmorgen"


### ERRORS
msgctxt "#30701"
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
),
dict(
label='QMusic',
studio='QMusic',
studio='Q Music',
# Q-Music: https://www.youtube.com/user/qmusic
path='plugin://plugin.video.youtube/user/qmusic/',
kids=False,
Expand Down Expand Up @@ -95,7 +95,7 @@
),
dict(
label='QMusic',
studio='QMusic',
studio='Q Music',
key='qmusic',
kids=False,
),
Expand Down
144 changes: 84 additions & 60 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import absolute_import, division, unicode_literals

import routing

import xbmcplugin
from xbmc import Keyboard
from xbmcgui import Dialog, ListItem
Expand All @@ -12,6 +11,7 @@
get_setting_as_bool, get_global_setting, localize,
notification, show_ok_dialog, show_settings)
from resources.lib.vtmgo import Content, VtmGo
from resources.lib.vtmgoepg import VtmGoEpg
from resources.lib.vtmgostream import VtmGoStream

plugin = routing.Plugin()
Expand Down Expand Up @@ -167,107 +167,121 @@ def show_kids_tvguide():


@plugin.route('/tvguide')
@plugin.route('/tvguide/<channel>')
def show_tvguide(channel=None):
def show_tvguide():
listing = []
kids = _get_kids_mode()
if channel is None:
# Show a list of all channels
from . import CHANNELS
for entry in CHANNELS:
# Skip non-kids channels when we are in kids mode.
if kids and entry.get('kids') is False:
continue

# Try to use the white icons for thumbnails (used for icons as well)
if get_cond_visibility('System.HasAddon(resource.images.studios.white)') == 1:
thumb = 'resource://resource.images.studios.white/{studio}.png'.format(**entry)
else:
thumb = 'DefaultTags.png'

# Try to use the coloured icons for fanart
if get_cond_visibility('System.HasAddon(resource.images.studios.coloured)') == 1:
fanart = 'resource://resource.images.studios.coloured/{studio}.png'.format(**entry)
elif get_cond_visibility('System.HasAddon(resource.images.studios.white)') == 1:
fanart = 'resource://resource.images.studios.white/{studio}.png'.format(**entry)
else:
fanart = 'DefaultTags.png'

listitem = ListItem(entry.get('label'), offscreen=True)
listitem.setInfo('video', {
'plot': localize(30206, label=entry.get('label')),
'studio': entry.get('studio'),
'mediatype': 'video',
})
listitem.setArt({
'icon': 'DefaultTags.png',
'fanart': fanart,
'thumb': thumb,
})
listing.append((plugin.url_for(show_tvguide, channel=entry.get('key')), listitem, True))

# Sort by default like in our dict.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
# Show a list of all channels
from . import CHANNELS
for entry in CHANNELS:
# Skip non-kids channels when we are in kids mode.
if kids and entry.get('kids') is False:
continue

else:
from .vtmgoepg import VtmGoEpg
for day in VtmGoEpg.get_dates():
listitem = ListItem(day.get('title'), offscreen=True)
listitem.setInfo('video', {
'plot': day.get('date'),
})
listing.append((plugin.url_for(show_tvguide_detail, channel=channel, date=day.get('date')), listitem, True))
# Try to use the white icons for thumbnails (used for icons as well)
if get_cond_visibility('System.HasAddon(resource.images.studios.white)') == 1:
thumb = 'resource://resource.images.studios.white/{studio}.png'.format(**entry)
else:
thumb = 'DefaultTags.png'

# Sort like we add it.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
# Try to use the coloured icons for fanart
if get_cond_visibility('System.HasAddon(resource.images.studios.coloured)') == 1:
fanart = 'resource://resource.images.studios.coloured/{studio}.png'.format(**entry)
elif get_cond_visibility('System.HasAddon(resource.images.studios.white)') == 1:
fanart = 'resource://resource.images.studios.white/{studio}.png'.format(**entry)
else:
fanart = 'DefaultTags.png'

xbmcplugin.setContent(plugin.handle, 'files')
listitem = ListItem(entry.get('label'), offscreen=True)
listitem.setInfo('video', {
'plot': localize(30215, channel=entry.get('label')),
'studio': entry.get('studio'),
'mediatype': 'video',
})
listitem.setArt({
'icon': 'DefaultTags.png',
'fanart': fanart,
'thumb': thumb,
})
listing.append((plugin.url_for(show_tvguide_channel, channel=entry.get('key')), listitem, True))

# Sort by default like in our dict.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)

xbmcplugin.setPluginCategory(plugin.handle, category='VTM KIDS / TV Guide' if kids else 'VTM GO / TV Guide')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/tvguide/<channel>')
def show_tvguide_channel(channel):
listing = []

for day in VtmGoEpg.get_dates():
if day['highlight']:
title = '[B]%s[/B]'
else:
title = '%s'

listitem = ListItem(title % day.get('title'), offscreen=True)
listitem.setArt({
'icon': 'DefaultYear.png',
})
listitem.setInfo('video', {
'plot': day.get('title'),
})
listing.append((plugin.url_for(show_tvguide_detail, channel=channel, date=day.get('date')), listitem, True))

xbmcplugin.setContent(plugin.handle, 'files')

# Sort like we add it.
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)

xbmcplugin.setPluginCategory(plugin.handle, category='TV Guide')
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/tvguide/<channel>/<date>')
def show_tvguide_detail(channel=None, date=None):
try:
from .vtmgoepg import VtmGoEpg
_vtmGoEpg = VtmGoEpg()
epg = _vtmGoEpg.get_epg(date=date)
except Exception as ex:
notification(message=str(ex))
raise

# The epg contains the data for all channels. We only need the data of the requested channel.
channel = epg.get(channel)
epg_json = epg.get(channel)

listing = []
for broadcast in channel.broadcasts:
for broadcast in epg_json.broadcasts: # type: EpgBroadcast
title = '{time} - {title}'.format(
time=broadcast.time.strftime('%H:%M'),
title=broadcast.title
)

listitem = ListItem(title, offscreen=True)
listitem.setArt({
'thumb': broadcast.image,
})
listitem.setInfo('video', {
'title': title,
'plot': broadcast.description,
'mediatype': broadcast.mediatype,
'duration': broadcast.duration,
})
listitem.setArt({
'thumb': broadcast.image,
listitem.addStreamInfo('video', {
'duration': broadcast.duration,
})
listitem.setProperty('IsPlayable', 'true')

listing.append(('#', listitem, False))
listing.append((plugin.url_for(play_epg, channel=channel, program_type=broadcast.playable_type, epg_id=broadcast.uuid), listitem, False))

xbmcplugin.setContent(plugin.handle, 'episodes')

xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.setPluginCategory(plugin.handle, category='VTM GO / TV Guide')
xbmcplugin.setPluginCategory(plugin.handle, category=date)
ok = xbmcplugin.addDirectoryItems(plugin.handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=False)

Expand Down Expand Up @@ -585,6 +599,13 @@ def show_search():
xbmcplugin.endOfDirectory(plugin.handle, ok, cacheToDisc=True)


@plugin.route('/play/epg/<channel>/<program_type>/<epg_id>')
def play_epg(channel, program_type, epg_id):
_vtmGoEpg = VtmGoEpg()
details = _vtmGoEpg.get_details(channel=channel, program_type=program_type, epg_id=epg_id)
_stream(details.playable_type, details.playable_uuid)


@plugin.route('/play/livetv/<channel>')
def play_livetv(channel):
_stream('channels', channel)
Expand Down Expand Up @@ -702,6 +723,9 @@ def _stream(strtype, strid):
listitem.setContentLookup(False)

if strtype == 'channels':
# For live channels, we need to keep on updating the manifest
# This might not be needed, and could be done with the Location-tag updates if inputstream.adaptive supports it
# See https:/peak3d/inputstream.adaptive/pull/298#issuecomment-524206935
listitem.setProperty('inputstream.adaptive.manifest_update_parameter', 'full')
try:
from inputstreamhelper import Helper
Expand Down
4 changes: 4 additions & 0 deletions resources/lib/vtmgo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, unicode_literals

import json

try: # Python 3
Expand All @@ -9,6 +10,7 @@
from urllib import quote

import requests
from resources.lib import kodilogging
from resources.lib.kodiutils import proxies


Expand Down Expand Up @@ -362,6 +364,8 @@ def _get_url(self, url, auth=None):
if auth:
headers['x-dpp-jwt'] = auth

kodilogging.log('Fetching %s...' % url, kodilogging.LOGDEBUG)

response = requests.session().get('https://api.vtmgo.be' + url, headers=headers, verify=False, proxies=proxies)

if response.status_code != 200:
Expand Down
Loading