コード例 #1
0
ファイル: player.py プロジェクト: freevo/freevo2
def GetItem(playerid, properties):
    """
    JsonRPC Callback Player.GetItem
    """
    app = freevo.taskmanager.applications[-1]
    if not 'type' in properties:
        properties.append('type')
    result = utils.fill_basic_item_properties(app.item, properties)
    result['id'] = 0
    for prop in properties:
        if prop == 'streamdetails':
            value = {
                'audio': [],
                'subtitle': [],
                'video': [] }
            if app.name == 'videoplayer':
                for a in app.item.metadata.audio:
                    value['audio'].append(utils.fill_audio_details(a))
                for s in app.item.metadata.subtitles:
                    value['subtitle'].append(utils.fill_subtitle_details(s))
                for v in app.item.metadata.video:
                    value['video'].append({'aspect': v.aspect, 'duration': int(app.item.metadata.length),
                                           'height': v.height, 'width': v.width, 'stereomode': '',
                                           'codec': v.codec.lower().replace('h.264 avc', 'h264')})
        elif prop == 'playcount':
            value = 0     # FIXME
        elif prop == 'resume':
            value = {
                'position': 0.0,
                'total': 0.0 }  # FIXME
        else:
            log.error('no support for %s' % prop)
            continue
        result[prop] = value
    return {'item': result }
コード例 #2
0
ファイル: videolibrary.py プロジェクト: pacificIT/freevo2
def _fill_movie_details(f, properties):
    """
    Helper function to provide episode details
    """
    info = {
        'movieid': f._beacon_id[1],
        'label': f.get('title')
    }
    # it kind of sucks, but we have to ask kaa.(web)metadata again for
    # each movie to get the details.
    metadata = kaa.metadata.parse(f.url[7:])
    webmetadata = kaa.webmetadata.parse(f.url[7:], metadata)
    for prop in properties:
        if prop == 'title':
            info[prop] = f.get('title')
        elif prop == 'thumbnail':
            info[prop] = utils.register_image(f.get('poster'), f)
        elif prop in ('rating',):
            info[prop] = 0.0
        elif prop == 'file':
            info[prop] = f.url
        elif prop == 'plot':
            info[prop] = f.get('description')
        elif prop in ('playcount', 'setid'):
            info[prop] = 0
        elif prop == 'resume':
            info[prop] =  { 'position': 0, 'total': 0 }
        elif prop == 'set':
            info[prop] = ''
        elif prop == 'fanart':
            info[prop] = utils.register_image((webmetadata and webmetadata.image) or '')
        elif prop == 'imdbnumber':
            info[prop] = (webmetadata and webmetadata.imdb) or ''
        elif prop == 'genre':
            info[prop] = (webmetadata and webmetadata.genre) or []
        elif prop == 'year':
            info[prop] = (webmetadata and webmetadata.year) or 0
        elif prop == 'runtime':
            info[prop] = f.get('length')
        elif prop in ('firstaired', 'dateadded', 'originaltitle', 'sorttitle', 'trailer'):
            info[prop] = ''
        elif prop in ('cast', 'mpaa', 'studio', 'director', 'tag'):
            info[prop] = []
        elif prop == 'streamdetails':
            info[prop] = {
                'audio': [],
                'subtitle': [],
                'video': [] }
            if metadata:
                for v in metadata.video:
                    info[prop]['video'].append(utils.fill_video_details(v, metadata))
                for a in metadata.audio:
                    info[prop]['audio'].append(utils.fill_audio_details(a))
                for s in metadata.subtitles:
                    info[prop]['subtitle'].append(utils.fill_subtitle_details(s))
        else:
            log.error('no support for %s' % prop)
            info[prop] = ''
    return info
