← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~phill-ridout/openlp/media_ext_refactors into lp:openlp

 

Phill has proposed merging lp:~phill-ridout/openlp/media_ext_refactors into lp:openlp.

Commit message:
refactor media extensions

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/media_ext_refactors/+merge/368212
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~phill-ridout/openlp/media_ext_refactors into lp:openlp.
=== modified file 'openlp/core/common/json.py'
--- openlp/core/common/json.py	2019-05-23 19:33:46 +0000
+++ openlp/core/common/json.py	2019-05-31 20:34:31 +0000
@@ -23,7 +23,6 @@
 from json import JSONDecoder, JSONEncoder
 from pathlib import Path
 
-
 _registered_classes = {}
 
 

=== modified file 'openlp/core/lib/mediamanageritem.py'
--- openlp/core/lib/mediamanageritem.py	2019-05-22 06:47:00 +0000
+++ openlp/core/lib/mediamanageritem.py	2019-05-31 20:34:31 +0000
@@ -589,7 +589,7 @@
         """
         Add this item to the current service.
 
-        :param item: Item to be processed
+        :param QtWidgets.QListWidgetItem | QtWidgets.QTreeWidgetItem | None item: Item to be processed
         :param replace: Replace the existing item
         :param remote: Triggered from remote
         :param position: Position to place item
@@ -627,7 +627,7 @@
     def build_service_item(self, item=None, remote=False, context=ServiceItemContext.Live):
         """
         Common method for generating a service item
-        :param item: Service Item to be built.
+        :param QtWidgets.QListWidgetItem | QtWidgets.QTreeWidgetItem | None item: Service Item to be built.
         :param remote: Remote triggered (False)
         :param context: The context on which this is called
         """

=== modified file 'openlp/core/lib/serviceitem.py'
--- openlp/core/lib/serviceitem.py	2019-05-22 06:47:00 +0000
+++ openlp/core/lib/serviceitem.py	2019-05-31 20:34:31 +0000
@@ -593,9 +593,11 @@
         """
         return not bool(self.slides)
 
-    def validate_item(self, suffix_list=None):
+    def validate_item(self, suffixes=None):
         """
         Validates a service item to make sure it is valid
+
+        :param set[str] suffixes: A set of vaild suffixes
         """
         self.is_valid = True
         for slide in self.slides:
@@ -612,8 +614,8 @@
                     if not os.path.exists(file_name):
                         self.is_valid = False
                         break
-                    if suffix_list and not self.is_text():
+                    if suffixes and not self.is_text():
                         file_suffix = slide['title'].split('.')[-1]
-                        if file_suffix.lower() not in suffix_list:
+                        if file_suffix.lower() not in suffixes:
                             self.is_valid = False
                             break

=== modified file 'openlp/core/ui/media/mediacontroller.py'
--- openlp/core/ui/media/mediacontroller.py	2019-05-05 05:59:29 +0000
+++ openlp/core/ui/media/mediacontroller.py	2019-05-31 20:34:31 +0000
@@ -44,7 +44,7 @@
 from openlp.core.ui import DisplayControllerType
 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.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
 
 
 log = logging.getLogger(__name__)
@@ -65,11 +65,6 @@
     current_media_players is an array of player instances keyed on ControllerType.
 
     """
-    def __init__(self, parent=None):
-        """
-        Constructor
-        """
-        super(MediaController, self).__init__(parent)
 
     def setup(self):
         self.vlc_player = None
@@ -95,28 +90,8 @@
         Registry().register_function('songs_hide', self.media_hide)
         Registry().register_function('songs_blank', self.media_blank)
         Registry().register_function('songs_unblank', self.media_unblank)
-        Registry().register_function('mediaitem_suffixes', self._generate_extensions_lists)
         register_endpoint(media_endpoint)
 
-    def _generate_extensions_lists(self):
-        """
-        Set the active players and available media files
-        """
-        suffix_list = []
-        self.audio_extensions_list = []
-        if self.vlc_player.is_active:
-            for item in self.vlc_player.audio_extensions_list:
-                if item not in self.audio_extensions_list:
-                    self.audio_extensions_list.append(item)
-                    suffix_list.append(item[2:])
-        self.video_extensions_list = []
-        if self.vlc_player.is_active:
-            for item in self.vlc_player.video_extensions_list:
-                if item not in self.video_extensions_list:
-                    self.video_extensions_list.append(item)
-                    suffix_list.append(item[2:])
-        self.service_manager.supported_suffixes(suffix_list)
-
     def bootstrap_initialise(self):
         """
         Check to see if we have any media Player's available.
