-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdate-webcam-urls.py
More file actions
152 lines (122 loc) · 5.92 KB
/
Copy pathupdate-webcam-urls.py
File metadata and controls
152 lines (122 loc) · 5.92 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Google Image Search Scraper that searches for known WebCam URL patterns (works in August of 2016)
# by awgh@awgh.org
# This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
import urllib2
import ssl
from bs4 import BeautifulSoup
import json
import os
import geoip2.database
import linecache
import sys
import xml.etree.cElementTree as ET
from urlparse import urlparse
root = ET.Element("urls")
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
geoip = geoip2.database.Reader('GeoLite2-City.mmdb')
def get_soup(url,header):
content = urllib2.urlopen(urllib2.Request(url,headers=header)).read()
#print content
return BeautifulSoup(content, 'html.parser')
def googleImageSearch(query, DIR = None, TAG = None):
url="https://www.google.com/search?q="+query+"&source=lnms&tbm=isch"
print url
header={'User-Agent':"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"}
soup = get_soup(url,header)
ActualImages=[]# contains the link for Large original images, type of image
for a in soup.find_all("div",{"class":"rg_meta"}):
link , Type =json.loads(a.text)["ou"] ,json.loads(a.text)["ity"]
print link +':::'+Type
ActualImages.append((link,Type))
print "there are total" , len(ActualImages),"images"
if(DIR != None and TAG != None): # save images if DIR and TAG are set
if not os.path.exists(DIR):
os.mkdir(DIR)
DIR = os.path.join(DIR, TAG)
if not os.path.exists(DIR):
os.mkdir(DIR)
for i , (img , Type) in enumerate( ActualImages):
try:
pr = urlparse(img)
q = query
if query.startswith('inurl'):
q = query[7:-1]
if not q.lower().startswith(pr[2].lower()):
print 'MISMATCH:'
print q +' -> '+pr[2]
continue
req = urllib2.Request(img, headers={'User-Agent' : header})
resp = urllib2.urlopen(req, timeout=10.0, context=ctx)
mime = resp.headers['Content-Type']
peer = resp.fp._sock.fp._sock.getpeername()
imageMime = False
if mime.startswith('image/') or mime == 'application/octet-stream':
imageMime = True
if(DIR != None and TAG != None and imageMime):
raw_img = resp.read()
cntr = len([i for i in os.listdir(DIR) if TAG in i]) + 1
if len(Type)==0:
f = open(os.path.join(DIR , TAG + "_"+ str(cntr)+".jpg"), 'wb')
else :
f = open(os.path.join(DIR , TAG + "_"+ str(cntr)+"."+Type), 'wb')
f.write(raw_img)
f.close()
# if we make it to here, save link
g = geoip.city(peer[0])
et = ET.SubElement(root, "url")
et.attrib['link'] = img
if mime:
et.attrib['mime'] = mime
if peer:
et.attrib['ip'] = peer[0]
et.attrib['port'] = str(int(peer[1]))
if g:
if g.city and g.city.name:
et.attrib['city'] = g.city.name
if g.subdivisions and g.subdivisions.most_specific and g.subdivisions.most_specific.name:
et.attrib['region'] = g.subdivisions.most_specific.name
if g.country and g.country.name:
et.attrib['country'] = g.country.name
if g.location:
if g.location.latitude:
et.attrib['lat'] = str(float(g.location.latitude))
if g.location.longitude:
et.attrib['long'] = str(float(g.location.longitude))
except Exception as e:
PrintException()
def googleImageInURLSearch(query, DIR = None, TAG = None):
googleImageSearch("inurl:\""+query+"\"", DIR, TAG)
googleImageInURLSearch("/jpg/image.jpg?r=", "Pictures", "Axis_JPEG")
googleImageInURLSearch("/mjpg/video.mjpg", "Pictures", "Axis_MJPEG")
googleImageInURLSearch("/axis-cgi/jpg/image.cgi?resolution=", "Pictures", "Axis2_MJPEG")
googleImageInURLSearch("/record/current.jpg", "Pictures", "Mobotix_JPEG")
googleImageInURLSearch("/cgi-bin/faststream.jpg?stream=", "Pictures", "Mobotix_MJPEG")
googleImageInURLSearch("/oneshotimage.jpg", "Pictures", "SNC_JPEG")
googleImageInURLSearch("/SnapshotJPEG?Resolution=", "Pictures", "Panasonic_JPEG")
googleImageInURLSearch("/nphMotionJpeg?Resolution=", "Pictures", "Panasonic_MJPEG")
googleImageInURLSearch("/cgi-bin/video.jpg?resolution=", "Pictures", "Vivotek_JPEG")
googleImageInURLSearch("/Jpeg/CamImg.jpg", "Pictures", "ORite_JPEG")
googleImageInURLSearch("?action-snapshot", "Pictures", "Veo_JPEG")
googleImageInURLSearch("?action-stream", "Pictures", "Veo_MJPEG")
googleImageInURLSearch("/GetData.cgi", "Pictures", "Veo2_JPEG")
googleImageInURLSearch("/videostream.cgi", "Pictures", "3G_MJPEG")
googleImageInURLSearch("/video.cgi?resolution=VGA", "Pictures", "Other1_MJPEG")
googleImageInURLSearch("/live?camera=", "Pictures", "Other2_MJPEG")
googleImageInURLSearch("/videofeed", "Pictures", "Other3_MJPEG")
googleImageInURLSearch("/video?submenu=mjpg", "Pictures", "Other4_MJPEG")
googleImageInURLSearch("/snapshot.jpg?", "Pictures", "Other1_JPEG")
googleImageInURLSearch("/cgi-bin/snapshot.cgi", "Pictures", "Other2_JPEG")
tree = ET.ElementTree(root)
tree.write("urls.xml")
geoip.close()
print "Completed"