コード例 #3
0
def GetItem(playerid, properties):
    """
    JsonRPC Callback Player.GetItem
    """
    app = freevo.taskmanager.applications[-1]
    if not 'type' in properties:
        properties.append('type')
    result = utils.fill_basic_item_properties(app.item, properties)
    result['id'] = 0
    for prop in properties:
        if prop == 'streamdetails':
            value = {
                'audio': [],
                'subtitle': [],
                'video': [] }
            if app.name == 'videoplayer':
                for a in app.item.metadata.audio:
                    value['audio'].append(utils.fill_audio_details(a))
                for s in app.item.metadata.subtitles:
                    value['subtitle'].append(utils.fill_subtitle_details(s))
                for v in app.item.metadata.video:
                    value['video'].append({'aspect': v.aspect, 'duration': int(app.item.metadata.length),
                                           'height': v.height, 'width': v.width, 'stereomode': '',
                                           'codec': v.codec.lower().replace('h.264 avc', 'h264')})
        elif prop == 'playcount':
            value = 0     # FIXME
        elif prop == 'art':
            value = {}
            if app.item.get('series') and app.item.get('episode'):
                series = app.item.get('series')
                series = kaa.webmetadata.tv.series(series)
                if series:
                    if series.banner:
                        value['tvshow.banner'] = utils.register_image(series.banner)
                    if series.image:
                        value['tvshow.fanart'] = utils.register_image(series.image)
                    if series.poster:
                        value['tvshow.poster'] = utils.register_image(series.poster)
            thumb = app.item.get('image')
            if thumb:
                value['thumb'] = utils.register_image(thumb, app.item)
            print value
        else:
            log.error('no support for %s' % prop)
            value = ''
        result[prop] = value
    return {'item': result }
コード例 #4
0
ファイル: videolibrary.py プロジェクト: pacificIT/freevo2
def GetEpisodeDetails(episodeid, properties):
    """
    JsonRPC Callback VideoLibrary.GetEpisodeDetails
    """
    result = (yield kaa.beacon.query(id=episodeid, type='video'))
    if len(result) != 1:
        log.error('bad query')
        yield {}
    details = _fill_episode_details(result[0], properties)
    if 'streamdetails' in properties:
        metadata = kaa.metadata.parse(result[0].url)
        value = {
            'audio': [],
            'subtitle': [],
            'video': [] }
        if metadata:
            for v in metadata.video:
                value['video'].append(utils.fill_video_details(v, metadata))
            for a in metadata.audio:
                value['audio'].append(utils.fill_audio_details(a))
            for s in metadata.subtitles:
                value['subtitle'].append(utils.fill_subtitle_details(s))
        details['streamdetails'] = value
    yield {'episodedetails': details}
コード例 #5
0
ファイル: player.py プロジェクト: freevo/freevo2
def GetProperties(playerid, properties):
    """
    JsonRPC Callback Player.GetProperties
    """
    app = freevo.taskmanager.applications[-1]
    result = {}
    for prop in properties:
        if prop == 'audiostreams':
            result[prop] = []
            if app.name in 'videoplayer':
                if app.item.metadata.audio:
                    for a in app.item.metadata.audio:
                        result[prop].append(utils.fill_audio_details(a))
                else:
                    log.error('no audio stream')
            elif app.name in 'audioplayer':
                result[prop].append(utils.fill_audio_details(app.item.metadata))
            elif app.name not in ('imageviewer',):
                log.error('no audio stream')
        elif prop == 'canseek':
            result[prop] = True
        elif prop == 'currentaudiostream':
            result[prop] = {}
            if app.name == 'videoplayer' and app.item.metadata.audio:
                result[prop] = utils.fill_audio_details(app.item.metadata.audio[0])
                if app.player.streaminfo.get('current-audio') is not None:
                    idx = app.player.streaminfo.get('current-audio')
                    if len(app.item.metadata.audio) > idx:
                        result[prop] = utils.fill_audio_details(app.item.metadata.audio[idx])
            elif app.name in 'audioplayer':
                result[prop] = utils.fill_audio_details(app.item.metadata)
            elif app.name not in ('imageviewer',):
                log.error('no audio stream')
        elif prop == 'currentsubtitle':
            result[prop] = {}
            if app.name == 'videoplayer' and app.player.streaminfo.get('current-subtitle') is not None:
                idx = app.player.streaminfo.get('current-subtitle')
                if idx >= 0 and len(app.item.metadata.subtitles) > idx:
                    result[prop] = utils.fill_subtitle_details(app.item.metadata.subtitles[idx])
                elif idx >= 0:
                    log.error('subtitle out of range')
        elif prop == 'partymode':
            result[prop] = False
        elif prop == 'playlistid':
            result[prop] = 1    # FIXME
        elif prop == 'position':
            result[prop] = -1    # FIXME
        elif prop == 'playcount':
            result[prop] = 0     # FIXME
        elif prop == 'repeat':
            result[prop] = 'off'
        elif prop == 'shuffled':
            result[prop] = False
        elif prop == 'speed':
            if _is_playing(app):
                result[prop] = 1
            else:
                result[prop] = 0
        elif prop == 'subtitleenabled':
            if app.name == 'videoplayer' and app.player.streaminfo.get('current-subtitle') is not None:
                result[prop] = True
            else:
                result[prop] = False
        elif prop == 'subtitles':
            result[prop] = []
            if app.name == 'videoplayer':
                for s in app.item.metadata.subtitles:
                    result[prop].append(utils.fill_subtitle_details(s))
        elif prop in ('time', 'totaltime'):
            item = getattr(app, 'item', None)
            if not item:
                val = 0
            elif prop == 'time':
                val = item.get('elapsed_secs') or 0
            else:
                val = item.info.get('length') or item.get('elapsed_secs') or 0
            result[prop] = {
                'hours': int(val) / 3600,
                'minutes': (int(val) / 60) % 60,
                'seconds': int(val) % 60,
                'milliseconds': int(val * 1000) % 1000}
        elif prop == 'percentage':
            result[prop] = 0
            item = getattr(app, 'item', None)
            if item:
                tcur = item.get('elapsed_secs') or 0
                tlen = item.info.get('length') or item.get('elapsed_secs') or 0
                if tcur and tlen:
                    result[prop] = (tcur * 100) / tlen
        elif prop == 'type':
            if app.name == 'videoplayer':
                if item.get('series') and item.get('episode'):
                    result[prop] = 'episode'
                else:
                    result[prop] = 'video'
            elif app.name == 'audioplayer':
                result[prop] = 'song'
            elif app.name == 'imageviewer':
                result[prop] = 'picture'
            else:
                raise AttributeError('unsupported application')
        else:
            raise AttributeError('unsupported property: %s' % prop)
    return result