@@ -131,7 +106,8 @@
         else:
             State().missing_text('media_live', translate('OpenLP.SlideController',
                                  'VLC or pymediainfo are missing, so you are unable to play any media'))
-        self._generate_extensions_lists()
+        self.service_manager.supported_suffixes(AUDIO_EXT)
+        self.service_manager.supported_suffixes(VIDEO_EXT)
         return True
 
     def bootstrap_post_set_up(self):
@@ -381,7 +357,7 @@
             if file.is_file:
                 suffix = '*%s' % file.suffix.lower()
                 file = str(file)
-                if suffix in self.vlc_player.video_extensions_list:
+                if suffix in VIDEO_EXT:
                     if not controller.media_info.is_background or controller.media_info.is_background and \
                             self.vlc_player.can_background:
                         self.resize(display, self.vlc_player)
@@ -389,7 +365,7 @@
                             self.current_media_players[controller.controller_type] = self.vlc_player
                             controller.media_info.media_type = MediaType.Video
                             return True
-                if suffix in self.vlc_player.audio_extensions_list:
+                if suffix in AUDIO_EXT:
                     if self.vlc_player.load(display, file):
                         self.current_media_players[controller.controller_type] = self.vlc_player
                         controller.media_info.media_type = MediaType.Audio

=== modified file 'openlp/core/ui/media/mediaplayer.py'
--- openlp/core/ui/media/mediaplayer.py	2019-05-03 17:26:37 +0000
+++ openlp/core/ui/media/mediaplayer.py	2019-05-31 20:34:31 +0000
@@ -38,13 +38,10 @@
         self.parent = parent
         self.name = name
         self.available = self.check_available()
-        self.is_active = False
         self.can_background = False
         self.can_folder = False
         self.state = {0: MediaState.Off, 1: MediaState.Off}
         self.has_own_widget = False
-        self.audio_extensions_list = []
-        self.video_extensions_list = []
 
     def check_available(self):
         """
@@ -166,12 +163,6 @@
         """
         return ''
 
