mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 22:39:38 +00:00
move add to queue to api call
This commit is contained in:
@@ -25,6 +25,7 @@ from home.src.index.reindex import Reindex, ReindexManual, ReindexPopulate
|
|||||||
from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder
|
from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder
|
||||||
from home.src.ta.ta_redis import RedisArchivist
|
from home.src.ta.ta_redis import RedisArchivist
|
||||||
from home.src.ta.task_manager import TaskManager
|
from home.src.ta.task_manager import TaskManager
|
||||||
|
from home.src.ta.urlparser import Parser
|
||||||
|
|
||||||
CONFIG = AppConfig().config
|
CONFIG = AppConfig().config
|
||||||
REDIS_HOST = os.environ.get("REDIS_HOST")
|
REDIS_HOST = os.environ.get("REDIS_HOST")
|
||||||
@@ -196,7 +197,12 @@ def download_pending(self, auto_only=False):
|
|||||||
def extrac_dl(self, youtube_ids, auto_start=False):
|
def extrac_dl(self, youtube_ids, auto_start=False):
|
||||||
"""parse list passed and add to pending"""
|
"""parse list passed and add to pending"""
|
||||||
TaskManager().init(self)
|
TaskManager().init(self)
|
||||||
pending_handler = PendingList(youtube_ids=youtube_ids, task=self)
|
if isinstance(youtube_ids, str):
|
||||||
|
to_add = Parser(youtube_ids).parse()
|
||||||
|
else:
|
||||||
|
to_add = youtube_ids
|
||||||
|
|
||||||
|
pending_handler = PendingList(youtube_ids=to_add, task=self)
|
||||||
pending_handler.parse_url_list()
|
pending_handler.parse_url_list()
|
||||||
pending_handler.add_to_pending(auto_start=auto_start)
|
pending_handler.add_to_pending(auto_start=auto_start)
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,10 @@
|
|||||||
<img id="animate-icon" onclick="showForm()" src="{% static 'img/icon-add.svg' %}" alt="add-icon">
|
<img id="animate-icon" onclick="showForm()" src="{% static 'img/icon-add.svg' %}" alt="add-icon">
|
||||||
<p>Add to download queue</p>
|
<p>Add to download queue</p>
|
||||||
<div class="show-form">
|
<div class="show-form">
|
||||||
<form id='hidden-form' action="/downloads/" method="post">
|
<form id='hidden-form'>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ add_form }}
|
{{ add_form }}
|
||||||
<button type="submit">Add to download queue</button>
|
<button onclick="addToQueue()">Add to download queue</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ from home.src.index.video_constants import VideoTypeEnum
|
|||||||
from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder
|
from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder
|
||||||
from home.src.ta.helper import time_parser
|
from home.src.ta.helper import time_parser
|
||||||
from home.src.ta.ta_redis import RedisArchivist
|
from home.src.ta.ta_redis import RedisArchivist
|
||||||
from home.src.ta.urlparser import Parser
|
from home.tasks import index_channel_playlists, subscribe_to
|
||||||
from home.tasks import extrac_dl, index_channel_playlists, subscribe_to
|
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
|
|
||||||
|
|
||||||
@@ -368,7 +367,7 @@ class AboutView(MinView):
|
|||||||
|
|
||||||
class DownloadView(ArchivistResultsView):
|
class DownloadView(ArchivistResultsView):
|
||||||
"""resolves to /download/
|
"""resolves to /download/
|
||||||
takes POST for downloading youtube links
|
handle the download queue
|
||||||
"""
|
"""
|
||||||
|
|
||||||
view_origin = "downloads"
|
view_origin = "downloads"
|
||||||
@@ -452,34 +451,6 @@ class DownloadView(ArchivistResultsView):
|
|||||||
|
|
||||||
return buckets_sorted
|
return buckets_sorted
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def post(request):
|
|
||||||
"""handle post requests"""
|
|
||||||
to_queue = AddToQueueForm(data=request.POST)
|
|
||||||
if to_queue.is_valid():
|
|
||||||
url_str = request.POST.get("vid_url")
|
|
||||||
print(url_str)
|
|
||||||
try:
|
|
||||||
youtube_ids = Parser(url_str).parse()
|
|
||||||
except ValueError:
|
|
||||||
# failed to process
|
|
||||||
key = "message:add"
|
|
||||||
print(f"failed to parse: {url_str}")
|
|
||||||
mess_dict = {
|
|
||||||
"status": key,
|
|
||||||
"level": "error",
|
|
||||||
"title": "Failed to extract links.",
|
|
||||||
"message": "Not a video, channel or playlist ID or URL",
|
|
||||||
}
|
|
||||||
RedisArchivist().set_message(key, mess_dict, expire=True)
|
|
||||||
return redirect("downloads")
|
|
||||||
|
|
||||||
print(youtube_ids)
|
|
||||||
extrac_dl.delay(youtube_ids)
|
|
||||||
|
|
||||||
sleep(2)
|
|
||||||
return redirect("downloads", permanent=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ChannelIdBaseView(ArchivistResultsView):
|
class ChannelIdBaseView(ArchivistResultsView):
|
||||||
"""base class for all channel-id views"""
|
"""base class for all channel-id views"""
|
||||||
|
|||||||
@@ -160,6 +160,20 @@ function dlPending() {
|
|||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addToQueue() {
|
||||||
|
let textArea = document.getElementById('id_vid_url');
|
||||||
|
if (textArea.value === '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let toPost = {data: [{youtube_id: textArea.value, status: 'pending'}]};
|
||||||
|
let apiEndpoint = '/api/download/';
|
||||||
|
apiRequest(apiEndpoint, 'POST', toPost);
|
||||||
|
textArea.value = "";
|
||||||
|
setTimeout(function () {
|
||||||
|
checkMessages();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
function toIgnore(button) {
|
function toIgnore(button) {
|
||||||
let youtube_id = button.getAttribute('data-id');
|
let youtube_id = button.getAttribute('data-id');
|
||||||
let apiEndpoint = '/api/download/' + youtube_id + '/';
|
let apiEndpoint = '/api/download/' + youtube_id + '/';
|
||||||
|
|||||||
Reference in New Issue
Block a user