diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index 1cb4cf9a..31ac2741 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -61,6 +61,7 @@ The list views return a paginate object with the following keys: - prev_pages: *array of ints* of previous pages, if available - current_page: *int* current page from query - max_hits: *bool* if max of 10k results is reached +- params: *str* additional url encoded query parameters - last_page: *int* of last page link - next_pages: *array of ints* of next pages - total_hits: *int* total results @@ -169,6 +170,7 @@ GET /api/download/ Parameter: - filter: pending, ignore +- channel: channel-id ### Add list of videos to download queue POST /api/download/ diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 94e6af6d..70d2485e 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -53,9 +53,7 @@ class ApiBaseView(APIView): def initiate_pagination(self, request): """set initial pagination values""" - user_id = request.user.id - page_get = int(request.GET.get("page", 0)) - self.pagination_handler = Pagination(page_get, user_id) + self.pagination_handler = Pagination(request) self.data.update( { "size": self.pagination_handler.pagination["page_size"], @@ -368,13 +366,23 @@ class DownloadApiListView(ApiBaseView): """get request""" query_filter = request.GET.get("filter", False) self.data.update({"sort": [{"timestamp": {"order": "asc"}}]}) + + must_list = [] if query_filter: if query_filter not in self.valid_filter: message = f"invalid url query filder: {query_filter}" print(message) return Response({"message": message}, status=400) - self.data["query"] = {"term": {"status": {"value": query_filter}}} + must_list.append({"term": {"status": {"value": query_filter}}}) + + filter_channel = request.GET.get("channel", False) + if filter_channel: + must_list.append( + {"term": {"channel_id": {"value": filter_channel}}} + ) + + self.data["query"] = {"bool": {"must": must_list}} self.get_document_list(request) return Response(self.response) diff --git a/tubearchivist/home/src/download/queue.py b/tubearchivist/home/src/download/queue.py index f1f4ac2f..13bd49be 100644 --- a/tubearchivist/home/src/download/queue.py +++ b/tubearchivist/home/src/download/queue.py @@ -246,7 +246,7 @@ class PendingList(PendingIndex): print(f"{youtube_id}: skipping premium video, id not matching") return False # stop if video is streaming live now - if vid["is_live"]: + if vid["live_status"] in ["is_upcoming", "is_live"]: return False return self._parse_youtube_details(vid) diff --git a/tubearchivist/home/src/download/subscriptions.py b/tubearchivist/home/src/download/subscriptions.py index 7f8a1676..95ff358a 100644 --- a/tubearchivist/home/src/download/subscriptions.py +++ b/tubearchivist/home/src/download/subscriptions.py @@ -63,6 +63,7 @@ class ChannelSubscription: for idx, channel in enumerate(all_channels): channel_id = channel["channel_id"] + print(f"{channel_id}: find missing videos.") last_videos = self.get_last_youtube_videos(channel_id) if last_videos: diff --git a/tubearchivist/home/src/index/generic.py b/tubearchivist/home/src/index/generic.py index 15e12648..099c5d45 100644 --- a/tubearchivist/home/src/index/generic.py +++ b/tubearchivist/home/src/index/generic.py @@ -73,16 +73,25 @@ class Pagination: figure out the pagination based on page size and total_hits """ - def __init__(self, page_get, user_id, search_get=False): - self.user_id = user_id + def __init__(self, request): + self.request = request + self.page_get = False + self.params = False + self.get_params() self.page_size = self.get_page_size() - self.page_get = page_get - self.search_get = search_get self.pagination = self.first_guess() + def get_params(self): + """process url query parameters""" + query_dict = self.request.GET.copy() + self.page_get = int(query_dict.get("page", 0)) + + _ = query_dict.pop("page", False) + self.params = query_dict.urlencode() + def get_page_size(self): """get default or user modified page_size""" - key = f"{self.user_id}:page_size" + key = f"{self.request.user.id}:page_size" page_size = RedisArchivist().get_message(key)["status"] if not page_size: config = AppConfig().config @@ -108,9 +117,9 @@ class Pagination: "prev_pages": prev_pages, "current_page": page_get, "max_hits": False, + "params": self.params, } - if self.search_get: - pagination.update({"search_get": self.search_get}) + return pagination def validate(self, total_hits): diff --git a/tubearchivist/home/templates/home/base.html b/tubearchivist/home/templates/home/base.html index 83b41f93..5e539956 100644 --- a/tubearchivist/home/templates/home/base.html +++ b/tubearchivist/home/templates/home/base.html @@ -79,16 +79,16 @@