-    def get_info(self):
-        """
-        Returns Information about the player
-        """
-        return ''
-
     def get_live_state(self):
         """
         Get the state of the live player

=== modified file 'openlp/core/ui/media/vlcplayer.py'
--- openlp/core/ui/media/vlcplayer.py	2019-05-22 16:47:20 +0000
+++ openlp/core/ui/media/vlcplayer.py	2019-05-31 20:34:31 +0000
@@ -33,7 +33,6 @@
 from PyQt5 import QtWidgets
 
 from openlp.core.common import is_linux, is_macosx, is_win
-from openlp.core.common.i18n import translate
 from openlp.core.common.settings import Settings
 from openlp.core.ui.media import MediaState, MediaType
 from openlp.core.ui.media.mediaplayer import MediaPlayer
@@ -42,20 +41,18 @@
 log = logging.getLogger(__name__)
 
 # Audio and video extensions copied from 'include/vlc_interface.h' from vlc 2.2.0 source
-AUDIO_EXT = ['*.3ga', '*.669', '*.a52', '*.aac', '*.ac3', '*.adt', '*.adts', '*.aif', '*.aifc', '*.aiff', '*.amr',
-             '*.aob', '*.ape', '*.awb', '*.caf', '*.dts', '*.flac', '*.it', '*.kar', '*.m4a', '*.m4b', '*.m4p', '*.m5p',
-             '*.mid', '*.mka', '*.mlp', '*.mod', '*.mpa', '*.mp1', '*.mp2', '*.mp3', '*.mpc', '*.mpga', '*.mus',
-             '*.oga', '*.ogg', '*.oma', '*.opus', '*.qcp', '*.ra', '*.rmi', '*.s3m', '*.sid', '*.spx', '*.thd', '*.tta',
-             '*.voc', '*.vqf', '*.w64', '*.wav', '*.wma', '*.wv', '*.xa', '*.xm']
+AUDIO_EXT = ('3ga', '669', 'a52', 'aac', 'ac3', 'adt', 'adts', 'aif', 'aifc', 'aiff', 'amr', 'aob', 'ape', 'awb', 'caf',
+             'dts', 'flac', 'it', 'kar', 'm4a', 'm4b', 'm4p', 'm5p', 'mid', 'mka', 'mlp', 'mod', 'mpa', 'mp1', 'mp2',
+             'mp3', 'mpc', 'mpga', 'mus', 'oga', 'ogg', 'oma', 'opus', 'qcp', 'ra', 'rmi', 's3m', 'sid', 'spx', 'thd',
+             'tta', 'voc', 'vqf', 'w64', 'wav', 'wma', 'wv', 'xa', 'xm')
 
-VIDEO_EXT = ['*.3g2', '*.3gp', '*.3gp2', '*.3gpp', '*.amv', '*.asf', '*.avi', '*.bik', '*.divx', '*.drc', '*.dv',
-             '*.f4v', '*.flv', '*.gvi', '*.gxf', '*.iso', '*.m1v', '*.m2v', '*.m2t', '*.m2ts', '*.m4v', '*.mkv',
-             '*.mov', '*.mp2', '*.mp2v', '*.mp4', '*.mp4v', '*.mpe', '*.mpeg', '*.mpeg1', '*.mpeg2', '*.mpeg4', '*.mpg',
-             '*.mpv2', '*.mts', '*.mtv', '*.mxf', '*.mxg', '*.nsv', '*.nuv', '*.ogg', '*.ogm', '*.ogv', '*.ogx', '*.ps',
-             '*.rec', '*.rm', '*.rmvb', '*.rpl', '*.thp', '*.tod', '*.ts', '*.tts', '*.txd', '*.vob', '*.vro', '*.webm',
-             '*.wm', '*.wmv', '*.wtv', '*.xesc',
+VIDEO_EXT = ('3g2', '3gp', '3gp2', '3gpp', 'amv', 'asf', 'avi', 'bik', 'divx', 'drc', 'dv', 'f4v', 'flv', 'gvi', 'gxf',
+             'iso', 'm1v', 'm2v', 'm2t', 'm2ts', 'm4v', 'mkv', 'mov', 'mp2', 'mp2v', 'mp4', 'mp4v', 'mpe', 'mpeg',
+             'mpeg1', 'mpeg2', 'mpeg4', 'mpg', 'mpv2', 'mts', 'mtv', 'mxf', 'mxg', 'nsv', 'nuv', 'ogg', 'ogm', 'ogv',
+             'ogx', 'ps', 'rec', 'rm', 'rmvb', 'rpl', 'thp', 'tod', 'ts', 'tts', 'txd', 'vob', 'vro', 'webm', 'wm',
+             'wmv', 'wtv', 'xesc',
              # These extensions was not in the official list, added manually.
-             '*.nut', '*.rv', '*.xvid']
+             'nut', 'rv', 'xvid')
 
 
 def get_vlc():
@@ -109,8 +106,6 @@
         self.display_name = '&VLC'
         self.parent = parent
         self.can_folder = True
-        self.audio_extensions_list = AUDIO_EXT
-        self.video_extensions_list = VIDEO_EXT
 
     def setup(self, output_display, live_display):
         """
@@ -374,14 +369,3 @@
             else:
                 controller.seek_slider.setSliderPosition(output_display.vlc_media_player.get_time())
             controller.seek_slider.blockSignals(False)
-
-    def get_info(self):
-        """
-        Return some information about this player
-        """
-        return(translate('Media.player', 'VLC is an external player which '
-               'supports a number of different formats.') +
-               '<br/> <strong>' + translate('Media.player', 'Audio') +
-               '</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>' +
-               translate('Media.player', 'Video') + '</strong><br/>' +
-               str(VIDEO_EXT) + '<br/>')

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2019-05-24 18:50:51 +0000
+++ openlp/core/ui/servicemanager.py	2019-05-31 20:34:31 +0000
@@ -320,7 +320,7 @@
         """
         super().__init__(parent)
         self.service_items = []
-        self.suffixes = []
+        self.suffixes = set()
         self.drop_position = -1
         self.service_id = 0
         # is a new service and has not been saved
@@ -403,20 +403,18 @@
         Resets the Suffixes list.
 
         """
-        self.suffixes = []
+        self.suffixes.clear()
 
     def supported_suffixes(self, suffix_list):
         """
         Adds Suffixes supported to the master list. Called from Plugins.
 
-        :param suffix_list: New Suffix's to be supported
+        :param list[str] | str suffix_list: New suffix(s) to be supported
         """
         if isinstance(suffix_list, str):
-            self.suffixes.append(suffix_list)
+            self.suffixes.add(suffix_list)
         else:
