def do_search(self, metadata): keys = [] if metadata.title: keys.append(metadata.title) if metadata.artist: keys.append(metadata.artist) urlkey = ensure_utf8('+'.join(keys)).replace(' ', '+') url = XIAMI_HOST + XIAMI_SEARCH_URL status, content = http_download(url=url, params={'key': urlkey}, proxy=get_proxy_settings( self.config_proxy)) if status < 200 or status >= 400: raise httplib.HTTPException(status, '') match = XIAMI_SEARCH_PATTERN.findall(content) result = [] if match: for title_elem, id, artist_elem, album_elem in match: title = TITLE_ATTR_PATTERN.search(title_elem).group(1) artist = TITLE_ATTR_PATTERN.search(artist_elem).group(1) album = TITLE_ATTR_PATTERN.search(album_elem).group(1) url = self.get_url(id) if url is not None: result.append( SearchResult(title=title, artist=artist, album=album, sourceid=self.id, downloadinfo=url)) return result
def do_search(self, metadata): keys = [] if metadata.title: keys.append(metadata.title) if metadata.artist: keys.append(metadata.artist) urlkey = ensure_utf8('+'.join(keys)).replace(' ', '+') url = NETEASE_HOST + NETEASE_SEARCH_URL params = 's=%s&type=1' % urlkey status, content = http_download(url=url, method='POST', params=params, proxy=get_proxy_settings(self.config_proxy)) if status < 200 or status >= 400: raise httplib.HTTPException(status, '') def map_func(song): if len(song['artists']) > 0: artist_name = song['artists'][0]['name'] else: artist_name = '' url = NETEASE_HOST + NETEASE_LYRIC_URL + '?id=' + str(song['id']) + '&lv=-1&kv=-1&tv=-1' return SearchResult(title=song['name'], artist=artist_name, album=song['album']['name'], sourceid=self.id, downloadinfo=url) parsed = json.loads(content) result = list(map(map_func, parsed['result']['songs'])) return result
def do_search(self, metadata): keys = [] if metadata.title: keys.append(metadata.title) if metadata.artist: keys.append(metadata.artist) urlkey = ensure_utf8('+'.join(keys)).replace(' ', '+') url = XIAMI_HOST + XIAMI_SEARCH_URL status, content = http_download(url=url, params={'key': urlkey}, proxy=get_proxy_settings(self.config_proxy)) if status < 200 or status >= 400: raise httplib.HTTPException(status, '') match = XIAMI_SEARCH_PATTERN.findall(content) result = [] if match: for title_elem, id, artist_elem, album_elem in match: title = TITLE_ATTR_PATTERN.search(title_elem).group(1) artist = TITLE_ATTR_PATTERN.search(artist_elem).group(1) album = TITLE_ATTR_PATTERN.search(album_elem).group(1) url = self.get_url(id) if url is not None: result.append(SearchResult(title=title, artist=artist, album=album, sourceid=self.id, downloadinfo=url)) return result
def real_search(self, title='', artist='', page=0): query = VIEWLYRICS_QUERY_FORM query = query.replace('%title', title) query = query.replace('%artist', artist) query = ensure_utf8( query.replace('%etc', ' client=\"MiniLyrics\" RequestPage=\'%d\'' % page)) #Needs real RequestPage queryhash = hashlib.md5() queryhash.update(query) queryhash.update(VIEWLYRICS_KEY) masterquery = '\2\0\4\0\0\0' + queryhash.digest() + query url = VIEWLYRICS_HOST + VIEWLYRICS_SEARCH_URL status, content = http_download(url=url, method='POST', params=masterquery, proxy=get_proxy_settings( self.config_proxy)) if status < 200 or status >= 400: raise httplib.HTTPException(status, '') contentbytes = map(ord, content) codekey = contentbytes[1] deccontent = '' for char in contentbytes[22:]: deccontent += chr(char ^ codekey) result = [] pagesleft = 0 tagreturn = parseString(deccontent).getElementsByTagName('return')[0] if tagreturn: pagesleftstr = self.alternative_gettagattribute( tagreturn.attributes.items(), 'PageCount') #tagreturn.attributes['PageCount'].value if pagesleftstr == '': pagesleft = 0 else: pagesleft = int(pagesleftstr) tagsfileinfo = tagreturn.getElementsByTagName('fileinfo') if tagsfileinfo: for onefileinfo in tagsfileinfo: if onefileinfo.hasAttribute('link'): title = onefileinfo.getAttribute('title') artist = onefileinfo.getAttribute('artist') album = onefileinfo.getAttribute('album') url = VIEWLYRICS_BASE_LRC_URL + onefileinfo.getAttribute( 'link') result.append( SearchResult(title=title, artist=artist, album=album, sourceid=self.id, downloadinfo=url)) return result, (pagesleft - page)
def real_search(self, title='', artist='', page = 0): query = VIEWLYRICS_QUERY_FORM query = query.replace('%title', title) query = query.replace('%artist', artist) query = ensure_utf8(query.replace('%etc', ' client=\"MiniLyrics\" RequestPage=\'%d\'' % page)) #Needs real RequestPage queryhash = hashlib.md5() queryhash.update(query) queryhash.update(VIEWLYRICS_KEY) masterquery = '\2\0\4\0\0\0' + queryhash.digest() + query url = VIEWLYRICS_HOST + VIEWLYRICS_SEARCH_URL status, content = http_download(url=url, method='POST', params=masterquery, proxy=get_proxy_settings(self.config_proxy)) if status < 200 or status >= 400: raise httplib.HTTPException(status, '') contentbytes = map(ord, content) codekey = contentbytes[1] deccontent = '' for char in contentbytes[22:]: deccontent += unichr(char ^ codekey) result = [] pagesleft = 0 tagreturn = parseString(deccontent).getElementsByTagName('return')[0] if tagreturn: pagesleftstr = self.alternative_gettagattribute(tagreturn.attributes.items(), 'PageCount') #tagreturn.attributes['PageCount'].value if pagesleftstr == '': pagesleft = 0 else: pagesleft = int(pagesleftstr) tagsfileinfo = tagreturn.getElementsByTagName('fileinfo') if tagsfileinfo: for onefileinfo in tagsfileinfo: if onefileinfo.hasAttribute('link'): title = onefileinfo.getAttribute('title') artist = onefileinfo.getAttribute('artist') album = onefileinfo.getAttribute('album') url = VIEWLYRICS_BASE_LRC_URL + onefileinfo.getAttribute('link') result.append(SearchResult(title=title, artist=artist, album=album, sourceid=self.id, downloadinfo=url)) return result, (pagesleft - page)
def normalize_location(location): """ Normalize location of metadata to URI form >>> normalize_location('/path/to/file') u'file:///path/to/file' >>> normalize_location(u'/path/to/file') u'file:///path/to/file' >>> normalize_location('file:///path/to/file') u'file:///path/to/file' >>> normalize_location('/\xe6\x96\x87\xe4\xbb\xb6/\xe8\xb7\xaf\xe5\xbe\x84') u'file:///%E6%96%87%E4%BB%B6/%E8%B7%AF%E5%BE%84' >>> normalize_location(u'/\u6587\u4ef6/\u8def\u5f84') u'file:///%E6%96%87%E4%BB%B6/%E8%B7%AF%E5%BE%84' """ if location and location[0] == '/': location = 'file://' + urllib.pathname2url(ensure_utf8(location)) location = ensure_unicode(location) return location