Exemple #1
0
def pick_podcast_media_file(media):
    """Return the best choice of files to play.

    XXX: This method uses the
         :ref:`~mediacore.lib.filetypes.pick_media_file_player` method and
         comes with the same caveats.

    :param media: A :class:`~mediacore.model.media.Media` instance.
    :returns: A :class:`~mediacore.model.media.MediaFile` object or None
    """
    player = pick_media_file_player(media, browser='itunes', player_type='html5')
    return player and player.file or None
Exemple #2
0
def pick_any_media_file(media):
    """Return a file playable in at least one browser, with the current
    player_type setting, or None.

    XXX: This method uses the
         :ref:`~mediacore.lib.filetypes.pick_media_file_player` method and
         comes with the same caveats.

    :param media: A :class:`~mediacore.model.media.Media` instance.
    :returns: A :class:`~mediacore.model.media.MediaFile` object or None
    """
    player = pick_media_file_player(media, browser='chrome')
    return player and player.file or None
    def test_sizeless_file_picking(self):
        """Test while file gets served to each browser, given that all files
        are the same filesize.
        """
        media, media_files = self._get_media('unsized')

        for mf in media_files:
            media_files[mf].size = None
        DBSession.flush()

        pylons.app_globals.settings['html5_player'] = 'html5'
        pylons.app_globals.settings['flash_player'] = 'flowplayer'

        combinations = [
            # Prefer flash, without embeds
            ('firefox', 2,          'flash', False, 'flv', 'flowplayer'),
            ('firefox', 3,          'flash', False, 'flv', 'flowplayer'),
            ('firefox', 3.5,        'flash', False, 'flv', 'flowplayer'),
            ('safari', 522,         'flash', False, 'flv', 'flowplayer'),
            ('opera', 10.5,         'flash', False, 'flv', 'flowplayer'),
            ('opera', 9,            'flash', False, 'flv', 'flowplayer'),
            ('chrome', 3.0,         'flash', False, 'flv', 'flowplayer'),
            ('android', 0,          'flash', False, 'flv', 'flowplayer'),
            ('itunes', 0,           'flash', False, 'm4v', 'html5'),
            ('iphone-ipod-ipad', 0, 'flash', False, 'm4v', 'html5'),
            ('unknown', 0,          'flash', False, 'flv', 'flowplayer'),
            # Prefer flash, including embeds
            ('firefox', 2,          'flash', True, 'youtube', 'youtube'),
            ('firefox', 3,          'flash', True, 'youtube', 'youtube'),
            ('firefox', 3.5,        'flash', True, 'youtube', 'youtube'),
            ('safari', 522,         'flash', True, 'youtube', 'youtube'),
            ('opera', 10.5,         'flash', True, 'youtube', 'youtube'),
            ('opera', 9,            'flash', True, 'youtube', 'youtube'),
            ('chrome', 3.0,         'flash', True, 'youtube', 'youtube'),
            ('android', 0,          'flash', True, 'youtube', 'youtube'),
            ('itunes', 0,           'flash', True, 'm4v',     'html5'),
            ('iphone-ipod-ipad', 0, 'flash', True, 'm4v',     'html5'),
            ('unknown', 0,          'flash', True, 'youtube', 'youtube'),
            # Prefer HTML5, without embeds
            ('firefox', 2,          'best', False, 'flv', 'flowplayer'),
            ('firefox', 3,          'best', False, 'flv', 'flowplayer'),
            ('firefox', 3.5,        'best', False, 'ogv', 'html5'),
            ('safari', 522,         'best', False, 'm4v', 'html5'),
            ('opera', 10.5,         'best', False, 'ogv', 'html5'),
            ('opera', 9,            'best', False, 'flv', 'flowplayer'),
            ('chrome', 3.0,         'best', False, 'm4v', 'html5'),
            ('android', 0,          'best', False, 'm4v', 'html5'),
            ('itunes', 0,           'best', False, 'm4v', 'html5'),
            ('iphone-ipod-ipad', 0, 'best', False, 'm4v', 'html5'),
            ('unknown', 0,          'best', False, 'flv', 'flowplayer'),
            # Prefer HTML5, including embeds
            ('firefox', 2,          'best', True, 'youtube', 'youtube'),
            ('firefox', 3,          'best', True, 'youtube', 'youtube'),
            ('firefox', 3.5,        'best', True, 'ogv',     'html5'),
            ('safari', 522,         'best', True, 'm4v',     'html5'),
            ('opera', 10.5,         'best', True, 'ogv',     'html5'),
            ('opera', 9,            'best', True, 'youtube', 'youtube'),
            ('chrome', 3.0,         'best', True, 'm4v',     'html5'),
            ('android', 0,          'best', True, 'm4v',     'html5'),
            ('itunes', 0,           'best', True, 'm4v',     'html5'),
            ('iphone-ipod-ipad', 0, 'best', True, 'm4v',     'html5'),
            ('unknown', 0,          'best', True, 'youtube', 'youtube'),
            # HTML5 only, without embeds
            ('firefox', 2,          'html5', False, None,  None),
            ('firefox', 3,          'html5', False, None,  None),
            ('firefox', 3.5,        'html5', False, 'ogv', 'html5'),
            ('safari', 522,         'html5', False, 'm4v', 'html5'),
            ('opera', 10.5,         'html5', False, 'ogv', 'html5'),
            ('opera', 9,            'html5', False, None,  None),
            ('chrome', 3.0,         'html5', False, 'm4v', 'html5'),
            ('android', 0,          'html5', False, 'm4v', 'html5'),
            ('itunes', 0,           'html5', False, 'm4v', 'html5'),
            ('iphone-ipod-ipad', 0, 'html5', False, 'm4v', 'html5'),
            ('unknown', 0,          'html5', False, None, None),
            # HTML5 only, including embeds
            ('firefox', 2,          'html5', True, None,  None),
            ('firefox', 3,          'html5', True, None,  None),
            ('firefox', 3.5,        'html5', True, 'ogv', 'html5'),
            ('safari', 522,         'html5', True, 'm4v', 'html5'),
            ('opera', 10.5,         'html5', True, 'ogv', 'html5'),
            ('opera', 9,            'html5', True, None,  None),
            ('chrome', 3.0,         'html5', True, 'm4v', 'html5'),
            ('android', 0,          'html5', True, 'm4v', 'html5'),
            ('itunes', 0,           'html5', True, 'm4v', 'html5'),
            ('iphone-ipod-ipad', 0, 'html5', True, 'm4v', 'html5'),
            ('unknown', 0,          'html5', True, None, None),
        ]

        from mediacore.lib.players import players
        players = dict(players)
        players[None] = None
        media_files[None] = None

        for browser, version, p_type, embedded, e_file, e_player in combinations:
            player = pick_media_file_player(media,
                    browser = browser,
                    version = version,
                    player_type = p_type,
                    include_embedded = embedded
            )
            if player:
                file = player.file
                browser, version = player.browser
            else:
                file, browser, version = None, None, None
            print "Unsized:", browser, version, p_type, embedded, e_file, e_player
            player_class = player and player.__class__ or None
            assert player_class == players[e_player], "Expected %r but was %r" % (players[e_player], player_class)
            assert file == media_files[e_file], "Expected %r but got %r" % (media_files[e_file], file)