Skip to content

Commit 23d7042

Browse files
committed
Add file format, size and unit to download info
1 parent 5d290ea commit 23d7042

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ def search(query, max_results=10, timeout=60):
6161
print('CalibreLibgenStore:search:result.download.url = {}'.format(
6262
download.url))
6363

64-
s.downloads[download.format] = download.url
64+
s.downloads['{} ({} {})'.format(
65+
download.format,
66+
download.size,
67+
download.unit
68+
)] = download.url
6569

6670
s.formats = ', '.join(s.downloads.keys())
6771
s.drm = SearchResult.DRM_UNLOCKED

libgen_client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4444
class 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

7883
class 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

Comments
 (0)