Skip to content

Commit

Permalink
Make user search more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
kannibalox committed Feb 15, 2024
1 parent 6211d09 commit d527a5b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
## [Unreleased]

### Added
- `ptp search`: Allow search users' snatched/leeching/uploaded/seeding
torrents, e.g. `ptp search type=snatched`

## [0.10.2] - 2023-10-30
### Added
- `ptp inbox`: Add `--raw` flag to get HTML for conversations ([#24](https://github.com/kannibalox/PTPAPI/pull/24), [@bonswouar](https://github.com/bonswouar))
Expand Down
4 changes: 2 additions & 2 deletions src/ptpapi/scripts/ptp.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ def search_page(api, args, target, movies, torrents, terms):
if not movies and not torrents:
logger.debug('Attempting to search target "%s" with terms %s', target, terms)
if target == "torrents":
if terms.get("type") == "snatched":
if terms.get("type") in ["snatched", "uploaded", "seeding", "leeching"]:
if "userid" in terms:
user = ptpapi.User(terms["userid"])
else:
user = api.current_user()
movies = user.snatched(terms)
movies = user.search(terms.get("type"), terms)
else:
movies = api.search(terms)
# Check to see if we should scrape the cover view data to save calls
Expand Down
4 changes: 2 additions & 2 deletions src/ptpapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def __repr__(self):
def __str__(self):
return "<ptpapi.User ID %s>" % self.ID

def snatched(self, filters=None):
def search(self, search_type, filters=None):
if filters is None:
filters = {}
filters["type"] = "snatched"
filters["type"] = search_type
filters["userid"] = str(self.ID)
req = session.base_get("torrents.php", params=filters)
return [Movie(data=m) for m in snarf_cover_view_data(req.content)]
Expand Down

0 comments on commit d527a5b

Please sign in to comment.