Skip to content

Instantly share code, notes, and snippets.

@XiaoGeNintendo
Last active January 6, 2021 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XiaoGeNintendo/ed00f9ecbb30db273069f467ffd0fb40 to your computer and use it in GitHub Desktop.
Save XiaoGeNintendo/ed00f9ecbb30db273069f467ffd0fb40 to your computer and use it in GitHub Desktop.
(TSRT) Source Generator THBwiki
'''
Touhou Music To Address From Thwiki
'''
import re
import urllib.request
import sys
import json
def getURL(url):
# print("访问开始:"+url)
request=urllib.request.Request(url)
response=urllib.request.urlopen(request)
html=response.read()
return html.decode('utf-8')
cate="N/A"
with open("test.txt","r",encoding="UTF-8") as f:
with open("out.txt","w",encoding="UTF-8") as of:
read=f.readlines()
count=1
x=int(input("Start position:"))
for line in read:
line=line.strip()
if '/' in line:
if count<x:
count+=1
continue
name=line.split("/")[0].strip()
print(count,"/",len(read),"-",cate,name)
url="https://thwiki.cc/"+urllib.parse.quote(name.replace(" ","_"))
res=getURL(url)
res2=re.search('"https:\\/\\/upload\\.thwiki\\.cc\\/.\\/..\\/.+\\.((ogg)|(mp3))"',res)
if res2==None:
print("[WARNING] NO LINK FOUND")
else:
add=res[(res2.span()[0]+1):(res2.span()[1]-1)]
of.write(name+"!!!"+cate+"!!!"+add+"\n")
of.flush()
else:
cate=line
count+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment