[API] add download now endpoint, fix vid_type
This commit is contained in:
parent
7941b0412b
commit
46229db64c
|
@ -221,6 +221,13 @@ Add to queue previously ignored video:
|
|||
}
|
||||
```
|
||||
|
||||
Download existing video now:
|
||||
```json
|
||||
{
|
||||
"status": "priority"
|
||||
}
|
||||
```
|
||||
|
||||
DELETE /api/download/\<video_id>/
|
||||
Forget or delete from download queue
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from home.src.index.video import SponsorBlock, YoutubeVideo
|
|||
from home.src.ta.config import AppConfig
|
||||
from home.src.ta.helper import UrlListParser
|
||||
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
||||
from home.tasks import check_reindex, extrac_dl, subscribe_to
|
||||
from home.tasks import check_reindex, download_single, extrac_dl, subscribe_to
|
||||
from rest_framework.authentication import (
|
||||
SessionAuthentication,
|
||||
TokenAuthentication,
|
||||
|
@ -395,7 +395,7 @@ class DownloadApiView(ApiBaseView):
|
|||
"""
|
||||
|
||||
search_base = "ta_download/_doc/"
|
||||
valid_status = ["pending", "ignore"]
|
||||
valid_status = ["pending", "ignore", "priority"]
|
||||
|
||||
def get(self, request, video_id):
|
||||
# pylint: disable=unused-argument
|
||||
|
@ -411,9 +411,17 @@ class DownloadApiView(ApiBaseView):
|
|||
print(message)
|
||||
return Response({"message": message}, status=400)
|
||||
|
||||
pending_video, status_code = PendingInteract(video_id).get_item()
|
||||
if status_code == 404:
|
||||
message = f"{video_id}: item not found {status_code}"
|
||||
return Response({"message": message}, status=404)
|
||||
|
||||
print(f"{video_id}: change status to {item_status}")
|
||||
PendingInteract(video_id=video_id, status=item_status).update_status()
|
||||
RedisQueue(queue_name="dl_queue").clear_item(video_id)
|
||||
if item_status == "priority":
|
||||
download_single.delay(pending_video)
|
||||
else:
|
||||
PendingInteract(video_id, item_status).update_status()
|
||||
RedisQueue(queue_name="dl_queue").clear_item(video_id)
|
||||
|
||||
return Response(request.data)
|
||||
|
||||
|
|
|
@ -117,6 +117,12 @@ class PendingInteract:
|
|||
path = f"ta_download/_update/{self.video_id}"
|
||||
_, _ = ElasticWrap(path).post(data=data)
|
||||
|
||||
def get_item(self):
|
||||
"""return pending item dict"""
|
||||
path = f"ta_download/_doc/{self.video_id}"
|
||||
response, status_code = ElasticWrap(path).get()
|
||||
return response["_source"], status_code
|
||||
|
||||
|
||||
class PendingList(PendingIndex):
|
||||
"""manage the pending videos list"""
|
||||
|
|
|
@ -13,7 +13,6 @@ from home.src.ta.helper import UrlListParser
|
|||
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
||||
from home.tasks import (
|
||||
download_pending,
|
||||
download_single,
|
||||
index_channel_playlists,
|
||||
kill_dl,
|
||||
re_sync_thumbs,
|
||||
|
@ -56,7 +55,6 @@ class PostData:
|
|||
"sort_order": self._sort_order,
|
||||
"hide_watched": self._hide_watched,
|
||||
"show_subed_only": self._show_subed_only,
|
||||
"dlnow": self._dlnow,
|
||||
"show_ignored_only": self._show_ignored_only,
|
||||
"manual-import": self._manual_import,
|
||||
"re-embed": self._re_embed,
|
||||
|
@ -178,16 +176,6 @@ class PostData:
|
|||
RedisArchivist().set_message(key, message)
|
||||
return {"success": True}
|
||||
|
||||
def _dlnow(self):
|
||||
"""start downloading single vid now"""
|
||||
youtube_id = self.exec_val
|
||||
print(f"{youtube_id}: downloading now")
|
||||
running = download_single.delay(youtube_id=youtube_id)
|
||||
task_id = running.id
|
||||
print("set task id: " + task_id)
|
||||
RedisArchivist().set_message("dl_queue_id", task_id)
|
||||
return {"success": True}
|
||||
|
||||
def _show_ignored_only(self):
|
||||
"""switch view on /downloads/ to show ignored only"""
|
||||
show_value = self.exec_val
|
||||
|
|
|
@ -6,6 +6,7 @@ Functionality:
|
|||
because tasks are initiated at application start
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
from celery import Celery, shared_task
|
||||
|
@ -107,11 +108,15 @@ def download_pending():
|
|||
|
||||
|
||||
@shared_task
|
||||
def download_single(youtube_id):
|
||||
def download_single(pending_video):
|
||||
"""start download single video now"""
|
||||
queue = RedisQueue(queue_name="dl_queue")
|
||||
queue.add_priority(youtube_id)
|
||||
print("Added to queue with priority: " + youtube_id)
|
||||
to_add = {
|
||||
"youtube_id": pending_video["youtube_id"],
|
||||
"vid_type": pending_video["vid_type"],
|
||||
}
|
||||
queue.add_priority(json.dumps(to_add))
|
||||
print(f"Added to queue with priority: {to_add}")
|
||||
# start queue if needed
|
||||
have_lock = False
|
||||
my_lock = RedisArchivist().get_lock("downloading")
|
||||
|
|
|
@ -193,8 +193,8 @@ function toIgnore(button) {
|
|||
|
||||
function downloadNow(button) {
|
||||
let youtube_id = button.getAttribute('data-id');
|
||||
let payload = JSON.stringify({ dlnow: youtube_id });
|
||||
sendPost(payload);
|
||||
let apiEndpoint = '/api/download/' + youtube_id + '/';
|
||||
apiRequest(apiEndpoint, 'POST', { status: 'priority' });
|
||||
document.getElementById(youtube_id).remove();
|
||||
setTimeout(function () {
|
||||
checkMessages();
|
||||
|
|
Loading…
Reference in New Issue