-
Notifications
You must be signed in to change notification settings - Fork 148
/
announce_server.py
50 lines (38 loc) · 1.22 KB
/
announce_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#encoding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests
import sys
import time
import urlparse
import datetime
import xmlrpclib
from flask import Flask, request, abort
import pygeoip
from bencode import bencode
geoip = pygeoip.GeoIP('GeoIP.dat')
app = Flask(__name__)
app.debug = False
rpc = xmlrpclib.ServerProxy('http://127.0.0.1:8004')
@app.route('/announce.php')
def announce():
'''/announce.php?info_hash=&peer_id=&ip=&port=&uploaded=&downloaded=&left=&numwant=&key=&compact=1'''
ip = request.args.get('ip')
port = request.args.get('port')
if not ip or not port:
return abort(404)
address = (ip, int(port))
binhash = urlparse.parse_qs(request.query_string)['info_hash'][0]
country = geoip.country_code_by_addr(ip)
if country not in ('CN','TW','JP','HK', 'KR'):
return abort(404)
rpc.announce(binhash.encode('hex'), address)
return bencode({'peers': '', 'interval': 86400})
@app.route('/announce/m3u8')
def m3u8():
url = 'http://tsymq.aliapp.com/baidu/file/index.php?uid=4013230200&uuid=56178f0f05b22&w=100%&h=100%&type=m3u8'
r = requests.get(url)
return r.content
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8005)