-            for suffix in suffix_list:
-                if suffix not in self.suffixes:
-                    self.suffixes.append(suffix)
+            self.suffixes.update(suffix_list)
 
     def on_new_service_clicked(self):
         """
@@ -475,9 +473,11 @@
                                               QtWidgets.QMessageBox.Save | QtWidgets.QMessageBox.Discard |
                                               QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Save)
 
-    def on_recent_service_clicked(self):
+    def on_recent_service_clicked(self, checked):
         """
         Load a recent file as the service triggered by mainwindow recent service list.
+
+        :param bool checked: Not used
         """
         if self.is_modified():
             result = self.save_modified_service()

=== modified file 'openlp/core/ui/themeform.py'
--- openlp/core/ui/themeform.py	2019-05-22 06:47:00 +0000
+++ openlp/core/ui/themeform.py	2019-05-31 20:34:31 +0000
@@ -32,7 +32,6 @@
 from openlp.core.common.registry import Registry
 from openlp.core.lib.theme import BackgroundGradientType, BackgroundType
 from openlp.core.lib.ui import critical_error_message_box
-# TODO: Fix this. Use a "get_video_extensions" method which uses the current media player
 from openlp.core.ui.media.vlcplayer import VIDEO_EXT
 from openlp.core.ui.themelayoutform import ThemeLayoutForm
 from openlp.core.ui.themewizard import Ui_ThemeWizard
@@ -76,9 +75,8 @@
         self.image_path_edit.filters = \
             '{name};;{text} (*)'.format(name=get_images_filter(), text=UiStrings().AllFiles)
         self.image_path_edit.pathChanged.connect(self.on_image_path_edit_path_changed)
-        # TODO: Should work
-        visible_formats = '({name})'.format(name='; '.join(VIDEO_EXT))
-        actual_formats = '({name})'.format(name=' '.join(VIDEO_EXT))
+        visible_formats = '(*.{name})'.format(name='; *.'.join(VIDEO_EXT))
+        actual_formats = '(*.{name})'.format(name=' *.'.join(VIDEO_EXT))
         video_filter = '{trans} {visible} {actual}'.format(trans=translate('OpenLP', 'Video Files'),
                                                            visible=visible_formats, actual=actual_formats)
         self.video_path_edit.filters = '{video};;{ui} (*)'.format(video=video_filter, ui=UiStrings().AllFiles)

=== modified file 'openlp/plugins/media/lib/mediaitem.py'
--- openlp/plugins/media/lib/mediaitem.py	2019-05-03 17:26:37 +0000
+++ openlp/plugins/media/lib/mediaitem.py	2019-05-31 20:34:31 +0000
@@ -38,7 +38,7 @@
 from openlp.core.lib.ui import critical_error_message_box
 from openlp.core.ui.icons import UiIcons
 from openlp.core.ui.media import parse_optical_path, format_milliseconds
-from openlp.core.ui.media.vlcplayer import get_vlc
+from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, get_vlc
 
 
 if get_vlc() is not None:
@@ -232,9 +232,9 @@
         """
         # self.populate_display_types()
         self.on_new_file_masks = translate('MediaPlugin.MediaItem',
-                                           'Videos ({video});;Audio ({audio});;{files} '
-                                           '(*)').format(video=' '.join(self.media_controller.video_extensions_list),
-                                                         audio=' '.join(self.media_controller.audio_extensions_list),
+                                           'Videos (*.{video});;Audio (*.{audio});;{files} '
+                                           '(*)').format(video=' *.'.join(VIDEO_EXT),
+                                                         audio=' *.'.join(AUDIO_EXT),
                                                          files=UiStrings().AllFiles)
 
     def on_delete_click(self):
@@ -301,9 +301,9 @@
         media_file_paths = Settings().value(self.settings_section + '/media files')
         media_file_paths.sort(key=lambda file_path: get_natural_key(file_path.name))
         if media_type == MediaType.Audio:
-            extension = self.media_controller.audio_extensions_list
+            extension = AUDIO_EXT
         else:
-            extension = self.media_controller.video_extensions_list
+            extension = VIDEO_EXT  # TODO: Rename extension to extensions
         extension = [x[1:] for x in extension]
         media = [x for x in media_file_paths if x.suffix in extension]
         return media

