def update(self): # From what I read you can't update the music library on a per directory or per path basis # so need to update the whole thing hosts = [x.strip() for x in self.server_hosts.split(',')] for host in hosts: logger.info( 'Sending library update command to Plex Media Server@ ' + host) url = "%s/library/sections" % host if self.token: params = {'X-Plex-Token': self.token} else: params = False r = request.request_minidom(url, params=params) sections = r.getElementsByTagName('Directory') if not sections: logger.info(u"Plex Media Server not running on: " + host) return False for s in sections: if s.getAttribute('type') == "artist": url = "%s/library/sections/%s/refresh" % ( host, s.getAttribute('key')) request.request_response(url, params=params)
def update(self): # From what I read you can't update the music library on a per directory or per path basis # so need to update the whole thing hosts = [x.strip() for x in self.server_hosts.split(',')] for host in hosts: logger.info('Sending library update command to Plex Media Server@ ' + host) url = "%s/library/sections" % host if self.token: params = {'X-Plex-Token': self.token} else: params = False r = request.request_minidom(url, params=params) sections = r.getElementsByTagName('Directory') if not sections: logger.info(u"Plex Media Server not running on: " + host) return False for s in sections: if s.getAttribute('type') == "artist": url = "%s/library/sections/%s/refresh" % (host, s.getAttribute('key')) request.request_response(url, params=params)
def getLyrics(artist, song): params = { "artist": artist.encode('utf-8'), "song": song.encode('utf-8'), "fmt": 'xml' } url = 'http://lyrics.wikia.com/api.php' data = request.request_minidom(url, params=params) if not data: return url = data.getElementsByTagName("url") if url: lyricsurl = url[0].firstChild.nodeValue else: logger.info('No lyrics found for %s - %s' % (artist, song)) return lyricspage = request.request_content(lyricsurl) if not lyricspage: logger.warn('Error fetching lyrics from: %s' % lyricsurl) return m = re.compile( '''<div class='lyricbox'><div class='rtMatcher'>.*?</div>(.*?)<!--''' ).search(lyricspage) if not m: m = re.compile( '''<div class='lyricbox'><span style="padding:1em"><a href="/Category:Instrumental" title="Instrumental">''' ).search(lyricspage) if m: return u'(Instrumental)' else: logger.warn('Cannot find lyrics on: %s' % lyricsurl) return lyrics = convert_html_entities(m.group(1)).replace('<br />', '\n') lyrics = re.sub('<.*?>', '', lyrics) return lyrics
def getLyrics(artist, song): params = {"artist": artist.encode('utf-8'), "song": song.encode('utf-8'), "fmt": 'xml' } url = 'http://lyrics.wikia.com/api.php' data = request.request_minidom(url, params=params) if not data: return url = data.getElementsByTagName("url") if url: lyricsurl = url[0].firstChild.nodeValue else: logger.info('No lyrics found for %s - %s' % (artist, song)) return lyricspage = request.request_content(lyricsurl) if not lyricspage: logger.warn('Error fetching lyrics from: %s' % lyricsurl) return m = re.compile('''<div class='lyricbox'><div class='rtMatcher'>.*?</div>(.*?)<!--''').search( lyricspage) if not m: m = re.compile( '''<div class='lyricbox'><span style="padding:1em"><a href="/Category:Instrumental" title="Instrumental">''').search( lyricspage) if m: return u'(Instrumental)' else: logger.warn('Cannot find lyrics on: %s' % lyricsurl) return lyrics = convert_html_entities(m.group(1)).replace('<br />', '\n') lyrics = re.sub('<.*?>', '', lyrics) return lyrics
def update(self): # Get token from user credentials if not self.token: loginpage = 'https://plex.tv/users/sign_in.json' post_params = { 'user[login]': self.username, 'user[password]': self.password } headers = { 'X-Plex-Device-Name': 'Headphones', 'X-Plex-Product': 'Headphones', 'X-Plex-Client-Identifier': common.USER_AGENT, 'X-Plex-Version': '' } logger.info("Getting plex.tv credentials for user %s", self.username) try: r = requests.post(loginpage, data=post_params, headers=headers) r.raise_for_status() except requests.RequestException as e: logger.error("Error getting plex.tv credentials, check settings: %s", e) return False try: data = r.json() except ValueError as e: logger.error("Error getting plex.tv credentials: %s", e) return False try: self.token = data['user']['authentication_token'] except KeyError as e: logger.error("Error getting plex.tv credentials: %s", e) return False # From what I read you can't update the music library on a per # directory or per path basis so need to update the whole thing hosts = [x.strip() for x in self.server_hosts.split(',')] for host in hosts: logger.info( 'Sending library update command to Plex Media Server@ ' + host) url = "%s/library/sections" % host if self.token: params = {'X-Plex-Token': self.token} else: params = False try: r = request.request_minidom(url, params=params) if not r: logger.warn("Error getting Plex Media Server details, check settings (possibly incorrect token)") return False sections = r.getElementsByTagName('Directory') if not sections: logger.info(u"Plex Media Server not running on: " + host) return False for s in sections: if s.getAttribute('type') == "artist": url = "%s/library/sections/%s/refresh" % ( host, s.getAttribute('key')) request.request_response(url, params=params) except Exception as e: logger.error("Error getting Plex Media Server details: %s" % e) return False