improved evil xp https music download hack

This commit is contained in:
cidoku 2026-01-26 21:42:51 -03:00
parent 0018bc8ab4
commit 0d4ff0ff9d

View File

@ -73,19 +73,20 @@ def downloadThread(link, savepath):
return return
print "[client] Download missing: %s" % link print "[client] Download missing: %s" % link
fp = urllib.urlopen(bucket + link) print "[client] Trying to download from: %s" % (bucket + link)
fp = urlopen(bucket + link)
if fp.getcode() == 200: if fp.getcode() == 200:
print savepath[:-1] print "[client] Downloading to", savepath[:-1]
if not os.path.exists(savepath[:-1]): if not os.path.exists(savepath[:-1]):
os.makedirs(savepath[:-1]) os.makedirs(savepath[:-1])
with open(savepath, "wb") as f: with open(savepath, "wb") as f:
f.write(fp.read()) f.write(fp.read())
print "successfully downloaded:", link print "[client] Successfully downloaded:", link
return return
DOWNLOAD_BLACKLIST.append(link) DOWNLOAD_BLACKLIST.append(link)
print "couldn't download '%s'" % link print "[client] Couldn't download '%s'" % link
def mockString(text): def mockString(text):
upper = random.choice([True, False]) upper = random.choice([True, False])
@ -110,7 +111,7 @@ def mockString(text):
class XPMusicDownloadThread(QtCore.QThread): class XPMusicDownloadThread(QtCore.QThread):
# Part of the evil HTTPS music download hack for XP systems # Part of the evil HTTPS music download hack for XP systems
finished_signal = QtCore.pyqtSignal(int, str) finishedSignal = QtCore.pyqtSignal(int, str)
def __init__(self, caller, url): def __init__(self, caller, url):
super(XPMusicDownloadThread, self).__init__() super(XPMusicDownloadThread, self).__init__()
@ -127,53 +128,53 @@ class XPMusicDownloadThread(QtCore.QThread):
return return
headers = { headers = {
'User-Agent': "AO2XP %s" % (GAME_VERSION), 'User-Agent': "AO2XP %s" % GAME_VERSION,
'Accept': '*/*', 'Accept': '*/*',
'Accept-Encoding': 'identity', 'Accept-Encoding': 'identity',
'Connection': 'Keep-Alive' 'Connection': 'Keep-Alive'
} }
request = Request(url, headers=headers) request = Request(url, headers=headers)
#request.get_method = lambda: 'HEAD'
try: try:
response = urlopen(request, timeout=5) response = urlopen(request, timeout=5)
# print request.headers
# print response.headers
except Exception as e: except Exception as e:
print "[audio] HTTP request failed, aborting... Details below:" print "[audio] HTTP request failed, aborting..."
print "[audio]", e, url print "[audio]", e, url
self.quit() self.quit()
return return
file_length = int(response.headers.get('Content-Length', 0)) try:
fileLength = response.headers.get('Content-Length')
if fileLength is not None:
fileLength = int(fileLength)
if file_length > 0: chunks = []
request = Request(url, headers=headers) bytesDownloaded = 0
response = urlopen(request) bufferSize = 8192
stream = ""
bytes_downloaded = 0 while not self.exiting:
buffer_size = 8192 chunk = response.read(bufferSize)
while bytes_downloaded < file_length:
if self.exiting:
self.quit()
break
chunk = response.read(buffer_size)
if not chunk: if not chunk:
break break
stream += chunk chunks.append(chunk)
bytes_downloaded += len(chunk) bytesDownloaded += len(chunk)
if not self.exiting: if self.exiting:
self.caller.stream = create_string_buffer(stream) self.quit()
self.finished_signal.emit(file_length, self.url) return
else:
print "[audio] Stream is empty, aborting..." stream = ''.join(chunks)
self.quit()
return if fileLength is not None and bytesDownloaded != fileLength:
print "[audio] Warning: downloaded size mismatch"
self.caller.XPStream = create_string_buffer(stream)
self.finishedSignal.emit(bytesDownloaded, url)
finally:
response.close()
def stop(self): def stop(self):
self.exiting = True self.exiting = True
@ -1775,9 +1776,9 @@ class GUI(QtGui.QWidget):
self.guiltySfx = 0 self.guiltySfx = 0
self.notGuiltySfx = 0 self.notGuiltySfx = 0
self.stream = 0 self.XPStream = 0
self.specialStream = False self.specialStream = False
self.downloadThread = None self.XPDownloadThread = None
self.tcp = None self.tcp = None
self.demoPlayer = None self.demoPlayer = None
@ -4437,9 +4438,9 @@ class GUI(QtGui.QWidget):
self.specialStream = True self.specialStream = True
if (musl.startswith("https") and error == 2) or self.specialStream: if (musl.startswith("https") and error == 2) or self.specialStream:
print "[audio] Downloading music with urllib2" print "[audio] Downloading music with urllib2"
self.downloadThread = XPMusicDownloadThread(self, mus.replace(" ", "%20")) self.XPDownloadThread = XPMusicDownloadThread(self, mus.replace(" ", "%20"))
self.downloadThread.finished_signal.connect(self.playDownloadedMusic) self.XPDownloadThread.finishedSignal.connect(self.playDownloadedMusic)
self.downloadThread.start() self.XPDownloadThread.start()
else: else:
print "[audio] Couldn't play music. Error", error print "[audio] Couldn't play music. Error", error
@ -4452,19 +4453,19 @@ class GUI(QtGui.QWidget):
self.specialStream = False self.specialStream = False
else: else:
audio.freeHandle(self.music) audio.freeHandle(self.music)
if self.stream: if self.XPStream:
self.stream = None self.XPStream = None
if self.downloadThread: if self.XPDownloadThread:
self.downloadThread.stop() self.XPDownloadThread.stop()
self.downloadThread = None self.XPDownloadThread = None
def playDownloadedMusic(self, file_length, url): def playDownloadedMusic(self, fileLength, url):
# Part of the evil HTTPS music download hack for XP systems # Part of the evil HTTPS music download hack for XP systems
if self.specialStream: if self.specialStream:
self.music = audio.loadMOD(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) self.music = audio.loadMOD(True, self.XPStream, 0, fileLength, BASS_SAMPLE_LOOP)
else: else:
self.music = audio.loadHandle(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) self.music = audio.loadHandle(True, self.XPStream, 0, fileLength, BASS_SAMPLE_LOOP)
if self.music: if self.music:
print "[audio] Done downloading; playing stream" print "[audio] Done downloading; playing stream"
audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0) audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0)