=== modified file 'tests/functional/openlp_core/common/test_path.py'
--- tests/functional/openlp_core/common/test_path.py	2019-05-23 19:49:13 +0000
+++ tests/functional/openlp_core/common/test_path.py	2019-05-31 20:34:31 +0000
@@ -22,7 +22,6 @@
 """
 Package to test the openlp.core.common.path package.
 """
-# TODO: fix patches
 import os
 from pathlib import Path
 from unittest import TestCase

=== modified file 'tests/functional/openlp_core/ui/media/test_mediacontroller.py'
--- tests/functional/openlp_core/ui/media/test_mediacontroller.py	2019-04-13 13:00:22 +0000
+++ tests/functional/openlp_core/ui/media/test_mediacontroller.py	2019-05-31 20:34:31 +0000
@@ -27,7 +27,6 @@
 
 from openlp.core.common.registry import Registry
 from openlp.core.ui.media.mediacontroller import MediaController
-from openlp.core.ui.media.vlcplayer import VlcPlayer
 from tests.helpers.testmixin import TestMixin
 
 from tests.utils.constants import RESOURCE_PATH
@@ -43,26 +42,6 @@
         Registry.create()
         Registry().register('service_manager', MagicMock())
 
-    def test_generate_extensions_lists(self):
-        """
-        Test that the extensions are create correctly
-        """
-        # GIVEN: A MediaController and an active player with audio and video extensions
-        media_controller = MediaController()
-        media_controller.vlc_player = VlcPlayer(None)
-        media_controller.vlc_player.is_active = True
-        media_controller.vlc_player.audio_extensions_list = ['*.mp3', '*.wav', '*.wma', '*.ogg']
-        media_controller.vlc_player.video_extensions_list = ['*.mp4', '*.mov', '*.avi', '*.ogm']
-
-        # WHEN: calling _generate_extensions_lists
-        media_controller._generate_extensions_lists()
-
-        # THEN: extensions list should have been copied from the player to the mediacontroller
-        assert media_controller.video_extensions_list == media_controller.video_extensions_list, \
-            'Video extensions should be the same'
-        assert media_controller.audio_extensions_list == media_controller.audio_extensions_list, \
-            'Audio extensions should be the same'
-
     def test_resize(self):
         """
         Test that the resize method is called correctly

=== modified file 'tests/functional/openlp_core/ui/media/test_vlcplayer.py'
--- tests/functional/openlp_core/ui/media/test_vlcplayer.py	2019-05-08 13:58:06 +0000
+++ tests/functional/openlp_core/ui/media/test_vlcplayer.py	2019-05-31 20:34:31 +0000
@@ -30,7 +30,7 @@
 
 from openlp.core.common.registry import Registry
 from openlp.core.ui.media import MediaState, MediaType
-from openlp.core.ui.media.vlcplayer import AUDIO_EXT, VIDEO_EXT, VlcPlayer, get_vlc
+from openlp.core.ui.media.vlcplayer import VlcPlayer, get_vlc
 from tests.helpers import MockDateTime
 from tests.helpers.testmixin import TestMixin
 
@@ -95,8 +95,6 @@
         assert '&VLC' == vlc_player.display_name
         assert vlc_player.parent is None
         assert vlc_player.can_folder is True
-        assert AUDIO_EXT == vlc_player.audio_extensions_list
-        assert VIDEO_EXT == vlc_player.video_extensions_list
 
     @patch('openlp.core.ui.media.vlcplayer.is_win')
     @patch('openlp.core.ui.media.vlcplayer.is_macosx')
@@ -958,20 +956,3 @@
         mocked_controller.seek_slider.setSliderPosition.assert_called_with(300)
         expected_calls = [call(True), call(False)]
         assert expected_calls == mocked_controller.seek_slider.blockSignals.call_args_list
-
-    @patch('openlp.core.ui.media.vlcplayer.translate')
-    def test_get_info(self, mocked_translate):
-        """
-        Test that get_info() returns some information about the VLC player
-        """
-        # GIVEN: A VlcPlayer
-        mocked_translate.side_effect = lambda *x: x[1]
-        vlc_player = VlcPlayer(None)
-
-        # WHEN: get_info() is run
-        info = vlc_player.get_info()
-
-        # THEN: The information should be correct
-        assert 'VLC is an external player which supports a number of different formats.<br/> ' \
-            '<strong>Audio</strong><br/>' + str(AUDIO_EXT) + '<br/><strong>Video</strong><br/>' + \
-               str(VIDEO_EXT) + '<br/>' == info


Follow ups