def fill_path(self, guid, path): # Split path into fragments fragments = path.strip('/').split('/') # Retrieve TV parameters if 'season' in self.media and len(fragments) >= 1: guid.season = try_convert(fragments[0], int) if 'episode' in self.media and len(fragments) >= 2: guid.episode = try_convert(fragments[1], int)
def fill_path(self, guid, path): # Split path into fragments fragments = path.strip('/').split('/') # Retrieve TV parameters if 'season' in self.media and len(fragments) >= 1: guid.season = try_convert(fragments[0], int) if 'episode' in self.media and len(fragments) >= 2: guid.episode = try_convert(fragments[1], int)
def parse_path(cls, guid, uri): # Parse path component for agent-specific data path_fragments = uri.path.strip('/').split('/') if guid.agent in DEFAULT_TV_AGENTS: if len(path_fragments) >= 1: guid.season = try_convert(path_fragments[0], int) if len(path_fragments) >= 2: guid.episode = try_convert(path_fragments[1], int) else: log.warn('Unable to completely parse guid (agent: %r)', guid.agent)
def fetch(self, key): if try_convert(key, int) is None: log.info('Ignoring request for metadata with an invalid key: %r', key) return None # Request metadata from server container = Plex['library'].metadata(key) if not container: return None # Cast to `list` (resolve iterators) items = list(container) if not items: return None item = items[0] # Ignore if this is an unsupported media type if item.type not in self.types: # TODO set flag to ignore future refresh requests log.info('Item %s with type "%s" has been ignored', key, item.type) return None return item
def fetch(self, key): if try_convert(key, int) is None: log.info('Ignoring request for metadata with an invalid key: %r', key) return None # Request metadata from server container = Plex['library'].metadata(key) if not container: return None # Cast to `list` (resolve iterators) items = list(container) if not items: return None item = items[0] # Ignore if this is an unsupported media type if item.type not in self.types: # TODO set flag to ignore future refresh requests log.info('Item %s with type "%s" has been ignored', key, item.type) return None return item
def match_episode(self, p_identifier, c_identifier): p_season, p_episode = p_identifier # Season number retrieval/validation (only except exact matches to p_season) if 'season' not in c_identifier: return c_season = try_convert(c_identifier['season'], int) if c_season != p_season: return # Episode number retrieval/validation c_episodes = None # Single or repeat-style episodes if 'episode' in c_identifier: episodes = c_identifier['episode'] if not isinstance(episodes, (list, set)): episodes = [episodes] c_episodes = [try_convert(x, int) for x in episodes] # Extend-style episodes if 'episode_from' in c_identifier and 'episode_to' in c_identifier: # Cast parameters to integers c_from = try_convert(c_identifier['episode_from'], int) c_to = try_convert(c_identifier['episode_to'], int) if c_from is None or c_to is None: return # Ensure range is valid count = c_to - c_from if count > 10 or count < 0: return # Ensure plex episode is inside identifier episode range if c_from <= p_episode <= c_to: c_episodes = range(c_from, c_to + 1) else: return return c_episodes
def match_episode(self, p_identifier, c_identifier): p_season, p_episode = p_identifier # Season number retrieval/validation (only except exact matches to p_season) if 'season' not in c_identifier: return c_season = try_convert(c_identifier['season'], int) if c_season != p_season: return # Episode number retrieval/validation c_episodes = None # Single or repeat-style episodes if 'episode' in c_identifier: episodes = c_identifier['episode'] if not isinstance(episodes, (list, set)): episodes = [episodes] c_episodes = [try_convert(x, int) for x in episodes] # Extend-style episodes if 'episode_from' in c_identifier and 'episode_to' in c_identifier: # Cast parameters to integers c_from = try_convert(c_identifier['episode_from'], int) c_to = try_convert(c_identifier['episode_to'], int) if c_from is None or c_to is None: return # Ensure range is valid count = c_to - c_from if count > 10 or count < 0: return # Ensure plex episode is inside identifier episode range if c_from <= p_episode <= c_to: c_episodes = range(c_from, c_to + 1) else: return return c_episodes
def fill(self, guid, uri, media=None): # Validate media matches agent if media is not None and media not in self.media: return False # Search children for match if self.children: # Iterate over children, checking if `guid` can be filled for child in self.children: if child.fill(guid, uri, media): return True # Parse netloc (media id) if self.regex: # Match `uri.netloc` against pattern match = self.regex.match(uri.netloc) if not match: return False id = ''.join(match.groups()) else: id = uri.netloc # Cast `id` to defined type if self.type: id = try_convert(id, self.type, id) # Update `guid` guid.service = self.service guid.id = id # Fill `guid` with extra details from URI self.fill_path(guid, uri.path) self.fill_query(guid, uri.query) # Process overrides if self.season is not None: guid.season = self.season return True
def fill(self, guid, uri, media=None): # Validate media matches agent if media is not None and media not in self.media: return False # Search children for match if self.children: # Iterate over children, checking if `guid` can be filled for child in self.children: if child.fill(guid, uri, media): return True # Parse netloc (media id) if self.regex: # Match `uri.netloc` against pattern match = self.regex.match(uri.netloc) if not match: return False id = ''.join(match.groups()) else: id = uri.netloc # Cast `id` to defined type if self.type: id = try_convert(id, self.type, id) # Update `guid` guid.service = self.service guid.id = id # Fill `guid` with extra details from URI self.fill_path(guid, uri.path) self.fill_query(guid, uri.query) # Process overrides if self.season is not None: guid.season = self.season return True