コード例 #6
0
ファイル: videolibrary.py プロジェクト: freevo/freevo2
def _fill_episode_details(f, properties, metadata=None):
    """
    Helper function to provide episode details
    """
    info = {
        'episodeid': f._beacon_id[1],
        'label': '%s %sx%02d - %s' % (f.get('series'), f.get('season'), f.get('episode'), f.get('title'))
    }
    for prop in properties:
        if prop == 'season':
            info[prop] = f.get('season') or 0
        elif prop == 'episode':
            info[prop] = f.get('episode') or 0
        elif prop == 'showtitle':
            info[prop] = f.get('series') or ''
        elif prop == 'title':
            info[prop] = f.get('title') or ''
        elif prop == 'thumbnail':
            info[prop] = utils.register_image(f.thumbnail, f)
        elif prop in ('rating',):
            info[prop] = 0.0
        elif prop == 'file':
            info[prop] = f.url
        elif prop == 'plot':
            info[prop] = f.get('description') or ''
        elif prop == 'playcount':
            info[prop] = 0
        elif prop == 'resume':
            info[prop] =  { 'position': 0.0, 'total': 0.0 }
        elif prop in ('firstaired', 'dateadded', 'originaltitle', 'lastplayed'):
            info[prop] = ''
        elif prop in ('cast', ):
            info[prop] = []
        elif prop == 'streamdetails':
            info[prop] = {
                'audio': [],
                'subtitle': [],
                'video': [] }
            if metadata and 0:
                for v in metadata.video:
                    info[prop]['video'].append(utils.fill_video_details(v, metadata))
                for a in metadata.audio:
                    info[prop]['audio'].append(utils.fill_audio_details(a))
                for s in metadata.subtitles:
                    info[prop]['subtitle'].append(utils.fill_subtitle_details(s))
            else:
                info[prop]['video'].append({
                    'height': 720,
                    'width': 1280,
                    'aspect': 16.0/9,
                    'codec': 'h264',
                    'duration': 1290,
                    'stereomode': '',
                })
                info[prop]['audio'].append({
                    'channels': 6,
                    'codec': 'ac3',
                    'language': '',
                })
        elif prop in ('tvshowid', 'specialsortepisode', 'specialsortseason'):
            info[prop] = -1
        else:
            log.error('no support for %s' % prop)
            info[prop] = ''
    return info