def update(self, metadata, media, lang, force):
        PlexLog.debug("=================== Update Start ===================")

        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        if not server:
            PlexLog.error("Missing server!")
            return

        show = request_json(urljoin(server, "show"), as_show(media))
        if show is None:
            return
        set_show(metadata, media, show)

        season_summary = show.get("season_summary", {})
        for season in media.seasons:
            season_id = media.seasons[season].id
            summary = season_summary.get(season)
            if summary is not None:
                update_season_summary(season_id, summary)
            for episode in media.seasons[season].episodes:
                episode_metadata = metadata.seasons[season].episodes[episode]
                model = request_json(urljoin(server, "episode"),
                                     as_episode(media, season, episode))
                set_episode(episode_metadata, model)
                set_episode_cover(episode_metadata, media, season, episode)
        PlexLog.debug("===================  Update end  ===================")
    def search(self, results, media, lang, manual):
        PlexLog.debug("=================== Search Start ===================")

        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        if not server:
            PlexLog.error("Missing server!")
            return

        movie = request_json(urljoin(server, "movie"), as_movie(media))
        if movie is None:
            return

        title = movie.get("title")
        if title is None:
            PlexLog.error("Missing or invalid title: %s" % str(movie))
            return

        aired = convert_date(movie.get("aired"))
        year = aired.year if aired is not None else 0

        # Plex throws exception that have "/" in ID
        mid = create_id(title, year)
        result = MetadataSearchResult(id=mid,
                                      name=title,
                                      year=year,
                                      lang=lang,
                                      score=100)
        results.Append(result)
        PlexLog.debug("===================  Search end  ===================")
示例#3
0
def update_tracks(media_id, track_file):
    try:
        tags = File(track_file, None, True)
        artist_str = " / ".join(tags["artist"])
        update_track(media_id, artist_str)
    except Exception, e:
        PlexLog.error(e)
示例#4
0
    def search(self, results, media, lang, manual):
        PlexLog.debug("=================== Search Start ===================")

        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        show = get_show(media)
        if show is None:
            return

        title = show.get("title")
        if title is None:
            PlexLog.error("Missing or invalid title: %s" % str(show))
            return

        aired = convert_date(show.get("aired"))
        year = aired.year if aired is not None else 0

        # Plex throws exception that have "/" in ID
        mid = create_id(title, year)
        result = MetadataSearchResult(id=mid,
                                      name=title,
                                      year=year,
                                      lang=lang,
                                      score=100)
        results.Append(result)
        PlexLog.debug("===================  Search end  ===================")
    def search(self, results, media, lang, manual):
        PlexLog.debug("=================== Search Start ===================")
        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        authKey = Prefs["AuthKey"]
        if not server:
            PlexLog.error("Missing server!")
            return

        requestUrl = urljoin(server, "album")
        if authKey:
            requestUrl = requestUrl + "?AuthKey=" + authKey

        PlexLog.debug("Requesting URL: %s" % requestUrl)

        album = request_json(requestUrl, as_album(media))
        if album is None:
            return

        result = MetadataSearchResult(id=media.id,
                                      name=media.title,
                                      lang=lang,
                                      year=None,
                                      score=100)

        results.Append(result)

        PlexLog.debug("===================  Search end  ===================")
示例#6
0
def get_episode_json(media, season, episode):
    path = get_show_file(media)
    season_dir = dirname(path)
    name = guess_name(path)
    file = episode_file(name, season, episode, "json")
    file_path = join(season_dir, file)
    if not exists(file_path):
        PlexLog.error("No JSON for %s" % file_path)
        return None
    string = Core.storage.load(file_path)
    return JSON.ObjectFromString(string)
示例#7
0
def request_json(url, json):
    PlexLog.debug("Request JSON %s" % str(request_json))
    response = requests.post(url, json=json)
    status_code = response.status_code
    if status_code != 200:
        PlexLog.error("HTTP response (%d)" % status_code)
        return None

    try:
        response_json = response.json()
    except ValueError:
        PlexLog.error("Invalid JSON response")
        return None

    PlexLog.debug("Response JSON: %s" % str(response_json))
    return response_json
    def update(self, metadata, media, lang, force):
        PlexLog.debug("=================== Update Start ===================")
        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        if not server:
            PlexLog.error("Missing server!")
            return

        album = request_json(urljoin(server, "album"), as_album(media))
        if album is None:
            return

        set_album(metadata, media, album)

        PlexLog.debug("===================  Update end  ===================")
