├── Main.py ├── README.md ├── SVPlayerHash.py └── Shooter.py /Main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | Created on Jan 20, 2014 4 | 5 | @author: magic282 6 | ''' 7 | import sys 8 | from Shooter import Shooter 9 | 10 | if __name__ == '__main__': 11 | print("Welcome to ShooterSubPyDownloader") 12 | 13 | fileNames = sys.argv[1:] 14 | 15 | for f in fileNames: 16 | shooter = Shooter(f) 17 | shooter.start() 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ShooterSubPyDownloader 2 | ====================== 3 | 4 | This is a shooter.cn subtitle download tool using Python. 5 | 6 | A C# version for Windows is [here](https://github.com/magic282/ShooterSubDownloader). 7 | -------------------------------------------------------------------------------- /SVPlayerHash.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | Created on Jan 20, 2014 4 | 5 | @author: magic282 6 | 7 | https://docs.google.com/document/d/1w5MCBO61rKQ6hI5m9laJLWse__yTYdRugpVyz4RzrmM/preview 8 | ''' 9 | 10 | import os 11 | import hashlib 12 | 13 | 14 | class SVPlayerHash(object): 15 | ''' 16 | classdocs 17 | ''' 18 | 19 | @staticmethod 20 | def ComputeFileHash(fileName): 21 | ret = "" 22 | try: 23 | vfile = open(fileName, "rb") 24 | except IOError: 25 | print("Cannot read file %s" % fileName) 26 | 27 | statinfo = os.stat(fileName) 28 | fLength = statinfo.st_size 29 | 30 | ret = [] 31 | for i in (4096, int(fLength/3)*2, int(fLength/3), fLength-8192): 32 | vfile.seek(i, 0) 33 | bBuf = vfile.read(4096) 34 | ret.append(hashlib.md5(bBuf).hexdigest()) 35 | vfile.close() 36 | return ';'.join(ret) 37 | 38 | def __init__(self, params): 39 | ''' 40 | Constructor 41 | ''' 42 | -------------------------------------------------------------------------------- /Shooter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ''' 3 | Created on Jan 20, 2014 4 | 5 | @author: magic282 6 | ''' 7 | 8 | from SVPlayerHash import SVPlayerHash 9 | try: # Python 3 10 | from urllib.parse import urlencode 11 | from urllib.request import Request, urlopen 12 | except ImportError: # Python 2 13 | from urllib import urlencode 14 | from urllib2 import Request, urlopen 15 | import json 16 | 17 | 18 | class Shooter(object): 19 | ''' 20 | classdocs 21 | ''' 22 | 23 | __SHOOTERURL = "http://shooter.cn/api/subapi.php" 24 | 25 | __fileName = "" 26 | __videoHash = "" 27 | 28 | __subInfo = [] 29 | 30 | def start(self): 31 | self.__videoHash = SVPlayerHash.ComputeFileHash(self.__fileName) 32 | values = dict(filehash=self.__videoHash, pathinfo=self.__fileName, format="json", lang="Chn") 33 | data = urlencode(values).encode('utf-8', 'replace') 34 | req = Request(self.__SHOOTERURL, data) 35 | rsp = urlopen(req) 36 | content = rsp.read().decode('utf-8', 'replace') 37 | 38 | jsonContent = json.loads(content) 39 | for idx_i, i in enumerate(jsonContent): 40 | print(i) 41 | 42 | if i["Delay"] != 0: 43 | delayFileName = '.'.join((self.__fileName, "chn%s" % ("" if idx_i == 0 else idx_i), "delay")) 44 | with open(delayFileName, 'w') as output: 45 | output.write(str(i["Delay"])) 46 | for idx_j, j in enumerate(i["Files"]): 47 | outFileNameList = [self.__fileName, "chn%s" % ("" if idx_i == 0 else idx_i), str(j["Ext"])] 48 | if len(i["Files"]) != 1: 49 | outFileNameList.insert(2, str(idx_j)) 50 | outFileName = '.'.join(outFileNameList) 51 | dLink = j["Link"] 52 | print(dLink) 53 | response = urlopen(dLink) 54 | backF = response.read() 55 | with open(outFileName, 'wb') as output: 56 | output.write(backF) 57 | 58 | def __init__(self, params): 59 | ''' 60 | Constructor 61 | ''' 62 | self.__fileName = params 63 | --------------------------------------------------------------------------------