File size: 2,103 Bytes
6509820
a0c14f1
 
 
 
 
 
 
6509820
 
a0c14f1
 
6814f98
 
 
a0c14f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6509820
 
6d4e93b
c5da60b
30aaad8
c5da60b
6d4e93b
c5da60b
6d4e93b
 
30aaad8
c5da60b
30aaad8
6509820
c5da60b
a0c14f1
 
882a481
6814f98
 
a0c14f1
 
163719b
 
a0c14f1
 
 
 
 
6509820
163719b
a0c14f1
 
19137a2
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, Response, render_template, send_file, stream_with_context
import requests
import random
import pickle as pkl
import pycountry
import datetime as dt
import pytz

app = Flask(__name__)

with open('video_dict.pkl', 'rb') as f:
    feed_dict = pkl.load(f)
    
with open('live_urls.pkl', 'rb') as f:
    live_urls = pkl.load(f)

def get_ip_info(ip_address):
    try:
        response = requests.get(f"http://ipinfo.io/{ip_address}/json")
        data = response.json()
        return data
    except Exception as e:
        return {"error": str(e)}

def latlon_to_pixel(loc):
    latitude = float(loc.split(',')[0])
    longitude = float(loc.split(',')[1])

    y = ((90-latitude)/180)
    x = ((longitude+180)/360)
    return x*100, y*100

@app.route('/proxy/<path:url>')
def proxy(url):
    print('URL:', url)
    headers = {'User-Agent': 'Mozilla/5.0'}
    try:
        req = requests.get(f'http://{url}', headers=headers, stream=True, timeout=15)
        content_type = req.headers['content-type']
        
        return Response(req.iter_content(chunk_size=10*1024), content_type=content_type)
        
    except requests.exceptions.RequestException as e:
        print(f'Error: {e}')
        return send_file('static/error.png', mimetype='image/png')


@app.route('/')
def index():
    feed = random.randint(0, len(live_urls) - 1)
    #url = feed_dict[feed]['url']
    url = live_urls[feed]
    ip = ''.join(url.split('//')[-1]).split(':')[0]
    info = get_ip_info(ip)
    country = (pycountry.countries.get(alpha_2=info['country']).name).lower()
    name = (info['city'] + ", " + info['region'] + ", " + country).lower()
    org = info['org'].lower()
    timezone = pytz.timezone(info['timezone'])
    time = dt.datetime.now(timezone)
    loc = info['loc']
    X, Y = latlon_to_pixel(info['loc'])
    proxy_url = 'proxy/' + url.split('http://')[-1] 
    return render_template('index.html', name=name, url=proxy_url, info=info, country=country, time=time, ip=ip, org=org, loc=loc, X=X, Y=Y)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port='7860', debug=True)