openlp/openlp/plugins/media/mediaplugin.py

125 lines
6.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2011-03-24 19:04:02 +00:00
# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, #
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2009-10-08 05:02:39 +00:00
import logging
2010-10-30 09:29:59 +00:00
import mimetypes
2009-10-08 05:02:39 +00:00
2010-06-08 15:38:09 +00:00
from PyQt4.phonon import Phonon
from openlp.core.lib import Plugin, StringContent, build_icon, translate
2010-10-07 21:47:17 +00:00
from openlp.plugins.media.lib import MediaMediaItem, MediaTab
2009-09-21 19:23:51 +00:00
2010-02-27 09:55:44 +00:00
log = logging.getLogger(__name__)
2009-05-15 05:15:53 +00:00
class MediaPlugin(Plugin):
2010-02-27 09:55:44 +00:00
log.info(u'%s MediaPlugin loaded', __name__)
def __init__(self, plugin_helpers):
2011-03-10 19:17:05 +00:00
Plugin.__init__(self, u'Media', plugin_helpers,
MediaMediaItem, MediaTab)
self.weight = -6
2010-07-10 01:01:14 +00:00
self.icon_path = u':/plugins/plugin_media.png'
self.icon = build_icon(self.icon_path)
# passed with drag and drop messages
self.dnd_id = u'Media'
self.additional_extensions = {
u'audio/ac3': [u'.ac3'],
u'audio/flac': [u'.flac'],
u'audio/x-m4a': [u'.m4a'],
u'audio/midi': [u'.mid', u'.midi'],
u'audio/x-mp3': [u'.mp3'],
u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'],
u'audio/qcelp': [u'.qcp'],
u'audio/x-wma': [u'.wma'],
u'audio/x-ms-wma': [u'.wma'],
u'video/x-flv': [u'.flv'],
u'video/x-matroska': [u'.mpv', u'.mkv'],
u'video/x-wmv': [u'.wmv'],
u'video/x-ms-wmv': [u'.wmv']}
2011-02-21 20:37:18 +00:00
self.audio_extensions_list = []
self.video_extensions_list = []
2010-10-30 09:29:59 +00:00
mimetypes.init()
2010-02-27 14:57:33 +00:00
for mimetype in Phonon.BackendCapabilities.availableMimeTypes():
mimetype = unicode(mimetype)
if mimetype.startswith(u'audio/'):
2011-02-21 20:37:18 +00:00
self._addToList(self.audio_extensions_list, mimetype)
elif mimetype.startswith(u'video/'):
2011-02-21 20:37:18 +00:00
self._addToList(self.video_extensions_list, mimetype)
2010-02-27 14:57:33 +00:00
def _addToList(self, list, mimetype):
2011-02-22 09:09:47 +00:00
# Add all extensions which mimetypes provides us for supported types.
extensions = mimetypes.guess_all_extensions(unicode(mimetype))
for extension in extensions:
2011-02-20 18:49:59 +00:00
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.serviceManager.supportedSuffixes(extension[1:])
2011-02-25 17:05:01 +00:00
log.info(u'MediaPlugin: %s extensions: %s' % (mimetype,
u' '.join(extensions)))
# Add extensions for this mimetype from self.additional_extensions.
# This hack clears mimetypes' and operating system's shortcomings
# by providing possibly missing extensions.
if mimetype in self.additional_extensions.keys():
for extension in self.additional_extensions[mimetype]:
2011-03-12 09:59:38 +00:00
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.serviceManager.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s additional extensions: %s' % (mimetype,
u' '.join(self.additional_extensions[mimetype])))
2009-10-01 16:56:42 +00:00
def about(self):
2010-07-23 18:03:19 +00:00
about_text = translate('MediaPlugin', '<strong>Media Plugin</strong>'
'<br />The media plugin provides playback of audio and video.')
2010-07-27 09:32:52 +00:00
return about_text
2010-09-27 18:15:55 +00:00
def setPluginTextStrings(self):
"""
Called to define all translatable texts of the plugin
"""
2010-09-15 17:55:27 +00:00
## Name PluginList ##
self.textStrings[StringContent.Name] = {
u'singular': translate('MediaPlugin', 'Media', 'name singular'),
u'plural': translate('MediaPlugin', 'Media', 'name plural')
2010-09-15 17:55:27 +00:00
}
## Name for MediaDockManager, SettingsManager ##
self.textStrings[StringContent.VisibleName] = {
u'title': translate('MediaPlugin', 'Media', 'container title')
}
# Middle Header Bar
2011-02-14 17:25:51 +00:00
tooltips = {
2011-02-14 19:08:18 +00:00
u'load': translate('MediaPlugin', 'Load a new Media'),
u'import': u'',
u'new': translate('MediaPlugin', 'Add a new Media'),
u'edit': translate('MediaPlugin', 'Edit the selected Media'),
u'delete': translate('MediaPlugin', 'Delete the selected Media'),
u'preview': translate('MediaPlugin', 'Preview the selected Media'),
u'live': translate('MediaPlugin', 'Send the selected Media live'),
u'service': translate('MediaPlugin',
2011-02-14 17:25:51 +00:00
'Add the selected Media to the service')
}
self.setPluginUiTextStrings(tooltips)