-
Notifications
You must be signed in to change notification settings - Fork 3
/
google.py
61 lines (49 loc) · 2.12 KB
/
google.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
50
51
52
53
54
55
56
57
58
59
60
61
from url_utils import UrlPathEncode
from parseGoogle import parseGoogleResult
GOOGLEURL = "https://www.google.com/search?ie=utf-8&oe=utf-8&q="
GOOGLEBASESEARCH = "comixology.com \"digital-comic\" \"{0} ({1}\" \"#{2}\""
COMICFORMATSEARCH = ' {0}'
def buildGoogleQueryURL(series, volume, issue, format, debug = False):
QS = GOOGLEBASESEARCH.format(series, volume, issue)
if format and format == 'Annual':
QS += COMICFORMATSEARCH.format(format)
QS = UrlPathEncode(QS)
URL = GOOGLEURL + QS
if debug:
print(URL)
return URL
def googleSeries(series, volume, issue, format, debug = False):
URL = buildGoogleQueryURL(series, volume, issue, format)
if debug:
print(URL)
return parseGoogleResult(URL, debug)
def findCMXID(series, volume, issue, format, debug = False):
CMXID = googleSeries(series, volume, issue, format, debug)
if CMXID is None and ' Annual' in series:
#check for Annual (maybe other formats?) in series name
if debug:
print("Remove Annual from series name and try again")
CMXID = findCMXID(series.replace(' Annual', ''), volume, issue, 'Annual', debug)
if CMXID is None:
#try without volume, if one was passed in
if debug:
print("Trying without volume")
CMXID = googleSeries(series, '', issue, format, debug)
if CMXID is None and series[0:4] == 'The ':
#try removing leading The
if debug:
print("Removing leading 'The '")
CMXID = googleSeries(series.replace('The ', '', 1), volume, issue, format, debug)
if CMXID is None and issue == '1':
#graphic novels, some one-shots don't have a number on CMX
if debug:
print("Trying without issue number")
CMXID = googleSeries(series, volume, '', format, debug)
if CMXID is None and issue == '1':
#graphic novels, some one-shots don't have a number on CMX
if debug:
print("Trying without issue number and without volume")
CMXID = googleSeries(series, '', '', format, debug)
if CMXID == -1:
CMXID = None
return CMXID