Exemplo n.º 1
0
def refresh_meta(video_type, old_title, imdb, alt_id, year, new_title=''):
    from metahandler import metahandlers
    __metaget__ = metahandlers.MetaData()
    search_title = new_title if new_title else old_title
    if video_type in ['tvshow', 'episode']:
        api = metahandlers.TheTVDB()
        results = api.get_matching_shows(search_title)
        search_meta = []
        for item in results:
            option = {'tvdb_id': item[0], 'title': item[1], 'imdb_id': item[2]}
            search_meta.append(option)

    else:
        search_meta = __metaget__.search_movies(search_title)
    log('search_meta: %s' % search_meta, xbmc.LOGDEBUG)

    option_list = ['%s...' % (i18n('manual_search'))]
    if search_meta:
        for option in search_meta:
            if 'year' in option and option['year'] is not None:
                disptitle = '%s (%s)' % (option['title'], option['year'])
            else:
                disptitle = option['title']
            option_list.append(disptitle)

    dialog = xbmcgui.Dialog()
    index = dialog.select(i18n('choose'), option_list)

    if index == 0:
        refresh_meta_manual(video_type, old_title, imdb, alt_id, year)
    elif index > -1:
        new_imdb_id = search_meta[index - 1]['imdb_id']
        try:
            new_tmdb_id = search_meta[index - 1]['tmdb_id']
        except:
            new_tmdb_id = ''

        # Temporary workaround for metahandlers problem:
        # Error attempting to delete from cache table: no such column: year
        if video_type == 'tvshow': year = ''

        log(search_meta[index - 1], xbmc.LOGDEBUG)
        __metaget__.update_meta(video_type,
                                old_title,
                                imdb,
                                year=year,
                                new_imdb_id=new_imdb_id,
                                new_tmdb_id=new_tmdb_id)
        xbmc.executebuiltin('Container.Refresh')
Exemplo n.º 2
0
def refresh_meta(video_type, old_title, imdb, alt_id, year, new_title=''):
    from metahandler import metahandlers
    __metaget__ = metahandlers.MetaData()
    search_title = new_title if new_title else old_title
    if video_type == 'tvshow':
        api = metahandlers.TheTVDB()
        results = api.get_matching_shows(search_title)
        search_meta = []
        for item in results:
            option = {
                'tvdb_id': item[0],
                'title': item[1],
                'imdb_id': item[2],
                'year': year
            }
            search_meta.append(option)

    else:
        search_meta = __metaget__.search_movies(search_title)
    print 'search_meta: %s' % search_meta

    option_list = ['Manual Search...']
    if search_meta:
        for option in search_meta:
            if 'year' in option:
                disptitle = '%s (%s)' % (option['title'], option['year'])
            else:
                disptitle = option['title']
            option_list.append(disptitle)
        dialog = xbmcgui.Dialog()
        index = dialog.select('Choose', option_list)

        if index == 0:
            refresh_meta_manual(video_type, old_title, imdb, alt_id, year)
        elif index > -1:
            new_imdb_id = search_meta[index - 1]['imdb_id']

            #Temporary workaround for metahandlers problem:
            #Error attempting to delete from cache table: no such column: year
            if video_type == 'tvshow': year = ''

            _1CH.log(search_meta[index - 1])
            __metaget__.update_meta(video_type, old_title, imdb, year=year)
            xbmc.executebuiltin('Container.Refresh')
Exemplo n.º 3
0
def updateMeta(params):
    if not cConfig().getSetting('metahandler') == 'true':
        return
    #videoType, name, imdbID, season=season, episode=episode, year=year, watched=watched
    try:
        from metahandler import metahandlers
    except Exception as e:
        logger.info("Could not import package 'metahandler'")
        logger.info(e)
        return
    meta = metahandlers.MetaData()
    season = ''
    episode = ''
    mediaType = params.getValue('mediaType')
    imdbID = params.getValue('imdbID')
    name = str(params.getValue('title'))
    year = params.getValue('year')
    print "MedienType: " + mediaType
    if (mediaType == 'movie' or mediaType == 'tvshow'):
        # show meta search input
        oGui = cGui()
        sSearchText = oGui.showKeyBoard(name)
        if (sSearchText != False and sSearchText != ''):
            if mediaType == 'movie':
                try:
                    foundInfo = meta.search_movies(sSearchText)
                except:
                    logger.info('error or nothing found')
                    foundInfo = False
            elif mediaType == 'tvshow':
                foundInfo = metahandlers.TheTVDB().get_matching_shows(
                    sSearchText, language="all")
            else:
                return
        else:
            return
        if not foundInfo:
            oGui.showInfo('xStream', 'Suchanfrage lieferte kein Ergebnis')
            return
        # select possible match
        dialog = xbmcgui.Dialog()
        items = []
        for item in foundInfo:
            if mediaType == 'movie':
                items.append(
                    str(item['title'].encode('utf-8')) + ' (' +
                    str(item['year']) + ')')
            elif mediaType == 'tvshow':
                items.append(str(item[1]))
            else:
                return
        index = dialog.select('Film/Serie wählen', items)
        if index > -1:
            item = foundInfo[index]
        else:
            return False

    if not imdbID:
        imdbID = ''
    if not year:
        year = ''
    if mediaType == 'movie':
        meta.update_meta(mediaType,
                         name,
                         imdbID,
                         new_imdb_id=str(item['imdb_id']),
                         new_tmdb_id=str(item['tmdb_id']),
                         year=year)
    elif mediaType == 'tvshow':
        if params.exist('season'):
            season = params.getValue('season')
            meta.update_season(name, imdbID, season)
        if params.exist('episode'):
            episode = params.getValue('episode')
        if season and episode:
            meta.update_episode_meta(name, imdbID, season, episode)
        elif season:
            meta.update_season(name, imdbID, season)
        else:
            meta.update_meta(mediaType,
                             name,
                             imdbID,
                             new_imdb_id=str(item[2]),
                             new_tmdb_id=str(item[0]),
                             year=year)
    #print params.getAllParameters()
    xbmc.executebuiltin("XBMC.Container.Refresh")
    return
