Example #1
0
    def _add_editcontrol(self, x, y, height, width, password=False):

        kwargs = dict(label="User",
                      font="font13",
                      textColor="FF00A4DC",
                      disabledColor="FF888888",
                      focusTexture="-",
                      noFocusTexture="-")

        # TODO: Kodi 17 compat removal cleanup
        if kodi_version() < 18:
            kwargs['isPassword'] = password

        control = xbmcgui.ControlEdit(0, 0, 0, 0, **kwargs)

        control.setPosition(x, y)
        control.setHeight(height)
        control.setWidth(width)

        self.addControl(control)

        # setType has no effect before the control is added to a window
        # TODO: Kodi 17 compat removal cleanup
        if password and not kodi_version() < 18:
            control.setType(xbmcgui.INPUT_TYPE_PASSWORD,
                            "Please enter password")

        return control
Example #2
0
def manage_libraries():

    directory(_(33098), "plugin://plugin.video.emby/?mode=refreshboxsets", False)
    directory(_(33154), "plugin://plugin.video.emby/?mode=addlibs", False)
    directory(_(33139), "plugin://plugin.video.emby/?mode=updatelibs", False)
    directory(_(33140), "plugin://plugin.video.emby/?mode=repairlibs", False)
    directory(_(33184), "plugin://plugin.video.emby/?mode=removelibs", False)
    directory(_(33060), "plugin://plugin.video.emby/?mode=thememedia", False)

    if kodi_version() >= 18:
        directory(_(33202), "plugin://plugin.video.emby/?mode=patchmusic", False)

    xbmcplugin.setContent(int(sys.argv[1]), 'files')
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Example #3
0
    def patch_music(self, notification=False):
        ''' Patch the music database to silence the rescan prompt.
        '''
        if kodi_version() < 18:
            LOG.info("version not supported for patching music db.")
            return

        with self.library.database_lock:
            with Database('music') as musicdb:
                self.library.kodi_media['Music'](
                    musicdb.cursor).disable_rescan(
                        musicdb.path.split('MyMusic')[1].split('.db')[0], 0)

        settings('MusicRescan.bool', True)

        if notification:
            dialog("notification",
                   heading="{emby}",
                   message=_('task_success'),
                   icon="{emby}",
                   time=1000,
                   sound=False)
Example #4
0
    def play(self, transcode=False):

        if kodi_version() > 17:
            path = "http://127.0.0.1:57578/emby/play/file.strm?mode=play&Id=%s" % self.item[
                'Id']

            if self.kodi_id:
                path += "&KodiId=%s" % self.kodi_id

            if self.media:
                path += "&MediaType=%s" % self.media
        else:
            path = "plugin://plugin.video.emby?mode=play&id=%s" % self.item[
                'Id']

        if transcode:
            path += "&transcode=true"

        if self.server:
            path += "&server=%s" % self.server_id

        xbmc.executebuiltin("PlayMedia(%s)" % path)
