@@ -36,10 +36,10 @@ def __init__(self, url, format, size, unit):
3636 self .unit = unit
3737
3838 @staticmethod
39- def parse (node ):
40- url = node .get ('href' ). replace ( 'ads.php' , 'get.php' )
39+ def parse (node , file_type , file_size , file_size_unit ):
40+ url = node .get ('href' )
4141
42- return LibgenDownload (url , 'EPUB' , 'Unknown' , 'Unknown' )
42+ return LibgenDownload (url , file_type , file_size , file_size_unit )
4343
4444class LibgenBook :
4545 def __init__ (self , title , author , series , downloads , language , image_url ):
@@ -56,7 +56,7 @@ def parse(node):
5656 SERIES_XPATH = '/td[2]'
5757 TITLE_XPATH = '/td[3]/a'
5858 LANGUAGE_XPATH = '/td[4]'
59- # FILE_XPATH = '/td[5]'
59+ FILE_XPATH = '/td[5]'
6060 DOWNLOADS_XPATH = '/td[6]//a'
6161
6262 author_result = xpath (node , AUTHOR_XPATH )
@@ -66,14 +66,19 @@ def parse(node):
6666 series = xpath (node , SERIES_XPATH )[0 ].text
6767 title = xpath (node , TITLE_XPATH )[0 ].text
6868 language = xpath (node , LANGUAGE_XPATH )[0 ].text
69+ file_info = xpath (node , FILE_XPATH )[0 ].text .encode ('utf-8' )
70+ file_type , file_size = file_info .split (' / ' )
71+ file_size , file_size_unit = file_size .split ('\xc2 \xa0 ' )
6972
7073 downloads_nodes = xpath (node , DOWNLOADS_XPATH )
71- downloads = [LibgenDownload .parse (n ) for n in downloads_nodes ]
74+ downloads = [
75+ LibgenDownload .parse (n , file_type , file_size , file_size_unit )
76+ for n in downloads_nodes ]
7277
7378 if not author and not title :
7479 return None
7580
76- return LibgenBook (title , author , series , downloads [ 0 : 1 ] , language , None )
81+ return LibgenBook (title , author , series , downloads , language , None )
7782
7883class LibgenSearchResults :
7984 def __init__ (self , results , total ):
@@ -109,7 +114,7 @@ def search(self, query):
109114 'q' : query ,
110115 'criteria' : '' ,
111116 'language' : '' ,
112- 'format' : 'epub ' ,
117+ 'format' : '' ,
113118 }
114119
115120 query_string = urllib .urlencode (query_params )
0 commit comments