Add option to ignore videos when deleting

Adds a "Delete and Ignore" option when deleting a video which
automatically marks it as ignored in the download queue.
This commit is contained in:
Jonathan VanderMey 2024-03-02 16:35:02 -05:00
parent 8778546577
commit 0b3af35123
3 changed files with 33 additions and 10 deletions

View File

@ -10,7 +10,7 @@ from api.src.aggs import (
WatchProgress,
)
from api.src.search_processor import SearchProcess
from home.src.download.queue import PendingInteract
from home.src.download.queue import PendingInteract, PendingList
from home.src.download.subscriptions import (
ChannelSubscription,
PlaylistSubscription,
@ -644,15 +644,25 @@ class DownloadApiListView(ApiBaseView):
return Response({"message": message}, status=400)
pending = [i["youtube_id"] for i in to_add if i["status"] == "pending"]
url_str = " ".join(pending)
try:
youtube_ids = Parser(url_str).parse()
except ValueError:
message = f"failed to parse: {url_str}"
print(message)
return Response({"message": message}, status=400)
if pending:
url_str = " ".join(pending)
try:
youtube_ids = Parser(url_str).parse()
except ValueError:
message = f"failed to parse: {url_str}"
print(message)
return Response({"message": message}, status=400)
extrac_dl.delay(youtube_ids, auto_start=auto_start)
extrac_dl.delay(youtube_ids, auto_start=auto_start)
ignore = [
{"type": "video", "url": i["youtube_id"]}
for i in to_add
if i["status"] == "ignore"
]
if ignore:
pending = PendingList(youtube_ids=ignore)
pending.parse_url_list()
pending.add_to_pending(status="ignore")
return Response(data)

View File

@ -92,7 +92,7 @@
{% if request.user|has_group:"admin" or request.user.is_staff %}
<button onclick="deleteConfirm()" id="delete-item">Delete Video</button>
<div class="delete-confirm" id="delete-button">
<span>Are you sure? </span><button class="danger-button" onclick="deleteVideo(this)" data-id="{{ video.youtube_id }}" data-redirect = "{{ video.channel.channel_id }}">Delete</button> <button onclick="cancelDelete()">Cancel</button>
<span>Are you sure? </span><button class="danger-button" onclick="deleteVideo(this)" data-id="{{ video.youtube_id }}" data-redirect = "{{ video.channel.channel_id }}">Delete</button> <button class="danger-button" onclick="deleteAndIgnoreVideo(this)" data-id="{{ video.youtube_id }}" data-redirect = "{{ video.channel.channel_id }}">Delete and Ignore</button> <button onclick="cancelDelete()">Cancel</button>
</div>
{% endif %}
</div>

View File

@ -381,6 +381,19 @@ function deleteVideo(button) {
}, 1000);
}
function deleteAndIgnoreVideo(button) {
let to_delete = button.getAttribute('data-id');
let to_redirect = button.getAttribute('data-redirect');
let endpointDelete = '/api/video/' + to_delete + '/';
apiRequest(endpointDelete, 'DELETE');
let endpointDownload = '/api/download/';
apiRequest(endpointDownload, 'POST', { data: [{ youtube_id: to_delete, status: 'ignore' }] });
setTimeout(function () {
let redirect = '/channel/' + to_redirect;
window.location.replace(redirect);
}, 1000);
}
function deleteChannel(button) {
let to_delete = button.getAttribute('data-id');
let apiEndpoint = '/api/channel/' + to_delete + '/';