Exemplo n.º 4
0
def makeXbmcMenu(addon_handle, base_url, menuContent):
    import xbmc
    import xbmcgui
    import xbmcplugin
    import xbmcaddon
    from metahandler import metahandlers
    
    mg = metahandlers.MetaData()
    tv = metahandlers.TheTVDB()
    media = ''
    viewMode = ''
    for elem in menuContent:
        urlTags, parameters, otherParam = elem[0], elem[1], elem[2]
        otherParam = otherParam or {}
        isFolder = parameters.pop('isFolder')
        if otherParam.has_key('viewMode'):
            viewMode = otherParam['viewMode']
        addonInfo = None
        while otherParam.has_key('addonInfo'):
            meta = otherParam['addonInfo']
            media, metaregexp = meta.partition('*')[0:3:2]
            metaKwargs = re.match(metaregexp ,parameters['label'].replace(u'\u2019',"'"))
            if not metaKwargs: break
            kwargs = metaKwargs.groupdict().copy()
            if media in ['movie', 'tvshow']:
                name = kwargs['name']
                try: 
                    addonInfo = mg.get_meta(media, **kwargs)
                except:
                    break
                else:
                    if not addonInfo['imdb_id'] and media == 'tvshow':
                        showList = tv.get_matching_shows(name)
                        if showList:
                            kwargs.update(zip(['tmdb_id', 'name','imdb_id'], showList[0]))
                            urlTags['imdb_id'] = kwargs['imdb_id']
                            urlTags['name'] = kwargs['name']
                        addonInfo = mg.get_meta(media, **kwargs)
                    otherParam['labeldef'] = name + ' (' + str(addonInfo['year']) + ')'
                    
            elif media in ['season', 'episode']:
                imdb_id = urlTags.get('imdb_id', '')
                name =  urlTags.get('name', None) or kwargs.get('name', None)
                if not name: break
                if not imdb_id:
                    try:
                        showList = tv.get_matching_shows(name)
                    except:
                        break
                    else:
                        if showList: name, imdb_id = showList[0][1:]
                if imdb_id:
                    if media == 'season':
                        addonInfo = mg.get_seasons(name, imdb_id, kwargs['season'])[0]
                        urlTags['season'] = kwargs['season']
                    else:
                        season = urlTags.get('season', None) or kwargs['season']
                        episode = kwargs['episode']
                        addonInfo = mg.get_episode_meta(name, imdb_id, season, episode)
                        otherParam['labeldef'] = name + ' S' + season.rjust(2, '0') + 'E' + episode.rjust(2, '0') 
            break
        
        if addonInfo:
            parameters['iconImage'] = addonInfo['cover_url'] or parameters.get('iconImage', '')
            parameters['thumbnailImage'] = parameters['iconImage']
        if parameters.has_key('iconImage'):
            if not parameters.has_key('thumbnailImage'):
                parameters['thumbnailImage'] = parameters['iconImage'] 
        if urlTags.has_key('icondefflag'):
            urlTags.pop('icondefflag')
            if parameters.has_key('iconImage'): urlTags['icondef'] = parameters['iconImage']
        if urlTags.has_key('labeldefflag'):
            urlTags.pop('labeldefflag')
            urlTags['labeldef'] = otherParam.get('labeldef',parameters['label'])
        try:
            url = build_url(base_url, urlTags)
        except:
            print urlTags
            
        if not parameters.has_key('iconImage'):
            iconDefault = 'defaultFolder.png' if isFolder else 'DefaultVideo.png'
            parameters['iconImage'] = urlTags.get('icondef', None) or iconDefault 
            
        li = xbmcgui.ListItem(**parameters)
        li.setProperty('IsPlayable', 'false' if isFolder else 'true')
        if addonInfo:
            li.setInfo('video', addonInfo)
            if addonInfo['backdrop_url']: li.setProperty('fanart_image', addonInfo['backdrop_url'])
        if otherParam.has_key('contextMenu'): 
            contextMenu = otherParam.pop('contextMenu')
            li.addContextMenuItems(contextMenu['lista'], replaceItems = contextMenu['replaceItems'])
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                        listitem=li, isFolder=isFolder, totalItems=len(menuContent))
        
    if media: xbmcplugin.setContent(addon_handle, media + 's')
    if viewMode: xbmc.executebuiltin("Container.SetViewMode(%s)" % viewMode)
                                     
    xbmcplugin.endOfDirectory(addon_handle)