Skip to content

Instantly share code, notes, and snippets.

@bcho
Created July 20, 2015 14:32
Show Gist options
  • Save bcho/94615fe82c68d6d57f47 to your computer and use it in GitHub Desktop.
Save bcho/94615fe82c68d6d57f47 to your computer and use it in GitHub Desktop.
trick
'''A simple script for extracting xiami song url.'''
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
def decode(location):
encoded = location[1:]
total_chars = len(encoded)
col = int(location[0])
row, remains = int(float(total_chars) / col), total_chars % col
address = ['' * col] * total_chars
sizes = [row + 1] * remains + [row] * (col - remains)
pos = 0
for i, size in enumerate(sizes):
for index in range(size):
if pos + index < total_chars:
address[col * index + i] = encoded[pos + index]
pos = pos + size
join = lambda x: ''.join(x)
return unquote(join(map(join, address))).replace('^', '0')
location = ('7h%5xo4%2_lFe4d9a9355t2.im%2F9.ay116757EEtFfa%2F15mu'
'%bb6b44%-p%im2F929pt3fb4b435n%2liF29393hDbb6%-6Eu3Fe.'
'22243%_ec2d518-lAm.c24%5_3k7fdbE4%%l')
print(decode(location))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment