示例#1
0
def get_recent_items():
    """
    actually get the recent items, not limited like /library/recentlyAdded
    :return:
    """
    args = {
        "sort": "addedAt:desc",
        "X-Plex-Container-Start": "0",
        "X-Plex-Container-Size": "%s" % config.max_recent_items_per_library
    }

    episode_re = re.compile(ur'(?su)ratingKey="(?P<key>\d+)"'
                            ur'.+?grandparentRatingKey="(?P<parent_key>\d+)"'
                            ur'.+?title="(?P<title>.*?)"'
                            ur'.+?grandparentTitle="(?P<parent_title>.*?)"'
                            ur'.+?index="(?P<episode>\d+?)"'
                            ur'.+?parentIndex="(?P<season>\d+?)".+?addedAt="(?P<added>\d+)"'
                            ur'.+?<Part.+? file="(?P<filename>[^"]+?)"')
    movie_re = re.compile(ur'(?su)ratingKey="(?P<key>\d+)".+?title="(?P<title>.*?)'
                          ur'".+?addedAt="(?P<added>\d+)"'
                          ur'.+?<Part.+? file="(?P<filename>[^"]+?)"')
    available_keys = ("key", "title", "parent_key", "parent_title", "season", "episode", "added", "filename")
    recent = []

    for section in Plex["library"].sections():
        if section.type not in ("movie", "show") \
                or section.key not in config.enabled_sections \
                or section.key in ignore_list.sections:
            Log.Debug(u"Skipping section: %s" % section.title)
            continue

        use_args = args.copy()
        plex_item_type = "Movie"
        if section.type == "show":
            use_args["type"] = "4"
            plex_item_type = "Episode"

        url = "http://127.0.0.1:32400/library/sections/%s/all" % int(section.key)
        response = query_plex(url, use_args)

        matcher = episode_re if section.type == "show" else movie_re
        matches = [m.groupdict() for m in matcher.finditer(response.content)]
        for match in matches:
            data = dict((key, match[key] if key in match else None) for key in available_keys)
            if section.type == "show" and data["parent_key"] in ignore_list.series:
                Log.Debug(u"Skipping series: %s" % data["parent_title"])
                continue
            if data["key"] in ignore_list.videos:
                Log.Debug(u"Skipping item: %s" % data["title"])
                continue
            if is_physically_ignored(data["filename"], plex_item_type):
                Log.Debug(u"Skipping item: %s" % data["title"])
                continue

            if is_recent(int(data["added"])):
                recent.append((int(data["added"]), section.type, section.title, data["key"]))

    return recent
示例#2
0
def get_recent_items():
    """
    actually get the recent items, not limited like /library/recentlyAdded
    :return:
    """
    args = {
        "sort": "addedAt:desc",
        "X-Plex-Container-Start": "0",
        "X-Plex-Container-Size": "%s" % config.max_recent_items_per_library
    }

    episode_re = re.compile(ur'ratingKey="(?P<key>\d+)"'
                            ur'.+?grandparentRatingKey="(?P<parent_key>\d+)"'
                            ur'.+?title="(?P<title>.*?)"'
                            ur'.+?grandparentTitle="(?P<parent_title>.*?)"'
                            ur'.+?index="(?P<episode>\d+?)"'
                            ur'.+?parentIndex="(?P<season>\d+?)".+?addedAt="(?P<added>\d+)"')
    movie_re = re.compile(ur'ratingKey="(?P<key>\d+)".+?title="(?P<title>.*?)".+?addedAt="(?P<added>\d+)"')
    available_keys = ("key", "title", "parent_key", "parent_title", "season", "episode", "added")
    recent = []

    for section in Plex["library"].sections():
        if section.type not in ("movie", "show") \
                or section.key not in config.enabled_sections \
                or section.key in ignore_list.sections:
            Log.Debug(u"Skipping section: %s" % section.title)
            continue

        use_args = args.copy()
        if section.type == "show":
            use_args["type"] = "4"

        url = "http://127.0.0.1:32400/library/sections/%s/all" % int(section.key)
        response = query_plex(url, use_args)

        matcher = episode_re if section.type == "show" else movie_re
        matches = [m.groupdict() for m in matcher.finditer(response.content)]
        for match in matches:
            data = dict((key, match[key] if key in match else None) for key in available_keys)
            if section.type == "show" and data["parent_key"] in ignore_list.series:
                Log.Debug(u"Skipping series: %s" % data["parent_title"])
                continue
            if data["key"] in ignore_list.videos:
                Log.Debug(u"Skipping item: %s" % data["title"])
                continue
            if is_recent(int(data["added"])):
                recent.append((int(data["added"]), section.type, section.title, data["key"]))

    return recent
示例#3
0
def get_section_size(key):
    """
    quick query to determine the section size
    :param key:
    :return:
    """
    size = None
    url = "http://127.0.0.1:32400/library/sections/%s/all" % int(key)
    use_args = {"X-Plex-Container-Size": "0", "X-Plex-Container-Start": "0"}
    response = query_plex(url, use_args)
    matches = container_size_re.findall(response.content)
    if matches:
        size = int(matches[0])

    return size
示例#4
0
def get_section_size(key):
    """
    quick query to determine the section size
    :param key:
    :return:
    """
    size = None
    url = "http://127.0.0.1:32400/library/sections/%s/all" % int(key)
    use_args = {
        "X-Plex-Container-Size": "0",
        "X-Plex-Container-Start": "0"
    }
    response = query_plex(url, use_args)
    matches = container_size_re.findall(response.content)
    if matches:
        size = int(matches[0])

    return size