From bf5591949253442ff7d25bccf84acfdcce6cf08f Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Fri, 18 Oct 2024 23:04:31 +0200 Subject: [PATCH 01/10] Added covers, fixed getting all torrent - Fixed issue that prevented to call the search function with the number=None argument - Added poster images to be included in torrent object --- ncoreparser/client.py | 2 +- ncoreparser/client_async.py | 2 +- ncoreparser/parser.py | 17 ++++++++++++++--- ncoreparser/torrent.py | 3 ++- tests/manual.py | 12 ++++++------ tests/manual_async.py | 11 ++++++----- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/ncoreparser/client.py b/ncoreparser/client.py index 1dfd1ed..68e2723 100644 --- a/ncoreparser/client.py +++ b/ncoreparser/client.py @@ -79,7 +79,7 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] - if number is None or len(new_torrents) == 0: + if len(new_torrents) == 0: return torrents torrents.extend(new_torrents) page_count += 1 diff --git a/ncoreparser/client_async.py b/ncoreparser/client_async.py index 3f818fc..5c316c1 100644 --- a/ncoreparser/client_async.py +++ b/ncoreparser/client_async.py @@ -81,7 +81,7 @@ async def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamW except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] - if number is None or len(new_torrents) == 0: + if len(new_torrents) == 0: return torrents torrents.extend(new_torrents) page_count += 1 diff --git a/ncoreparser/parser.py b/ncoreparser/parser.py index 01547ed..1a172b9 100644 --- a/ncoreparser/parser.py +++ b/ncoreparser/parser.py @@ -15,6 +15,7 @@ def __init__(self): self.not_found_pattern = re.compile(r'
Nincs találat!
') self.seeders_pattern = re.compile(r'
([0-9]+)
') self.leechers_pattern = re.compile(r'
([0-9]+)
') + self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?\')') @staticmethod def get_key(data): @@ -32,17 +33,25 @@ def get_items(self, data): sizes = self.size_pattern.findall(data) seed = self.seeders_pattern.findall(data) leech = self.leechers_pattern.findall(data) + poster_image = self.poster_image_pattern.findall(data) + + # There can be torrents without poster_image + if (len(poster_image) < len(leech)): + for i in range(len(poster_image), len(leech)): + poster_image.append('no cover') + if len(types) != 0 and len(types) == len(ids_names) == \ - len(dates_times) == len(sizes) == len(seed) == len(leech): + len(dates_times) == len(sizes) == len(seed) == len(leech) == len(poster_image): ids, names = zip(*ids_names) dates, times = zip(*dates_times) key = self.get_key(data) else: if not self.not_found_pattern.search(data): raise NcoreParserError(f"Error while parse download items in {self.__class__.__name__}.") + return for i, id in enumerate(ids): yield {"id": id, "title": names[i], "key": key, "date": parse_datetime(dates[i], times[i]), - "size": Size(sizes[i]), "type": SearchParamType(types[i]), "seed": seed[i], "leech": leech[i]} + "size": Size(sizes[i]), "type": SearchParamType(types[i]), "seed": seed[i], "leech": leech[i], "poster_image": poster_image[i]} class TorrenDetailParser: @@ -57,6 +66,7 @@ def __init__(self): self.peers_pattern = re.compile(r'div class="dt">Seederek:.*?.*?
Leecherek:
.*?
(?P[0-9]+)
', re.DOTALL) + self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?)\'') def get_item(self, data): try: @@ -69,9 +79,10 @@ def get_item(self, data): peers = self.peers_pattern.search(data) seed = peers.group('seed') leech = peers.group('leech') + poster_image = self.poster_image_pattern except AttributeError as e: raise NcoreParserError(f"Error while parsing by detailed page. {e}") from e - return {"title": title, "key": key, "date": date, "size": size, "type": t_type, 'seed': seed, 'leech': leech} + return {"title": title, "key": key, "date": date, "size": size, "type": t_type, 'seed': seed, 'leech': leech, 'poster_image': poster_image} class RssParser: diff --git a/ncoreparser/torrent.py b/ncoreparser/torrent.py index 392250c..9da61d8 100644 --- a/ncoreparser/torrent.py +++ b/ncoreparser/torrent.py @@ -4,7 +4,7 @@ class Torrent: def __init__(self, id, title, key, size, #pylint: disable=too-many-arguments - type, date, seed, leech, **params): #pylint: disable=too-many-arguments + type, date, seed, leech, poster_image, **params): #pylint: disable=too-many-arguments self._details = {} self._details["id"] = int(id) self._details["title"] = title @@ -14,6 +14,7 @@ def __init__(self, id, title, key, size, #pylint: disable=too-many-arguments self._details["date"] = date self._details["seed"] = seed self._details["leech"] = leech + self._details["poster_image"] = poster_image self._details["download"] = URLs.DOWNLOAD_LINK.value.format(id=id, key=key) self._details.update(params) diff --git a/tests/manual.py b/tests/manual.py index 0596a85..d65c29b 100644 --- a/tests/manual.py +++ b/tests/manual.py @@ -2,14 +2,13 @@ import argparse from ncoreparser import Client, SearchParamType, ParamSort, ParamSeq - def print_category(msg): print("") print("*{:175}*".format("-" * 175)) print(f"|{msg:^175}|") - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech")) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) def pretty_print(torrent): @@ -18,8 +17,9 @@ def pretty_print(torrent): str(torrent['size']), str(torrent['id']), torrent['seed'], - torrent['leech'])) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + torrent['leech'], + torrent['poster_image'])) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) parser = argparse.ArgumentParser() diff --git a/tests/manual_async.py b/tests/manual_async.py index 07a596b..5070112 100644 --- a/tests/manual_async.py +++ b/tests/manual_async.py @@ -8,9 +8,9 @@ def print_category(msg): print("") print("*{:175}*".format("-" * 175)) print(f"|{msg:^175}|") - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech")) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) def pretty_print(torrent): @@ -19,8 +19,9 @@ def pretty_print(torrent): str(torrent['size']), str(torrent['id']), torrent['seed'], - torrent['leech'])) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + torrent['leech'], + torrent['poster_image'])) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) parser = argparse.ArgumentParser() From 3f5212dd320c9bd4417261d1956d9fae07ccea06 Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Sat, 19 Oct 2024 22:20:09 +0200 Subject: [PATCH 02/10] Fixed poster regexp --- ncoreparser/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ncoreparser/parser.py b/ncoreparser/parser.py index 1a172b9..3b2d27d 100644 --- a/ncoreparser/parser.py +++ b/ncoreparser/parser.py @@ -15,7 +15,7 @@ def __init__(self): self.not_found_pattern = re.compile(r'
Nincs találat!
') self.seeders_pattern = re.compile(r'') self.leechers_pattern = re.compile(r'') - self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?\')') + self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?)(?=\')') @staticmethod def get_key(data): From f112df3252bdea1907087ae3210815207066705a Mon Sep 17 00:00:00 2001 From: bmago Date: Fri, 25 Oct 2024 09:10:08 +0200 Subject: [PATCH 03/10] Bumped version to 2.2.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f92d4ae..808f4d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "ncoreparser" -version = "2.1.2" +version = "2.2.0" description = "Package to download from ncore.pro" authors = [ { name="Aron Radics", email="aron.radics.jozsef@gmail.com" } From 8b189e8e8a6ef977d1e9764b8c0e2245f1c65a49 Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Fri, 1 Nov 2024 22:37:29 +0100 Subject: [PATCH 04/10] fixed infinit loop when no search pattern defined --- ncoreparser/client.py | 3 +++ tests/manual.py | 5 +++++ tests/manual_async.py | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/ncoreparser/client.py b/ncoreparser/client.py index 68e2723..74fd455 100644 --- a/ncoreparser/client.py +++ b/ncoreparser/client.py @@ -67,6 +67,9 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N sort_by=ParamSort.UPLOAD, sort_order=ParamSeq.DECREASING, number=None): page_count = 1 torrents = [] + if (pattern == ""): + return torrents + while number is None or len(torrents) < number: url = URLs.DOWNLOAD_PATTERN.value.format(page=page_count, t_type=type.value, diff --git a/tests/manual.py b/tests/manual.py index d65c29b..ed710c8 100644 --- a/tests/manual.py +++ b/tests/manual.py @@ -65,6 +65,11 @@ def pretty_print(torrent): for torrent in torrents: pretty_print(torrent) + print_category("Test number=None && pattern=''") + torrents = client.search(pattern="") + for torrent in torrents: + pretty_print(torrent) + client.logout() end = time.time() diff --git a/tests/manual_async.py b/tests/manual_async.py index 5070112..7132f46 100644 --- a/tests/manual_async.py +++ b/tests/manual_async.py @@ -66,6 +66,11 @@ async def main(): for torrent in torrents: pretty_print(torrent) + print_category("Test number=None && pattern=''") + torrents = await client.search(pattern="") + for torrent in torrents: + pretty_print(torrent) + await client.logout() end = time.time() From cf1456c435067aafe34407f25009874efbc404d2 Mon Sep 17 00:00:00 2001 From: bmago Date: Tue, 5 Nov 2024 12:21:46 +0100 Subject: [PATCH 05/10] fixed infinit loop & poster img - Fixed infinit loop when not defining number, -1 means give me all torrent - Fixed issue regarding the torrents which does not have any poster --- ncoreparser/client.py | 7 ++----- ncoreparser/client_async.py | 4 ++-- ncoreparser/parser.py | 42 ++++++++++++++++++++++++++----------- tests/manual.py | 7 ++++++- tests/manual_async.py | 7 ++++++- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/ncoreparser/client.py b/ncoreparser/client.py index 74fd455..77fc6ce 100644 --- a/ncoreparser/client.py +++ b/ncoreparser/client.py @@ -67,10 +67,7 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N sort_by=ParamSort.UPLOAD, sort_order=ParamSeq.DECREASING, number=None): page_count = 1 torrents = [] - if (pattern == ""): - return torrents - - while number is None or len(torrents) < number: + while number is None or number == -1 or len(torrents) < number: url = URLs.DOWNLOAD_PATTERN.value.format(page=page_count, t_type=type.value, sort=sort_by.value, @@ -82,7 +79,7 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] - if len(new_torrents) == 0: + if number is None or len(new_torrents) == 0: return torrents torrents.extend(new_torrents) page_count += 1 diff --git a/ncoreparser/client_async.py b/ncoreparser/client_async.py index 5c316c1..c5d5e67 100644 --- a/ncoreparser/client_async.py +++ b/ncoreparser/client_async.py @@ -69,7 +69,7 @@ async def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamW sort_by=ParamSort.UPLOAD, sort_order=ParamSeq.DECREASING, number=None): page_count = 1 torrents = [] - while number is None or len(torrents) < number: + while number is None or number == -1 or len(torrents) < number: url = URLs.DOWNLOAD_PATTERN.value.format(page=page_count, t_type=type.value, sort=sort_by.value, @@ -81,7 +81,7 @@ async def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamW except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] - if len(new_torrents) == 0: + if number is None or len(new_torrents) == 0: return torrents torrents.extend(new_torrents) page_count += 1 diff --git a/ncoreparser/parser.py b/ncoreparser/parser.py index 3b2d27d..7be3d37 100644 --- a/ncoreparser/parser.py +++ b/ncoreparser/parser.py @@ -9,13 +9,16 @@ class TorrentsPageParser: def __init__(self): self.type_pattern = re.compile(r'' r'.*') - self.id_name_pattern = re.compile(r'') + self.id_name_poster_pattern = re.compile( + r'.*?(?:onmouseover="mutat\(\'(https:\/\/.*?)\',.*?)', + re.DOTALL) + self.id_name_patter = re.compile(r'') self.date_pattern = re.compile(r'
(.*?)
(.*?)
') self.size_pattern = re.compile(r'
(.*?)
') self.not_found_pattern = re.compile(r'
Nincs találat!
') self.seeders_pattern = re.compile(r'
') self.leechers_pattern = re.compile(r'') - self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?)(?=\')') + @staticmethod def get_key(data): @@ -26,23 +29,34 @@ def get_key(data): raise NcoreParserError(f"Error while read user " f"key with pattern: {key_pattern}") + + def id_exists(self, data, search_id): + for i, id in enumerate(data): + if search_id in data[i]: + return True + + return False + + def get_items(self, data): types = self.type_pattern.findall(data) - ids_names = self.id_name_pattern.findall(data) + ids_names_posters = self.id_name_poster_pattern.findall(data) + ids_names = self.id_name_patter.findall(data) dates_times = self.date_pattern.findall(data) sizes = self.size_pattern.findall(data) seed = self.seeders_pattern.findall(data) leech = self.leechers_pattern.findall(data) - poster_image = self.poster_image_pattern.findall(data) - # There can be torrents without poster_image - if (len(poster_image) < len(leech)): - for i in range(len(poster_image), len(leech)): - poster_image.append('no cover') + # Not all torrents has poster img + if (len(ids_names) != len(ids_names_posters)): + for i, id in enumerate(ids_names): + if not self.id_exists(ids_names_posters, ids_names[i][0]): + missing_torrent_data = (ids_names[i][0], ids_names[i][1], 'no cover') + ids_names_posters.append(missing_torrent_data) - if len(types) != 0 and len(types) == len(ids_names) == \ - len(dates_times) == len(sizes) == len(seed) == len(leech) == len(poster_image): - ids, names = zip(*ids_names) + if len(types) != 0 and len(types) == len(ids_names_posters) == \ + len(dates_times) == len(sizes) == len(seed) == len(leech): + ids, names, poster_image = zip(*ids_names_posters) dates, times = zip(*dates_times) key = self.get_key(data) else: @@ -79,7 +93,11 @@ def get_item(self, data): peers = self.peers_pattern.search(data) seed = peers.group('seed') leech = peers.group('leech') - poster_image = self.poster_image_pattern + poster_image = self.poster_image_pattern.search(data) + + # There can be torrents without poster image + if not poster_image: + poster_image = 'No cover' except AttributeError as e: raise NcoreParserError(f"Error while parsing by detailed page. {e}") from e return {"title": title, "key": key, "date": date, "size": size, "type": t_type, 'seed': seed, 'leech': leech, 'poster_image': poster_image} diff --git a/tests/manual.py b/tests/manual.py index ed710c8..b9273e8 100644 --- a/tests/manual.py +++ b/tests/manual.py @@ -65,11 +65,16 @@ def pretty_print(torrent): for torrent in torrents: pretty_print(torrent) - print_category("Test number=None && pattern=''") + print_category("Test number=None") torrents = client.search(pattern="") for torrent in torrents: pretty_print(torrent) + print_category("Test number=-1") + torrents = client.search(pattern="creed", number=-1) + for torrent in torrents: + pretty_print(torrent) + client.logout() end = time.time() diff --git a/tests/manual_async.py b/tests/manual_async.py index 7132f46..f2a7017 100644 --- a/tests/manual_async.py +++ b/tests/manual_async.py @@ -66,11 +66,16 @@ async def main(): for torrent in torrents: pretty_print(torrent) - print_category("Test number=None && pattern=''") + print_category("Test number=None") torrents = await client.search(pattern="") for torrent in torrents: pretty_print(torrent) + print_category("Test number=-1") + torrents = await client.search(pattern="creed", number=-1) + for torrent in torrents: + pretty_print(torrent) + await client.logout() end = time.time() From de73cbaf4f9b591a2054bd2e0b6ca333861628de Mon Sep 17 00:00:00 2001 From: Magos Bence <62614405+lnxx-56@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:46:41 +0100 Subject: [PATCH 06/10] reformatted ncoreparser/parser.py Co-authored-by: Aron Radics --- ncoreparser/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ncoreparser/parser.py b/ncoreparser/parser.py index 7be3d37..b988eb7 100644 --- a/ncoreparser/parser.py +++ b/ncoreparser/parser.py @@ -11,7 +11,8 @@ def __init__(self): r'.*') self.id_name_poster_pattern = re.compile( r'.*?(?:onmouseover="mutat\(\'(https:\/\/.*?)\',.*?)', - re.DOTALL) + re.DOTALL + ) self.id_name_patter = re.compile(r'') self.date_pattern = re.compile(r'
(.*?)
(.*?)
') self.size_pattern = re.compile(r'
(.*?)
') From db1ad8d7519a12745b398b63ec7eeaf51fdc9c38 Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Thu, 7 Nov 2024 23:48:47 +0100 Subject: [PATCH 07/10] fixed torrent details page poster regex --- ncoreparser/parser.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ncoreparser/parser.py b/ncoreparser/parser.py index b988eb7..baa317d 100644 --- a/ncoreparser/parser.py +++ b/ncoreparser/parser.py @@ -81,7 +81,7 @@ def __init__(self): self.peers_pattern = re.compile(r'div class="dt">Seederek:.*?
.*?
Leecherek:
.*?', re.DOTALL) - self.poster_image_pattern = re.compile(r'onmouseover="mutat\(\'(?Phttps://.*?)\'') + self.poster_image_pattern = re.compile(r']*src="(https://[^\"]+)', re.DOTALL) def get_item(self, data): try: @@ -94,11 +94,9 @@ def get_item(self, data): peers = self.peers_pattern.search(data) seed = peers.group('seed') leech = peers.group('leech') - poster_image = self.poster_image_pattern.search(data) + poster_image_match = self.poster_image_pattern.search(data) + poster_image = poster_image_match.group(1) if poster_image_match else "No cover" - # There can be torrents without poster image - if not poster_image: - poster_image = 'No cover' except AttributeError as e: raise NcoreParserError(f"Error while parsing by detailed page. {e}") from e return {"title": title, "key": key, "date": date, "size": size, "type": t_type, 'seed': seed, 'leech': leech, 'poster_image': poster_image} From 19f6df2fa8257735e118b1689f3e89ec689f37dc Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Thu, 7 Nov 2024 23:50:16 +0100 Subject: [PATCH 08/10] fixed return value when number is none --- ncoreparser/client.py | 2 +- ncoreparser/client_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ncoreparser/client.py b/ncoreparser/client.py index 77fc6ce..408725b 100644 --- a/ncoreparser/client.py +++ b/ncoreparser/client.py @@ -79,9 +79,9 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] + torrents.extend(new_torrents) if number is None or len(new_torrents) == 0: return torrents - torrents.extend(new_torrents) page_count += 1 return torrents[:number] diff --git a/ncoreparser/client_async.py b/ncoreparser/client_async.py index c5d5e67..6a2a9fa 100644 --- a/ncoreparser/client_async.py +++ b/ncoreparser/client_async.py @@ -81,9 +81,9 @@ async def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamW except Exception as e: raise NcoreConnectionError(f"Error while searhing torrents. {e}") from e new_torrents = [Torrent(**params) for params in self._page_parser.get_items(request.text)] + torrents.extend(new_torrents) if number is None or len(new_torrents) == 0: return torrents - torrents.extend(new_torrents) page_count += 1 return torrents[:number] From ea65f23987f6cd5a2e7c77c66a593808591569ff Mon Sep 17 00:00:00 2001 From: Magos Bence Date: Fri, 8 Nov 2024 00:03:51 +0100 Subject: [PATCH 09/10] added poster imgs to tests --- tests/manual.py | 15 ++++++++------- tests/manual_async.py | 14 +++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/manual.py b/tests/manual.py index b9273e8..e813a53 100644 --- a/tests/manual.py +++ b/tests/manual.py @@ -2,24 +2,25 @@ import argparse from ncoreparser import Client, SearchParamType, ParamSort, ParamSeq + def print_category(msg): print("") - print("*{:175}*".format("-" * 175)) - print(f"|{msg:^175}|") - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:276}*".format("-" * 276)) + print(f"|{msg:^276}|") + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|{:^100}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) def pretty_print(torrent): - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format(torrent['title'], + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|{:^100}|".format(torrent['title'], torrent['type'], str(torrent['size']), str(torrent['id']), torrent['seed'], torrent['leech'], torrent['poster_image'])) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) parser = argparse.ArgumentParser() diff --git a/tests/manual_async.py b/tests/manual_async.py index f2a7017..65a998c 100644 --- a/tests/manual_async.py +++ b/tests/manual_async.py @@ -6,22 +6,22 @@ def print_category(msg): print("") - print("*{:175}*".format("-" * 175)) - print(f"|{msg:^175}|") - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:276}*".format("-" * 276)) + print(f"|{msg:^276}|") + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|{:^100}|".format("Title", "Type", "Size", "ID", "Seed", "Leech", "Poster")) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) def pretty_print(torrent): - print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|".format(torrent['title'], + print("|{:^100}|{:^30}|{:^10}|{:^10}|{:^10}|{:^10}|{:^100}|".format(torrent['title'], torrent['type'], str(torrent['size']), str(torrent['id']), torrent['seed'], torrent['leech'], torrent['poster_image'])) - print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 10)) + print("*{:^100}*{:^30}*{:^10}*{:^10}*{:^10}*{:^10}*{:^100}*".format("-" * 100, "-" * 30, "-" * 10, "-" * 10, "-" * 10, "-" * 10, "-" * 100)) parser = argparse.ArgumentParser() From c4328f64c5ff11dd6e46033930ec4b8f1338d1c0 Mon Sep 17 00:00:00 2001 From: Magos Bence <62614405+lnxx-56@users.noreply.github.com> Date: Thu, 6 Feb 2025 20:19:07 +0100 Subject: [PATCH 10/10] Update ncoreparser/client.py Co-authored-by: Aron Radics --- ncoreparser/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ncoreparser/client.py b/ncoreparser/client.py index 408725b..8792249 100644 --- a/ncoreparser/client.py +++ b/ncoreparser/client.py @@ -67,7 +67,7 @@ def search(self, pattern, type=SearchParamType.ALL_OWN, where=SearchParamWhere.N sort_by=ParamSort.UPLOAD, sort_order=ParamSeq.DECREASING, number=None): page_count = 1 torrents = [] - while number is None or number == -1 or len(torrents) < number: + while number is in (None, -1) or len(torrents) < number: url = URLs.DOWNLOAD_PATTERN.value.format(page=page_count, t_type=type.value, sort=sort_by.value,