Example #5
0
def browse(media, view_id=None, folder=None, server_id=None):

    ''' Browse content dynamically.
    '''
    LOG.info("--[ v:%s/%s ] %s", view_id, media, folder)
    get_server(server_id)

    folder = folder.lower() if folder else None

    if folder is None and media in ('homevideos', 'movies', 'books', 'audiobooks'):
        return browse_subfolders(media, view_id, server_id)

    if folder and folder == 'firstletter':
        return browse_letters(media, view_id, server_id)

    if view_id:

        view = EMBY['api'].get_item(view_id)
        xbmcplugin.setPluginCategory(int(sys.argv[1]), view['Name'])

    content_type = "files"

    if media in ('tvshows', 'seasons', 'episodes', 'movies', 'musicvideos', 'songs', 'albums'):
        content_type = media
    elif media in ('homevideos', 'photos'):
        content_type = "images"
    elif media in ('books', 'audiobooks'):
        content_type = "videos"
    elif media == 'music':
        content_type = "artists"


    if folder == 'recentlyadded':
        listing = EMBY['api'].get_recently_added(None, view_id, None)
    elif folder == 'genres':
        listing = EMBY['api'].get_genres(view_id)
    elif media == 'livetv':
        listing = EMBY['api'].get_channels()
    elif folder == 'unwatched':
        listing = downloader.get_filtered_section(view_id, None, None, None, None, None, ['IsUnplayed'], None, server_id)
    elif folder == 'favorite':
        listing = downloader.get_filtered_section(view_id, None, None, None, None, None, ['IsFavorite'], None, server_id)
    elif folder == 'inprogress':
        listing = downloader.get_filtered_section(view_id, None, None, None, None, None, ['IsResumable'], None, server_id)
    elif folder == 'boxsets':
        listing = downloader.get_filtered_section(view_id, get_media_type('boxsets'), None, True, None, None, None, None, server_id)
    elif folder == 'random':
        listing = downloader.get_filtered_section(view_id, get_media_type(content_type), 25, True, "Random", None, None, None, server_id)
    elif (folder or "").startswith('firstletter-'):
        listing = downloader.get_filtered_section(view_id, get_media_type(content_type), None, None, None, None, None, {'NameStartsWith': folder.split('-')[1]}, server_id)
    elif (folder or "").startswith('genres-'):
        listing = downloader.get_filtered_section(view_id, get_media_type(content_type), None, None, None, None, None, {'GenreIds': folder.split('-')[1]}, server_id)
    elif folder == 'favepisodes':
        listing = downloader.get_filtered_section(None, get_media_type(content_type), 25, None, None, None, ['IsFavorite'], None, server_id)
    elif media == 'homevideos':
        listing = downloader.get_filtered_section(folder or view_id, get_media_type(content_type), None, False, None, None, None, None, server_id)
    elif media == 'movies':
        listing = downloader.get_filtered_section(folder or view_id, get_media_type(content_type), None, True, None, None, None, None, server_id)
    elif media in ('boxset', 'library'):
        listing = downloader.get_filtered_section(folder or view_id, None, None, True, None, None, None, None, server_id)
    elif media == 'episodes':
        listing = downloader.get_filtered_section(folder or view_id, get_media_type(content_type), None, True, None, None, None, None, server_id)
    elif media == 'boxsets':
        listing = downloader.get_filtered_section(folder or view_id, None, None, False, None, None, ['Boxsets'], None, server_id)
    elif media == 'tvshows':
        listing = downloader.get_filtered_section(folder or view_id, get_media_type(content_type), None, True, None, None, None, None, server_id)
    elif media == 'seasons':
        listing = EMBY['api'].get_seasons(folder)
    elif media != 'files':
        listing = downloader.get_filtered_section(folder or view_id, get_media_type(content_type), None, False, None, None, None, None, server_id)
    else:
        listing = downloader.get_filtered_section(folder or view_id, None, None, False, None, None, None, None, server_id)


    if listing:

        listitems = objects.ListItem(EMBY['auth/server-address'])
        list_li = []
        listing = listing if type(listing) == list else listing.get('Items', [])

        for item in listing:

            li = xbmcgui.ListItem()
            li.setProperty('embyid', item['Id'])
            li.setProperty('embyserver', server_id)
            li = listitems.set(item, li)

            if item.get('IsFolder'):

                params = {
                    'id': view_id or item['Id'],
                    'mode': "browse",
                    'type': get_folder_type(item, media) or media,
                    'folder': item['Id'],
                    'server': server_id
                }
                path = "%s?%s" % ("plugin://plugin.video.emby/",  urllib.urlencode(params))
                context = []

                if item['Type'] in ('Series', 'Season', 'Playlist'):
                    context.append(("Play", "RunPlugin(plugin://plugin.video.emby/?mode=playlist&id=%s&server=%s)" % (item['Id'], server_id)))

                if item['UserData']['Played']:
                    context.append((_(16104), "RunPlugin(plugin://plugin.video.emby/?mode=unwatched&id=%s&server=%s)" % (item['Id'], server_id)))
                else:
                    context.append((_(16103), "RunPlugin(plugin://plugin.video.emby/?mode=watched&id=%s&server=%s)" % (item['Id'], server_id)))

                li.addContextMenuItems(context)
                list_li.append((path, li, True))

            elif item['Type'] == 'Genre':

                params = {
                    'id': view_id or item['Id'],
                    'mode': "browse",
                    'type': get_folder_type(item, media) or media,
                    'folder': 'genres-%s' % item['Id'],
                    'server': server_id
                }
                path = "%s?%s" % ("plugin://plugin.video.emby/",  urllib.urlencode(params))
                list_li.append((path, li, True))

            else:
                if item['Type'] == 'Photo' and CONTENT_TYPE == 'video':

                    path = "plugin://plugin.video.emby/?mode=photoviewer&id=%s" % item['Id']
                    li.setProperty('path', path)

                elif item['Type'] not in ('PhotoAlbum', 'Photo'):

                    if kodi_version() > 17:
                        path = "http://127.0.0.1:57578/emby/play/file.strm?mode=play&Id=%s&server=%s" % (item['Id'], server_id)
                    else:
                        params = {
                            'id': item['Id'],
                            'mode': "play",
                            'server': server_id
                        }
                        path = "%s?%s" % ("plugin://plugin.video.emby/", urllib.urlencode(params))
                    
                    li.setProperty('path', path)
                    context = [(_(13412), "RunPlugin(plugin://plugin.video.emby/?mode=playlist&id=%s&server=%s)" % (item['Id'], server_id))]

                    if item['UserData']['Played']:
                        context.append((_(16104), "RunPlugin(plugin://plugin.video.emby/?mode=unwatched&id=%s&server=%s)" % (item['Id'], server_id)))
                    else:
                        context.append((_(16103), "RunPlugin(plugin://plugin.video.emby/?mode=watched&id=%s&server=%s)" % (item['Id'], server_id)))

                    li.addContextMenuItems(context)

                list_li.append((li.getProperty('path'), li, False))

        xbmcplugin.addDirectoryItems(int(sys.argv[1]), list_li, len(list_li))

    if content_type == 'images':
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_YEAR)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING)
        xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)

    xbmcplugin.setContent(int(sys.argv[1]), content_type)
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
Example #6
0
    def onPlayBackStarted(self):
        ''' We may need to wait for info to be set in kodi monitor.
            Accounts for scenario where Kodi starts playback and exits immediately.
            First, ensure previous playback terminated correctly in Emby.
        '''
        LOG.info("[ onPlayBackStarted ]")
        self.up_next = False

        try:
            current_file = self.get_current_file(5)
        except Exception as error:
            LOG.error(error)

            return

        self.stop_playback()
        items = window('emby_play.json')
        item = None
        count = 0

        while not items:

            if self.monitor.waitForAbort(2):
                return

            items = window('emby_play.json')
            count += 1

            if count == 20:
                LOG.info("Could not find emby prop...")

                return

        for item in items:
            if item['Path'] == current_file.decode('utf-8'):
                items.pop(items.index(item))

                break
        else:
            item = items.pop(0)

        window('emby_play.json', items)

        self.set_item(current_file, item)
        data = {
            'QueueableMediaTypes': "Video,Audio",
            'CanSeek': True,
            'ItemId': item['Id'],
            'MediaSourceId': item['MediaSourceId'],
            'PlayMethod': item['PlayMethod'],
            'VolumeLevel': item['Volume'],
            'PositionTicks': int(item['CurrentPosition'] * 10000000),
            'IsPaused': item['Paused'],
            'IsMuted': item['Muted'],
            'PlaySessionId': item['PlaySessionId'],
            'AudioStreamIndex': item['AudioStreamIndex'],
            'SubtitleStreamIndex': item['SubtitleStreamIndex']
        }
        item['Server']['api'].session_playing(data)
        window('emby.skip.%s.bool' % item['Id'], True)

        if self.monitor.waitForAbort(2):
            return

        if item['PlayOption'] == 'Addon' and kodi_version() < 18:
            self.set_audio_subs(item['AudioStreamIndex'],
                                item['SubtitleStreamIndex'])

        item['Track'] = True