plugin.video.viervijfzes/resources/lib/modules/player.py

77 lines
2.7 KiB
Python
Raw Normal View History

2020-03-19 16:45:31 +01:00
# -*- coding: utf-8 -*-
""" Player module """
from __future__ import absolute_import, division, unicode_literals
import logging
from resources.lib import kodiutils
from resources.lib.viervijfzes.auth import AuthApi
2020-03-22 10:30:23 +01:00
from resources.lib.viervijfzes.auth_awsidp import InvalidLoginException, AuthenticationException
2020-03-19 16:45:31 +01:00
from resources.lib.viervijfzes.content import ContentApi, UnavailableException, GeoblockedException
_LOGGER = logging.getLogger('player')
class Player:
""" Code responsible for playing media """
def __init__(self):
""" Initialise object """
def play_from_page(self, channel, path):
""" Play the requested item.
:type channel: string
:type path: string
"""
# Get episode information
2020-03-21 20:34:07 +01:00
episode = ContentApi().get_episode(channel, path)
2020-03-19 16:45:31 +01:00
# Play this now we have the uuid
self.play(episode.uuid)
2020-03-19 16:45:31 +01:00
2020-03-21 20:34:07 +01:00
@staticmethod
def play(item):
2020-03-19 16:45:31 +01:00
""" Play the requested item.
:type item: string
"""
2020-03-25 07:50:45 +01:00
# Workaround for Raspberry Pi 3 and older
omxplayer = kodiutils.get_global_setting('videoplayer.useomxplayer')
if omxplayer is False:
kodiutils.set_global_setting('videoplayer.useomxplayer', True)
2020-03-19 16:45:31 +01:00
try:
2020-03-21 20:34:07 +01:00
# Check if we have credentials
if not kodiutils.get_setting('username') or not kodiutils.get_setting('password'):
2020-03-22 10:30:23 +01:00
confirm = kodiutils.yesno_dialog(
message=kodiutils.localize(30701)) # To watch a video, you need to enter your credentials. Do you want to enter them now?
2020-03-21 20:34:07 +01:00
if confirm:
kodiutils.open_settings()
kodiutils.end_of_directory()
return
# Fetch an auth token now
2020-03-22 10:30:23 +01:00
try:
auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'))
# Get stream information
resolved_stream = ContentApi(auth).get_stream_by_uuid(item)
2020-03-22 10:30:23 +01:00
except (InvalidLoginException, AuthenticationException) as ex:
_LOGGER.error(ex)
kodiutils.ok_dialog(message=kodiutils.localize(30702, error=str(ex)))
2020-03-22 10:30:23 +01:00
kodiutils.end_of_directory()
return
2020-03-21 20:34:07 +01:00
2020-03-19 16:45:31 +01:00
except GeoblockedException:
kodiutils.ok_dialog(heading=kodiutils.localize(30709), message=kodiutils.localize(30710)) # This video is geo-blocked...
return
except UnavailableException:
kodiutils.ok_dialog(heading=kodiutils.localize(30711), message=kodiutils.localize(30712)) # The video is unavailable...
return
# Play this item
kodiutils.play(resolved_stream)