11DEFAULT_FIELDS = "Title,Author,ID,MD5"
22
3+ BASE_URL = "http://libgen.io/"
34LIBGEN_URL = "http://libgen.io/foreignfiction/"
45
56BOOK_ENDPOINT = "json.php?ids={0}&fields={1}"
@@ -58,12 +59,13 @@ def parse(node):
5859 return LibgenDownload (url , format , size , unit )
5960
6061class LibgenBook :
61- def __init__ (self , title , author , series , downloads , language ):
62+ def __init__ (self , title , author , series , downloads , language , image_url ):
6263 self .title = title
6364 self .author = author
6465 self .series = series
6566 self .downloads = downloads
6667 self .language = language
68+ self .image_url = image_url
6769
6870 @staticmethod
6971 def parse (node ):
@@ -72,6 +74,7 @@ def parse(node):
7274 TITLE_XPATH = '/td[3]'
7375 LANGUAGE_XPATH = '/td[4]'
7476 DOWNLOADS_XPATH = '/td[5]/div/a[1]'
77+ IMAGE_REGEX = re .compile ("\<\;img src=\" ?/(fictioncovers/.*?)\" ? .*?\>\;" )
7578
7679 author_result = xpath (node , AUTHOR_XPATH )
7780 author = author_result [0 ].text if len (author_result ) > 0 else 'Unknown'
@@ -85,7 +88,11 @@ def parse(node):
8588 if not author or not title :
8689 return None
8790
88- return LibgenBook (title , author , series , downloads , language )
91+ raw_html = etree .tostring (node )
92+ image_match = IMAGE_REGEX .search (raw_html )
93+ image_url = BASE_URL + image_match .groups (1 )[0 ] if image_match is not None else None
94+
95+ return LibgenBook (title , author , series , downloads , language , image_url )
8996
9097class LibgenSearchResults :
9198 def __init__ (self , results , total ):
0 commit comments