More missing lib fixes and MediaInfo cleanup

This commit is contained in:
Tim Bentley 2018-11-18 17:29:47 +00:00
parent 77613086bf
commit a3d0dc28de
7 changed files with 41 additions and 62 deletions

View File

@ -49,7 +49,8 @@ class LogMixin(object):
setattr(self, name, self.logging_wrapper(m, self))
return self._logger
def logging_wrapper(self, func, parent):
@staticmethod
def logging_wrapper(func, parent):
"""
Code to added debug wrapper to work on called functions within a decorated class.
"""

View File

@ -54,11 +54,17 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
def bootstrap_initialise(self):
"""
Bootstrap all the plugin manager functions
Scan a directory for objects inheriting from the ``Plugin`` class.
"""
self.find_plugins()
# hook methods have to happen after find_plugins. Find plugins needs
# the controllers hence the hooks have moved from setupUI() to here
# Find and insert settings tabs
glob_pattern = os.path.join('plugins', '*', '[!.]*plugin.py')
extension_loader(glob_pattern)
plugin_classes = Plugin.__subclasses__()
for p in plugin_classes:
try:
p()
self.log_debug('Loaded plugin {plugin}'.format(plugin=str(p)))
except TypeError:
self.log_exception('Failed to load plugin {plugin}'.format(plugin=str(p)))
def bootstrap_post_set_up(self):
"""
@ -86,20 +92,6 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
plugin.app_startup()
self.application.process_events()
def find_plugins(self):
"""
Scan a directory for objects inheriting from the ``Plugin`` class.
"""
glob_pattern = os.path.join('plugins', '*', '[!.]*plugin.py')
extension_loader(glob_pattern)
plugin_classes = Plugin.__subclasses__()
for p in plugin_classes:
try:
p()
self.log_debug('Loaded plugin {plugin}'.format(plugin=str(p)))
except TypeError:
self.log_exception('Failed to load plugin {plugin}'.format(plugin=str(p)))
@staticmethod
def hook_media_manager():
"""

View File

@ -32,6 +32,7 @@ import uuid
from PyQt5 import QtGui
from openlp.core.state import State
from openlp.core.common import md5_hash
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
@ -441,7 +442,7 @@ class ServiceItem(RegistryProperties):
self.processor = header.get('processor', None)
self.has_original_files = True
self.metadata = header.get('item_meta_data', [])
if 'background_audio' in header:
if 'background_audio' in header and State().check_preconditions('media'):
self.background_audio = []
for file_path in header['background_audio']:
# In OpenLP 3.0 we switched to storing Path objects in JSON files
@ -688,7 +689,7 @@ class ServiceItem(RegistryProperties):
self.is_valid = False
break
elif self.is_command():
if self.is_capable(ItemCapabilities.IsOptical):
if self.is_capable(ItemCapabilities.IsOptical) and State().check_preconditions('media'):
if not os.path.exists(frame['title']):
self.is_valid = False
break

View File

@ -50,7 +50,7 @@ class MediaType(object):
Folder = 5
class MediaInfo(object):
class ItemMediaInfo(object):
"""
This class hold the media related info
"""

View File

