def translate_uri(self, uri): '''Convert custom URI scheme to real playable URI. MAY be reimplemented by subclass. This is very likely the only thing you need to override as a backend author. Typically this is where you convert any Mopidy specific URI to a real URI and then return it. If you can’t convert the URI just return None. Parameters: uri (string) – the URI to translate Return type: string or None if the URI could not be translated''' logger.debug("Playback.translate_uri Plex with uri '%s'", uri) _rx = re.compile(r'plex:track:(?P<track_id>\d+)').match(uri) if _rx is None: # uri unknown logger.info('Unkown uri: %s', uri) return None elem = plexutils.findKey(self.backend.plex, _rx.group('track_id')) logger.info('getting file parts for eleme %r', elem) try: p = list(elem.iterParts())[0].key # hackisly get direct url of first part return '%s%s?X-Plex-Token=%s' % (elem.server.baseurl, p, self.backend.plex.token) except Exception as e: logger.exception(e) logger.info('fallback to returning stream for elem %r', elem) return elem.getStreamUrl()
def getByKey(self, key): """ Return the first item from all items with the specified key. Parameters: key (str): Key of the item to return. """ return utils.findKey(self.server, key)
def getByKey(self, key): return utils.findKey(self.server, key)
def test_utils_findKey(pms): with pytest.raises(NotFound): assert utils.findKey(pms, '9999999') assert utils.findKey(pms, '1')