Пример #1
0
def search_results_person(params):

    handle = int(sys.argv[1])

    person_id = params.get("person_id")
    details_url = (
        '{server}/emby/Users/{userid}/items' + '?PersonIds=' + person_id +
        # '&IncludeItemTypes=Movie' +
        '&Recursive=true' + '&Fields={field_filters}' + '&format=json')
    '''
    details_result = dataManager.GetContent(details_url)
    log.debug("Search Results Details: {0}", details_result)

    if details_result:
        items = details_result.get("Items")
        found_types = set()
        for item in items:
            found_types.add(item.get("Type"))
        log.debug("search_results_person found_types: {0}", found_types)
    '''
    dir_items, detected_type = processDirectory(details_url, None, params)

    log.debug('search_results_person results: {0}', dir_items)
    log.debug('search_results_person detect_type: {0}', detected_type)

    if detected_type is not None:
        # if the media type is not set then try to use the detected type
        log.debug("Detected content type: {0}", detected_type)
        content_type = None

        if detected_type == "Movie":
            content_type = 'movies'
        elif detected_type == "Episode":
            content_type = 'episodes'
        elif detected_type == "Series":
            content_type = 'tvshows'
        elif detected_type == "Music" or detected_type == "Audio" or detected_type == "Musicalbum":
            content_type = 'songs'

        if content_type:
            xbmcplugin.setContent(handle, content_type)

    #xbmcplugin.setContent(handle, detected_type)

    if dir_items is not None:
        xbmcplugin.addDirectoryItems(handle, dir_items)

    xbmcplugin.endOfDirectory(handle, cacheToDisc=False)
Пример #2
0
def getWidgetContent(handle, params):
    log.debug("getWigetContent Called: {0}", params)

    widget_type = params.get("type")
    if widget_type is None:
        log.error("getWigetContent type not set")
        return

    log.debug("widget_type: {0}", widget_type)

    items_url = ("{server}/emby/Users/{userid}/Items" + "?Limit={ItemLimit}" +
                 "&format=json" + '&Fields={field_filters}' +
                 "&ImageTypeLimit=1" + "&IsMissing=False")

    if widget_type == "recent_movies":
        xbmcplugin.setContent(handle, 'movies')
        items_url += ("&Recursive=true" + "&SortBy=DateCreated" +
                      "&SortOrder=Descending" +
                      "&Filters=IsUnplayed,IsNotFolder" + "&IsPlayed=false" +
                      "&IsVirtualUnaired=false" + "&IsMissing=False" +
                      "&IncludeItemTypes=Movie")

    elif widget_type == "inprogress_movies":
        xbmcplugin.setContent(handle, 'movies')
        items_url += ("&Recursive=true" + "&SortBy=DatePlayed" +
                      "&SortOrder=Descending" + "&Filters=IsResumable" +
                      "&IsVirtualUnaired=false" + "&IsMissing=False" +
                      "&IncludeItemTypes=Movie")

    elif widget_type == "random_movies":
        xbmcplugin.setContent(handle, 'movies')
        items_url += "&Ids={random_movies}"

    elif widget_type == "recent_tvshows":
        xbmcplugin.setContent(handle, 'episodes')
        items_url = ('{server}/emby/Users/{userid}/Items/Latest' +
                     '?GroupItems=true' + '&Limit={ItemLimit}' +
                     '&Recursive=true' + '&SortBy=DateCreated' +
                     '&SortOrder=Descending' + '&Filters=IsUnplayed' +
                     '&Fields={field_filters}' + '&IsPlayed=false' +
                     '&IsVirtualUnaired=false' + '&IsMissing=False' +
                     '&IncludeItemTypes=Episode' + '&ImageTypeLimit=1' +
                     '&format=json')

    elif widget_type == "recent_episodes":
        xbmcplugin.setContent(handle, 'episodes')
        items_url += ("&Recursive=true" + "&SortBy=DateCreated" +
                      "&SortOrder=Descending" +
                      "&Filters=IsUnplayed,IsNotFolder" + "&IsPlayed=false" +
                      "&IsVirtualUnaired=false" + "&IsMissing=False" +
                      "&IncludeItemTypes=Episode")

    elif widget_type == "inprogress_episodes":
        xbmcplugin.setContent(handle, 'episodes')
        items_url += ("&Recursive=true" + "&SortBy=DatePlayed" +
                      "&SortOrder=Descending" + "&Filters=IsResumable" +
                      "&IsVirtualUnaired=false" + "&IsMissing=False" +
                      "&IncludeItemTypes=Episode")

    elif widget_type == "nextup_episodes":
        xbmcplugin.setContent(handle, 'episodes')
        items_url = ("{server}/emby/Shows/NextUp" + "?Limit={ItemLimit}"
                     "&userid={userid}" + "&Recursive=true" +
                     '&Fields={field_filters}' + "&format=json" +
                     "&ImageTypeLimit=1")

    list_items, detected_type = processDirectory(items_url, None, params,
                                                 False)

    #list_items = populateWidgetItems(items_url, widget_type)

    xbmcplugin.addDirectoryItems(handle, list_items)
    xbmcplugin.endOfDirectory(handle, cacheToDisc=False)