@ -45,7 +45,7 @@ from openlp.core.lib.serviceitem import ItemCapabilities
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.ui import DisplayControllerType
from openlp.core.ui.icons import UiIcons
from openlp.core.ui.media import MediaState, MediaInfo, MediaType, parse_optical_path
from openlp.core.ui.media import MediaState, ItemMediaInfo, MediaType, parse_optical_path
from openlp.core.ui.media.endpoint import media_endpoint
from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
from openlp.core.widgets.toolbar import OpenLPToolbar
@ -172,7 +172,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
State().update_pre_conditions("mediacontroller", True)
else:
State().missing_text("mediacontroller", translate('OpenLP.SlideController',
"VLC or pymediainfo are missing so you are unable to play any media"))
"VLC or pymediainfo are missing, so you are unable to play any media"))
self._generate_extensions_lists()
return True
@ -182,12 +182,14 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
"""
display = self._define_display(self.display_controllers[DisplayControllerType.Live])
if DisplayControllerType.Live in self.current_media_players:
print("media_state_live if")
self.current_media_players[DisplayControllerType.Live].resize(display)
self.current_media_players[DisplayControllerType.Live].update_ui(display)
self.tick(self.display_controllers[DisplayControllerType.Live])
if self.current_media_players[DisplayControllerType.Live].get_live_state() is not MediaState.Playing:
self.live_timer.stop()
else:
print("media_state_live else")
self.live_timer.stop()
self.media_stop(self.display_controllers[DisplayControllerType.Live])
if self.display_controllers[DisplayControllerType.Live].media_info.can_loop_playback:
@ -199,12 +201,14 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
"""
display = self._define_display(self.display_controllers[DisplayControllerType.Preview])
if DisplayControllerType.Preview in self.current_media_players:
print("media_state_preview if")
self.current_media_players[DisplayControllerType.Preview].resize(display)
self.current_media_players[DisplayControllerType.Preview].update_ui(display)
self.tick(self.display_controllers[DisplayControllerType.Preview])
if self.current_media_players[DisplayControllerType.Preview].get_preview_state() is not MediaState.Playing:
self.preview_timer.stop()
else:
print("media_state_preview else")
self.preview_timer.stop()
self.media_stop(self.display_controllers[DisplayControllerType.Preview])
if self.display_controllers[DisplayControllerType.Preview].media_info.can_loop_playback:
@ -225,7 +229,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
:param controller: First element is the controller which should be used
"""
controller.media_info = MediaInfo()
controller.media_info = ItemMediaInfo()
# Build a Media ToolBar
controller.mediabar = OpenLPToolbar(controller)
controller.mediabar.add_toolbar_action('playbackPlay', text='media_playback_play',
@ -332,7 +336,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
controller = self.display_controllers[source]
# stop running videos
self.media_reset(controller)
controller.media_info = MediaInfo()
controller.media_info = ItemMediaInfo()
controller.media_info.volume = controller.volume_slider.value()
controller.media_info.is_background = video_behind_text
# background will always loop video.
@ -353,7 +357,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
else:
log.debug('video is not optical and live')
controller.media_info.length = service_item.media_length
is_valid = self._check_file_type(controller, display, service_item)
is_valid = self._check_file_type(controller, display)
display.override['theme'] = ''
display.override['video'] = True
if controller.media_info.is_background:
@ -373,7 +377,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
else:
log.debug('video is not optical and preview')
controller.media_info.length = service_item.media_length
is_valid = self._check_file_type(controller, display, service_item)
is_valid = self._check_file_type(controller, display)
if not is_valid:
# Media could not be loaded correctly
critical_error_message_box(translate('MediaPlugin.MediaItem', 'Unsupported File'),
@ -437,7 +441,7 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
# stop running videos
self.media_reset(controller)
# Setup media info
controller.media_info = MediaInfo()
controller.media_info = ItemMediaInfo()
controller.media_info.file_info = QtCore.QFileInfo(filename)
if audio_track == -1 and subtitle_track == -1:
controller.media_info.media_type = MediaType.CD
@ -461,33 +465,12 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
controller.media_info.media_type = MediaType.DVD
return True
def _get_used_players(self, service_item):
"""
Find the player for a given service item
:param service_item: where the information is about the media and required player
:return: player description
"""
return self.vlc_player
# If no player, we can't play
# if not used_players:
# return False
# default_player = [used_players]
# if service_item.processor and service_item.processor != UiStrings().Automatic:
# # check to see if the player is usable else use the default one.
# if service_item.processor.lower() not in used_players:
# used_players = default_player
# else:
# used_players = [service_item.processor.lower()]
# return used_players
def _check_file_type(self, controller, display, service_item):
def _check_file_type(self, controller, display):
"""
Select the correct media Player type from the prioritized Player list
:param controller: First element is the controller which should be used
:param display: Which display to use
:param service_item: The ServiceItem containing the details to be played.
"""
for file in controller.media_info.file_info:
if file.is_file:
@ -516,7 +499,6 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
self.current_media_players[controller.controller_type] = player
controller.media_info.media_type = MediaType.Video
return True
# no valid player found
return False
def media_play_msg(self, msg, status=True):

View File

@ -23,17 +23,13 @@
The Media plugin
"""
import logging
import re
from PyQt5 import QtCore
from openlp.core.state import State
from openlp.core.api.http import register_endpoint
from openlp.core.common import check_binary_exists
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import translate
from openlp.core.ui.icons import UiIcons
from openlp.core.common.path import Path
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import Plugin, StringContent
from openlp.plugins.media.endpoint import api_media_endpoint, media_endpoint

View File

@ -25,6 +25,7 @@ import os
from PyQt5 import QtCore, QtWidgets
from sqlalchemy.sql import and_, or_
from openlp.core.state import State
from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings, translate, get_natural_key
from openlp.core.ui.icons import UiIcons
@ -35,7 +36,7 @@ from openlp.core.lib import ServiceItemContext, check_item_selected, create_sepa
from openlp.core.lib.mediamanageritem import MediaManagerItem
from openlp.core.lib.plugin import PluginStatus
from openlp.core.lib.serviceitem import ItemCapabilities
from openlp.core.lib.ui import create_widget_action
from openlp.core.lib.ui import create_widget_action, critical_error_message_box
from openlp.plugins.songs.forms.editsongform import EditSongForm
from openlp.plugins.songs.forms.songexportform import SongExportForm
from openlp.plugins.songs.forms.songimportform import SongImportForm
@ -632,11 +633,17 @@ class SongMediaItem(MediaManagerItem):
service_item.xml_version = self.open_lyrics.song_to_xml(song)
# Add the audio file to the service item.
if song.media_files:
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
service_item.background_audio = [m.file_path for m in song.media_files]
service_item.metadata.append('<em>{label}:</em> {media}'.
format(label=translate('SongsPlugin.MediaItem', 'Media'),
media=service_item.background_audio))
if State().check_preconditions('media'):
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
service_item.background_audio = [m.file_path for m in song.media_files]
service_item.metadata.append('<em>{label}:</em> {media}'.
format(label=translate('SongsPlugin.MediaItem', 'Media'),
media=service_item.background_audio))
else:
critical_error_message_box(
translate('SongsPlugin.MediaItem', 'Missing Audio Software'),
translate('SongsPlugin.MediaItem',
'Unable to play background music for Song and audio is not configured'))
return True
def generate_footer(self, item, song):