Esempio n. 1
0
 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
Esempio n. 2
0
    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)
Esempio n. 3
0
 def get_songid(self, id):
     status, content = http_download(
         url=XIAMI_HOST + XIAMI_SONG_URL + str(id),
         proxy=get_proxy_settings(self.config_proxy))
     if status < 200 or status >= 400:
         return None
     match = XIAMI_ID_PATTERN.search(content)
     if not match:
         return None
     songid = match.group(1).strip()
     return songid
Esempio n. 4
0
 def do_download(self, downloadinfo):
     if not isinstance(downloadinfo, str) and \
             not isinstance(downloadinfo, unicode):
         raise TypeError(
             'Expect the downloadinfo as a string of url, but got type ',
             type(downloadinfo))
     status, content = http_download(url=HOST + downloadinfo,
                                     proxy=get_proxy_settings(
                                         self.config_proxy))
     if status < 200 or status >= 400:
         raise httplib.HTTPException(status, '')
     return content
Esempio n. 5
0
 def get_url(self, id):
     songid = self.get_songid(id)
     status, content = http_download(
         url=XIAMI_HOST + XIAMI_LRC_URL + str(songid),
         proxy=get_proxy_settings(self.config_proxy))
     if status < 200 or status >= 400:
         return None
     match = XIAMI_URL_PATTERN.search(content)
     if not match:
         return None
     url = match.group(1).strip()
     if url.lower().endswith('.lrc'):
         return url
     else:
         return None
Esempio n. 6
0
 def do_download(self, downloadinfo):
     if not isinstance(downloadinfo, str) and \
             not isinstance(downloadinfo, unicode):
         raise TypeError(
             'Expect the downloadinfo as a string of url, but got type ',
             type(downloadinfo))
     # parts = urlparse.urlparse(downloadinfo)
     status, content = http_download(downloadinfo,
                                     proxy=get_proxy_settings(
                                         self.config_proxy))
     if status < 200 or status >= 400:
         raise httplib.HTTPException(status)
     if content:
         content = HTMLParser.HTMLParser().unescape(content.decode('utf-8'))
     return content.encode('utf-8')
Esempio n. 7
0
    def do_download(self, downloadinfo):
        if not isinstance(downloadinfo, str) and \
                not isinstance(downloadinfo, unicode):
            raise TypeError(
                'Expect the downloadinfo as a string of url, but got type ',
                type(downloadinfo))

        status, content = http_download(url=downloadinfo,
                                        proxy=get_proxy_settings(
                                            self.config_proxy))
        if status < 200 or status >= 400:
            raise httplib.HTTPException(status)

        parsed = json.loads(content)
        lyric = parsed['lrc']['lyric']
        return lyric
Esempio n. 8
0
    def do_search(self, metadata):
        keys = []
        if metadata.title:
            keys.append(metadata.title)
        if metadata.artist:
            keys.append(metadata.artist)
        urlkey = (' '.join(keys))
        params = {'keyword': urlkey, 'field': 'all'}
        try:
            status, content = http_download(
                url=HOST + '/',
                params=params,
                proxy=get_proxy_settings(config=self.config_proxy))
        except pycurl.error as e:
            logging.error('Download failed. %s', e.args[1])
            return []

        if status < 200 or status >= 400:
            raise httplib.HTTPException(status)
        match = RESULT_PATTERN.findall(content)
        result = []
        if match:
            for artist, album, title, url in match:
                title = title.replace('<span class="highlighter">',
                                      '').replace('</span>', '')
                artist = artist.replace('<span class="highlighter">',
                                        '').replace('</span>', '')
                album = album.replace('<span class="highlighter">',
                                      '').replace('</span>', '')
                url = DOWNLOAD_URL_PREFIX + url
                result.append(
                    SearchResult(title=title,
                                 artist=artist,
                                 album=album,
                                 sourceid=self.id,
                                 downloadinfo=url))
        return result
Esempio n. 9
0
    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