3 Scraper for http://lrcct2.ttplayer.com/
16 __title__ =
"TTPlayer"
20 UserAgent =
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0'
22 socket.setdefaulttimeout(10)
24 LYRIC_TITLE_STRIP=[
"\(live[^\)]*\)",
"\(acoustic[^\)]*\)",
25 "\([^\)]*mix\)",
"\([^\)]*version\)",
26 "\([^\)]*edit\)",
"\(feat[^\)]*\)"]
27 LYRIC_TITLE_REPLACE=[(
"/",
"-"),(
" & ",
" and ")]
28 LYRIC_ARTIST_REPLACE=[(
"/",
"-"),(
" & ",
" and ")]
32 privide ttplayer specific function, such as encoding artist and title,
33 generate a Id code for server authorizition.
34 (see http://ttplyrics.googlecode.com/svn/trunk/crack)
40 These code may be ugly coz it is translated
41 from C code which is translated from asm code
42 grabed by ollydbg from ttp_lrcs.dll.
43 (see http://ttplyrics.googlecode.com/svn/trunk/crack)
50 tmp1 = (Id & 0x0000FF00) >> 8
53 if ((Id & 0x00FF0000) == 0):
54 tmp3 = 0x000000FF & ~tmp1
56 tmp3 = 0x000000FF & ((Id & 0x00FF0000) >> 16)
58 tmp3 = tmp3 | ((0x000000FF & Id) << 8)
60 tmp3 = tmp3 | (0x000000FF & tmp1)
62 if ((Id & 0xFF000000) == 0) :
63 tmp3 = tmp3 | (0x000000FF & (~Id))
65 tmp3 = tmp3 | (0x000000FF & (Id >> 24))
74 tmp1 = (char + tmp2) & 0x00000000FFFFFFFF
75 tmp2 = (tmp2 << (i%2 + 4)) & 0x00000000FFFFFFFF
76 tmp2 = (tmp1 + tmp2) & 0x00000000FFFFFFFF
87 tmp7 = (char + tmp1) & 0x00000000FFFFFFFF
88 tmp1 = (tmp1 << (i%2 + 3)) & 0x00000000FFFFFFFF
89 tmp1 = (tmp1 + tmp7) & 0x00000000FFFFFFFF
97 tmp1 = (((((tmp2 ^ tmp3) & 0x00000000FFFFFFFF) + (tmp1 | Id)) & 0x00000000FFFFFFFF) * (tmp1 | tmp3)) & 0x00000000FFFFFFFF
98 tmp1 = (tmp1 * (tmp2 ^ Id)) & 0x00000000FFFFFFFF
100 if tmp1 > 0x80000000:
101 tmp1 = tmp1 - 0x100000000
106 data = data.encode(
'UTF-16').decode(
'UTF-16')
108 for i
in range(len(data)):
109 rtn +=
'%02x00' % ord(data[i])
115 self.
LIST_URL =
'http://ttlrccnc.qianqian.com/dll/lyricsvr.dll?sh?Artist=%s&Title=%s&Flags=0'
116 self.
LYRIC_URL =
'http://ttlrccnc.qianqian.com/dll/lyricsvr.dll?dl?Id=%d&Code=%d&uid=01&mac=%012x'
119 log(
"%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title))
122 lyrics.source = __title__
127 for exp
in LYRIC_ARTIST_REPLACE:
128 p = re.compile(exp[0])
129 artist = p.sub(exp[1], artist)
130 for exp
in LYRIC_TITLE_REPLACE:
131 p = re.compile(exp[0])
132 title = p.sub(exp[1], title)
135 for exp
in LYRIC_TITLE_STRIP:
137 title = p.sub(
'', title)
140 title = title.strip().replace(
'`',
'').replace(
'/',
'')
141 artist = artist.strip().replace(
'`',
'').replace(
'/',
'')
144 url = self.
LIST_URL %(ttpClient.EncodeArtTit(artist.replace(
' ',
'').lower()), ttpClient.EncodeArtTit(title.replace(
' ',
'').lower()))
145 f = urllib.request.urlopen(url)
146 Page = f.read().decode(
'utf-8')
148 log(
"%s: %s::%s (%d) [%s]" % (
149 __title__, self.__class__.__name__,
150 sys.exc_info()[2].tb_frame.f_code.co_name,
151 sys.exc_info()[2].tb_lineno,
155 links_query = re.compile(
'<lrc id=\"(.*?)\" artist=\"(.*?)\" title=\"(.*?)\"></lrc>')
156 urls = re.findall(links_query, Page)
159 if (difflib.SequenceMatcher(
None, artist.lower(), x[1].lower()).ratio() > 0.8)
and (difflib.SequenceMatcher(
None, title.lower(), x[2].lower()).ratio() > 0.8):
160 links.append((x[1] +
' - ' + x[2], x[0], x[1], x[2]))
167 if lyr
and lyr.startswith(
'['):
173 title,Id,artist,song = link
176 url = self.
LYRIC_URL %(int(Id),ttpClient.CodeFunc(int(Id), artist + song), random.randint(0,0xFFFFFFFFFFFF))
177 log(
'%s: search url: %s' % (__title__, url))
178 header = {
'User-Agent':UserAgent}
179 req = urllib.request.Request(url, headers=header)
180 f = urllib.request.urlopen(req)
181 Page = f.read().decode(
'utf-8')
183 log(
"%s: %s::%s (%d) [%s]" % (
184 __title__, self.__class__.__name__,
185 sys.exc_info()[2].tb_frame.f_code.co_name,
186 sys.exc_info()[2].tb_lineno,
191 if Page.startswith(
'[ti:'):
192 check = Page.split(
'\n')
193 if not check[0][4:-1] ==
'':
194 if (difflib.SequenceMatcher(
None, song.lower(), check[0][4:-1].lower()).ratio() > 0.8):
198 if check[1][0:4] ==
'[ar:' and not check[1][4:-1] ==
'':
199 if (difflib.SequenceMatcher(
None, artist.lower(), check[1][4:-1].lower()).ratio() > 0.8):
205 elif Page.startswith(
'['):