Skip to content

Commit

Permalink
Allow searching a user's snatched torrents
Browse files Browse the repository at this point in the history
  • Loading branch information
kannibalox committed Feb 15, 2024
1 parent 73ba146 commit 6211d09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ptpapi/scripts/ptp.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ 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":
movies = api.search(terms)
if terms.get("type") == "snatched":
if "userid" in terms:
user = ptpapi.User(terms["userid"])
else:
user = api.current_user()
movies = user.snatched(terms)
else:
movies = api.search(terms)
# Check to see if we should scrape the cover view data to save calls
wanted_fields = set()
if movie_template is not None:
Expand Down
8 changes: 8 additions & 0 deletions src/ptpapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def __repr__(self):
def __str__(self):
return "<ptpapi.User ID %s>" % self.ID

def snatched(self, filters=None):
if filters is None:
filters = {}
filters["type"] = "snatched"
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)]

def bookmarks(self, search_terms=None):
"""Fetch a list of movies the user has bookmarked
Expand Down

0 comments on commit 6211d09

Please sign in to comment.