Пример #3
0
def search_results(params):

    item_type = params.get('item_type')
    query_string = params.get('query')
    if query_string:
        log.debug("query_string : {0}", query_string)
        query_string = urllib.unquote(query_string)
        log.debug("query_string : {0}", query_string)

    item_type = item_type.lower()

    if item_type == 'movie':
        heading_type = string_load(30231)
        content_type = 'movies'
    elif item_type == 'series':
        heading_type = string_load(30229)
        content_type = 'tvshows'
    elif item_type == 'episode':
        heading_type = string_load(30235)
        content_type = 'episodes'
        params["name_format"] = "Episode|episode_name_format"
    elif item_type == "music" or item_type == "audio" or item_type == "musicalbum":
        heading_type = 'Music'
        content_type = 'songs'
    elif item_type == "person":
        heading_type = 'Artists'
        content_type = 'artists'
    else:
        heading_type = item_type
        content_type = 'video'

    handle = int(sys.argv[1])

    if not query_string:
        home_window = HomeWindow()
        last_search = home_window.getProperty("last_search")
        kb = xbmc.Keyboard()
        kb.setHeading(heading_type.capitalize() + ' ' +
                      string_load(30246).lower())
        kb.setDefault(last_search)
        kb.doModal()

        if kb.isConfirmed():
            user_input = kb.getText().strip()
        else:
            return

        home_window.setProperty("last_search", user_input)
        log.debug('searchResults Called: {0}', params)
        query = user_input

    else:
        query = query_string

    query = urllib.quote(query)
    log.debug("query : {0}", query)

    if (not item_type) or (not query):
        return

    limit = int(params.get('limit', 20))
    content_url = ('{server}/emby/Search/Hints?searchTerm=' + query +
                   '&UserId={userid}' + '&Limit=' + str(limit) +
                   '&IncludeItemTypes=' + item_type +
                   '&ExcludeItemTypes=LiveTvProgram' + '&IncludePeople=false' +
                   '&IncludeMedia=true' + '&IncludeGenres=false' +
                   '&IncludeStudios=false' + '&IncludeArtists=false')

    if item_type == "person":
        content_url = ('{server}/emby/Search/Hints?searchTerm=' + query +
                       '&UserId={userid}' + '&Limit=' + str(limit) +
                       '&IncludePeople=true' + '&IncludeMedia=false' +
                       '&IncludeGenres=false' + '&IncludeStudios=false' +
                       '&IncludeArtists=false')

    # show a progress indicator if needed
    settings = xbmcaddon.Addon()
    progress = None
    if settings.getSetting('showLoadProgress') == "true":
        progress = xbmcgui.DialogProgress()
        progress.create(string_load(30112))
        progress.update(0, string_load(30113))

    search_hints_result = dataManager.GetContent(content_url)
    log.debug('SearchHints jsonData: {0}', search_hints_result)

    if search_hints_result is None:
        search_hints_result = {}

    search_hints = search_hints_result.get('SearchHints')
    if search_hints is None:
        search_hints = []

    total_results = int(search_hints_result.get('TotalRecordCount', 0))
    log.debug('SEARCH_TOTAL_RESULTS: {0}', total_results)

    # what type of search was it
    if item_type == "person":
        log.debug("Item Search Result")
        server = downloadUtils.getServer()
        list_items = []
        for item in search_hints:
            person_id = item.get('ItemId')
            person_name = item.get('Name')
            image_tag = item.get('PrimaryImageTag')
            person_thumbnail = downloadUtils.imageUrl(person_id,
                                                      "Primary",
                                                      0,
                                                      400,
                                                      400,
                                                      image_tag,
                                                      server=server)

            action_url = sys.argv[
                0] + "?mode=NEW_SEARCH_PERSON&person_id=" + person_id

            list_item = xbmcgui.ListItem(label=person_name)
            list_item.setProperty("id", person_id)
            if person_thumbnail:
                art_links = {}
                art_links["thumb"] = person_thumbnail
                art_links["poster"] = person_thumbnail
                list_item.setArt(art_links)

            item_tupple = (action_url, list_item, True)
            list_items.append(item_tupple)

        xbmcplugin.setContent(handle, 'artists')
        xbmcplugin.addDirectoryItems(handle, list_items)
        xbmcplugin.endOfDirectory(handle, cacheToDisc=False)

    else:
        # extract IDs for details query
        log.debug("Item Search Result")
        id_list = []
        for item in search_hints:
            item_id = item.get('ItemId')
            id_list.append(str(item_id))

        if len(id_list) > 0:
            Ids = ",".join(id_list)
            details_url = ('{server}/emby/Users/{userid}/items' + '?Ids=' +
                           Ids + '&Fields={field_filters}' + '&format=json')
            '''
            details_result = dataManager.GetContent(details_url)
            log.debug("Search Results Details: {0}", details_result)
            '''

            # set content type
            xbmcplugin.setContent(handle, content_type)

            dir_items, detected_type = processDirectory(
                details_url, progress, params)
            if dir_items is not None:
                xbmcplugin.addDirectoryItems(handle, dir_items)
                xbmcplugin.endOfDirectory(handle, cacheToDisc=False)

        elif not query_string:
            xbmcgui.Dialog().ok(string_load(30335), string_load(30336))

    if progress is not None:
        progress.update(100, string_load(30125))
        progress.close()