2008-12-14 16:19:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2022-02-01 10:10:57 +00:00
|
|
|
# Copyright (c) 2008-2022 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License for more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License #
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2015-03-10 21:33:35 +00:00
|
|
|
"""
|
|
|
|
The Media plugin
|
|
|
|
"""
|
2009-10-08 05:02:39 +00:00
|
|
|
import logging
|
2020-10-11 06:41:03 +00:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2017-10-07 07:05:07 +00:00
|
|
|
|
2020-10-11 06:41:03 +00:00
|
|
|
from openlp.core.common import sha256_file_hash
|
2018-04-10 19:26:56 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib import build_icon
|
2020-10-11 06:41:03 +00:00
|
|
|
from openlp.core.lib.db import Manager
|
2018-08-25 14:08:19 +00:00
|
|
|
from openlp.core.lib.plugin import Plugin, StringContent
|
2020-10-11 06:41:03 +00:00
|
|
|
from openlp.core.state import State
|
|
|
|
from openlp.core.ui.icons import UiIcons
|
|
|
|
from openlp.core.ui.media import parse_optical_path, parse_stream_path
|
|
|
|
|
|
|
|
from openlp.plugins.media.lib.db import Item, init_schema
|
2018-10-27 01:53:43 +00:00
|
|
|
from openlp.plugins.media.lib.mediaitem import MediaMediaItem
|
2009-09-21 19:23:51 +00:00
|
|
|
|
2018-10-02 04:39:42 +00:00
|
|
|
|
2010-02-27 09:55:44 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-04-19 19:15:12 +00:00
|
|
|
|
2013-01-16 19:37:47 +00:00
|
|
|
# Some settings starting with "media" are in core, because they are needed for core functionality.
|
2013-01-10 20:50:01 +00:00
|
|
|
|
2009-05-15 05:15:53 +00:00
|
|
|
class MediaPlugin(Plugin):
|
2015-03-10 21:33:35 +00:00
|
|
|
"""
|
|
|
|
The media plugin adds the ability to playback audio and video content.
|
|
|
|
"""
|
2016-05-21 18:19:18 +00:00
|
|
|
log.info('{name} MediaPlugin loaded'.format(name=__name__))
|
2009-03-02 22:12:14 +00:00
|
|
|
|
2013-01-23 21:05:25 +00:00
|
|
|
def __init__(self):
|
2020-10-11 06:41:03 +00:00
|
|
|
super().__init__('media', MediaMediaItem)
|
|
|
|
self.manager = Manager(plugin_name='media', init_schema=init_schema)
|
2008-12-14 19:50:17 +00:00
|
|
|
self.weight = -6
|
2018-04-07 19:41:00 +00:00
|
|
|
self.icon_path = UiIcons().video
|
2013-03-19 20:05:13 +00:00
|
|
|
self.icon = build_icon(self.icon_path)
|
2009-06-26 17:51:43 +00:00
|
|
|
# passed with drag and drop messages
|
2013-08-31 18:17:38 +00:00
|
|
|
self.dnd_id = 'Media'
|
2018-10-26 18:30:59 +00:00
|
|
|
State().add_service(self.name, self.weight, requires='mediacontroller', is_plugin=True)
|
2018-10-20 14:41:32 +00:00
|
|
|
State().update_pre_conditions(self.name, self.check_pre_conditions())
|
2009-02-28 23:19:45 +00:00
|
|
|
|
2015-03-10 21:33:35 +00:00
|
|
|
def initialise(self):
|
|
|
|
"""
|
|
|
|
Override the inherited initialise() method in order to upgrade the media before trying to load it
|
|
|
|
"""
|
2020-10-11 06:41:03 +00:00
|
|
|
media_files = self.settings.value('media/media files') or []
|
|
|
|
for filename in media_files:
|
|
|
|
if not isinstance(filename, (Path, str)):
|
|
|
|
continue
|
|
|
|
if isinstance(filename, Path):
|
|
|
|
name = filename.name
|
|
|
|
filename = str(filename)
|
|
|
|
elif filename.startswith('devicestream:') or filename.startswith('networkstream:'):
|
|
|
|
name, _, _ = parse_stream_path(filename)
|
|
|
|
elif filename.startswith('optical:'):
|
|
|
|
_, _, _, _, _, _, name = parse_optical_path(filename)
|
|
|
|
else:
|
|
|
|
name = os.path.basename(filename)
|
|
|
|
item = Item(name=name, file_path=filename)
|
|
|
|
if not filename.startswith('devicestream:') and not filename.startswith('networkstream:') \
|
|
|
|
and not filename.startswith('optical:'):
|
|
|
|
file_path = Path(filename)
|
|
|
|
if file_path.is_file() and file_path.exists():
|
|
|
|
item.file_hash = sha256_file_hash(file_path)
|
|
|
|
self.manager.save_object(item)
|
|
|
|
self.settings.remove('media/media files')
|
2015-03-10 21:33:35 +00:00
|
|
|
super().initialise()
|
|
|
|
|
2020-10-19 07:18:26 +00:00
|
|
|
def check_pre_conditions(self):
|
|
|
|
"""
|
|
|
|
Check the plugin can run and the media controller is available.
|
|
|
|
"""
|
|
|
|
return State().is_module_active('mediacontroller')
|
|
|
|
|
2016-01-04 00:18:01 +00:00
|
|
|
@staticmethod
|
|
|
|
def about():
|
2015-03-10 21:33:35 +00:00
|
|
|
"""
|
|
|
|
Return the about text for the plugin manager
|
|
|
|
"""
|
2010-07-23 18:03:19 +00:00
|
|
|
about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>'
|
2014-03-08 20:53:22 +00:00
|
|
|
'<br />The media plugin provides playback of audio and video.')
|
2010-07-27 09:32:52 +00:00
|
|
|
return about_text
|
2010-09-16 21:10:36 +00:00
|
|
|
|
2013-02-19 21:23:56 +00:00
|
|
|
def set_plugin_text_strings(self):
|
2010-09-10 19:21:14 +00:00
|
|
|
"""
|
|
|
|
Called to define all translatable texts of the plugin
|
|
|
|
"""
|
2014-04-12 20:19:22 +00:00
|
|
|
# Name PluginList
|
2013-03-19 19:43:22 +00:00
|
|
|
self.text_strings[StringContent.Name] = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'singular': translate('MediaPlugin', 'Media', 'name singular'),
|
|
|
|
'plural': translate('MediaPlugin', 'Media', 'name plural')
|
2010-09-15 17:55:27 +00:00
|
|
|
}
|
2014-04-12 20:19:22 +00:00
|
|
|
# Name for MediaDockManager, SettingsManager
|
2013-03-19 19:43:22 +00:00
|
|
|
self.text_strings[StringContent.VisibleName] = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'title': translate('MediaPlugin', 'Media', 'container title')
|
2010-09-10 19:21:14 +00:00
|
|
|
}
|
|
|
|
# Middle Header Bar
|
2011-02-14 17:25:51 +00:00
|
|
|
tooltips = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'load': translate('MediaPlugin', 'Load new media.'),
|
|
|
|
'import': '',
|
|
|
|
'new': translate('MediaPlugin', 'Add new media.'),
|
|
|
|
'edit': translate('MediaPlugin', 'Edit the selected media.'),
|
|
|
|
'delete': translate('MediaPlugin', 'Delete the selected media.'),
|
|
|
|
'preview': translate('MediaPlugin', 'Preview the selected media.'),
|
|
|
|
'live': translate('MediaPlugin', 'Send the selected media live.'),
|
|
|
|
'service': translate('MediaPlugin', 'Add the selected media to the service.')
|
2011-02-14 17:25:51 +00:00
|
|
|
}
|
2013-03-19 19:43:22 +00:00
|
|
|
self.set_plugin_ui_text_strings(tooltips)
|
2011-05-10 20:39:17 +00:00
|
|
|
|
|
|
|
def finalise(self):
|
|
|
|
"""
|
2013-04-19 19:15:12 +00:00
|
|
|
Time to tidy up on exit.
|
2011-05-10 20:39:17 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
log.info('Media Finalising')
|
2013-01-23 19:28:47 +00:00
|
|
|
self.media_controller.finalise()
|
2011-08-29 19:55:58 +00:00
|
|
|
Plugin.finalise(self)
|