示例#9
0
def set_metadata_posters(metadata, posterUrls):
    if posterUrls is None:
        return

    valid_names = list()
    i = 0

    PlexLog.info('Attempting to get new posters')

    for posterUrl in posterUrls:
        if posterUrl not in metadata.posters:
            valid_names.append(posterUrl)
            try:
                metadata.posters[posterUrl] = Proxy.Preview(
                    HTTP.Request(posterUrl).content, sort_order=i + 1)
                PlexLog.info('New poster added: %s' % posterUrl)
            except:
                PlexLog.error('New poster error: %s' % posterUrl)
                pass

    metadata.posters.validate_keys(valid_names)
示例#10
0
def update_put(media_id, update_type, parameters):
    token = Prefs["Token"]
    if not token:
        PlexLog.warn("Missing token!")
        return
    localhost = "http://127.0.0.1:32400"
    page_url = localhost + "/library/metadata/" + media_id
    xml_element = XML.ElementFromURL(page_url)
    container = xml_element.xpath("//MediaContainer")[0]
    section = String.Unquote(container.get("librarySectionID").encode("utf-8"))
    query = {
        "type": update_type,
        "id": media_id,  # Movie Type 1
        "X-Plex-Token": token
    }
    query.update(parameters)

    request_url = localhost + "/library/sections/" + section + "/all?"
    response = requests.put(request_url, params=query)
    if not response.ok:
        PlexLog.error("Fail to put update (%d)" % response.status_code)
示例#11
0
    def search(self, results, media, lang, manual):
        PlexLog.debug("=================== Search Start ===================")

        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        authKey = Prefs["AuthKey"]
        if not server:
            PlexLog.error("Missing server!")
            return

        requestUrl = urljoin(server, "show")
        if authKey:
            requestUrl = requestUrl + "?AuthKey=" + authKey

        PlexLog.debug("Requesting URL: %s" % requestUrl)

        show = request_json(requestUrl, as_show(media))
        if show is None:
            return

        title = show.get("title")
        if title is None:
            PlexLog.error("Missing or invalid title: %s" % str(show))
            return

        aired = convert_date(show.get("aired"))
        year = aired.year if aired is not None else 0

        # Plex throws exception that have "/" in ID
        mid = create_id(title, year)
        result = MetadataSearchResult(id=mid,
                                      name=title,
                                      year=year,
                                      lang=lang,
                                      score=100)
        results.Append(result)
        PlexLog.debug("===================  Search end  ===================")
    def search(self, results, media, lang, manual):
        PlexLog.debug("=================== Search Start ===================")
        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        if not server:
            PlexLog.error("Missing server!")
            return

        artist = request_json(urljoin(server, "artist"), as_artist(media))
        if artist is None:
            return

        result = MetadataSearchResult(id=media.id,
                                      name=media.title,
                                      lang=lang,
                                      year=None,
                                      score=100)

        results.Append(result)

        PlexLog.debug("===================  Search end  ===================")
示例#13
0
    def update(self, metadata, media, lang, force):
        PlexLog.debug("=================== Update Start ===================")
        PlexLog.debug("%s (%s)" % (self.name, self.ver))
        PlexLog.debug("Plex version: %s" % Platform.ServerVersion)

        server = Prefs["Server"]
        authKey = Prefs["AuthKey"]
        if not server:
            PlexLog.error("Missing server!")
            return

        requestUrl = urljoin(server, "album")
        if authKey:
            requestUrl = requestUrl + "?AuthKey=" + authKey

        PlexLog.debug("Requesting URL: %s" % requestUrl)

        album = request_json(requestUrl, as_album(media))
        if album is None:
            return

        set_album(metadata, media, album)

        PlexLog.debug("===================  Update end  ===================")