mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 20:00:15 +00:00
transform progress message to list, change subscribe messages
This commit is contained in:
parent
5a2d7c07bf
commit
1691bdadf5
@ -402,7 +402,7 @@ class PlaylistSubscription:
|
|||||||
all_youtube_ids = [i["youtube_id"] for i in all_indexed]
|
all_youtube_ids = [i["youtube_id"] for i in all_indexed]
|
||||||
|
|
||||||
new_thumbs = []
|
new_thumbs = []
|
||||||
|
counter = 1
|
||||||
for playlist in new_playlists:
|
for playlist in new_playlists:
|
||||||
url_type = playlist["type"]
|
url_type = playlist["type"]
|
||||||
playlist_id = playlist["url"]
|
playlist_id = playlist["url"]
|
||||||
@ -425,9 +425,16 @@ class PlaylistSubscription:
|
|||||||
self.change_subscribe(playlist_id, subscribe_status=True)
|
self.change_subscribe(playlist_id, subscribe_status=True)
|
||||||
|
|
||||||
# notify
|
# notify
|
||||||
|
message = {
|
||||||
|
"status": "message:subplaylist",
|
||||||
|
"level": "info",
|
||||||
|
"title": "Subscribing to Playlists",
|
||||||
|
"message": f"Processing {counter} of {len(new_playlists)}",
|
||||||
|
}
|
||||||
RedisArchivist().set_message(
|
RedisArchivist().set_message(
|
||||||
"progress:subscribe", {"status": "subscribing"}
|
"message:subplaylist", message=message
|
||||||
)
|
)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
return new_thumbs
|
return new_thumbs
|
||||||
|
|
||||||
|
@ -155,6 +155,14 @@ class RedisArchivist:
|
|||||||
REDIS_HOST = os.environ.get("REDIS_HOST")
|
REDIS_HOST = os.environ.get("REDIS_HOST")
|
||||||
REDIS_PORT = os.environ.get("REDIS_PORT") or 6379
|
REDIS_PORT = os.environ.get("REDIS_PORT") or 6379
|
||||||
NAME_SPACE = "ta:"
|
NAME_SPACE = "ta:"
|
||||||
|
CHANNELS = [
|
||||||
|
"download",
|
||||||
|
"add",
|
||||||
|
"rescan",
|
||||||
|
"subchannel",
|
||||||
|
"subplaylist",
|
||||||
|
"playlistscan",
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.redis_connection = redis.Redis(
|
self.redis_connection = redis.Redis(
|
||||||
@ -200,19 +208,19 @@ class RedisArchivist:
|
|||||||
redis_lock = self.redis_connection.lock(self.NAME_SPACE + lock_key)
|
redis_lock = self.redis_connection.lock(self.NAME_SPACE + lock_key)
|
||||||
return redis_lock
|
return redis_lock
|
||||||
|
|
||||||
def get_dl_message(self, cache_dir):
|
def get_progress(self):
|
||||||
"""get latest download progress message if available"""
|
"""get a list of all progress messages"""
|
||||||
|
all_messages = []
|
||||||
|
for channel in self.CHANNELS:
|
||||||
|
key = "message:" + channel
|
||||||
reply = self.redis_connection.execute_command(
|
reply = self.redis_connection.execute_command(
|
||||||
"JSON.GET", self.NAME_SPACE + "progress:download"
|
"JSON.GET", self.NAME_SPACE + key
|
||||||
)
|
)
|
||||||
if reply:
|
if reply:
|
||||||
json_str = json.loads(reply)
|
json_str = json.loads(reply)
|
||||||
elif json_str := self.monitor_cache_dir(cache_dir):
|
all_messages.append(json_str)
|
||||||
json_str = self.monitor_cache_dir(cache_dir)
|
|
||||||
else:
|
|
||||||
json_str = {"status": False}
|
|
||||||
|
|
||||||
return json_str
|
return all_messages
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def monitor_cache_dir(cache_dir):
|
def monitor_cache_dir(cache_dir):
|
||||||
|
@ -223,6 +223,7 @@ def re_sync_thumbs():
|
|||||||
def subscribe_to(url_str):
|
def subscribe_to(url_str):
|
||||||
"""take a list of urls to subscribe to"""
|
"""take a list of urls to subscribe to"""
|
||||||
to_subscribe_list = UrlListParser(url_str).process_list()
|
to_subscribe_list = UrlListParser(url_str).process_list()
|
||||||
|
counter = 1
|
||||||
for item in to_subscribe_list:
|
for item in to_subscribe_list:
|
||||||
to_sub_id = item["url"]
|
to_sub_id = item["url"]
|
||||||
if item["type"] == "playlist":
|
if item["type"] == "playlist":
|
||||||
@ -242,10 +243,15 @@ def subscribe_to(url_str):
|
|||||||
ChannelSubscription().change_subscribe(
|
ChannelSubscription().change_subscribe(
|
||||||
channel_id_sub, channel_subscribed=True
|
channel_id_sub, channel_subscribed=True
|
||||||
)
|
)
|
||||||
# notify
|
# notify for channels
|
||||||
RedisArchivist().set_message(
|
message = {
|
||||||
"progress:subscribe", {"status": "subscribing"}
|
"status": "message:subchannel",
|
||||||
)
|
"level": "info",
|
||||||
|
"title": "Subscribing to Channels",
|
||||||
|
"message": f"Processing {counter} of {len(to_subscribe_list)}",
|
||||||
|
}
|
||||||
|
RedisArchivist().set_message("message:subchannel", message=message)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
|
@ -34,7 +34,7 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
path("settings/", login_required(SettingsView.as_view()), name="settings"),
|
path("settings/", login_required(SettingsView.as_view()), name="settings"),
|
||||||
path("process/", login_required(process), name="process"),
|
path("process/", login_required(process), name="process"),
|
||||||
path("downloads/progress/", login_required(progress), name="progress"),
|
path("progress/", login_required(progress), name="progress"),
|
||||||
path("channel/", login_required(ChannelView.as_view()), name="channel"),
|
path("channel/", login_required(ChannelView.as_view()), name="channel"),
|
||||||
path(
|
path(
|
||||||
"channel/<slug:channel_id_detail>/",
|
"channel/<slug:channel_id_detail>/",
|
||||||
|
@ -521,9 +521,13 @@ class ChannelView(View):
|
|||||||
"""handle http post requests"""
|
"""handle http post requests"""
|
||||||
subscribe_form = SubscribeToChannelForm(data=request.POST)
|
subscribe_form = SubscribeToChannelForm(data=request.POST)
|
||||||
if subscribe_form.is_valid():
|
if subscribe_form.is_valid():
|
||||||
RedisArchivist().set_message(
|
message = {
|
||||||
"progress:subscribe", {"status": "subscribing"}
|
"status": "message:subchannel",
|
||||||
)
|
"level": "info",
|
||||||
|
"title": "Subscribing to Channels",
|
||||||
|
"message": "Parsing form data",
|
||||||
|
}
|
||||||
|
RedisArchivist().set_message("message:subchannel", message=message)
|
||||||
url_str = request.POST.get("subscribe")
|
url_str = request.POST.get("subscribe")
|
||||||
print(url_str)
|
print(url_str)
|
||||||
subscribe_to.delay(url_str)
|
subscribe_to.delay(url_str)
|
||||||
@ -800,6 +804,15 @@ class PlaylistView(View):
|
|||||||
if subscribe_form.is_valid():
|
if subscribe_form.is_valid():
|
||||||
url_str = request.POST.get("subscribe")
|
url_str = request.POST.get("subscribe")
|
||||||
print(url_str)
|
print(url_str)
|
||||||
|
message = {
|
||||||
|
"status": "message:subplaylist",
|
||||||
|
"level": "info",
|
||||||
|
"title": "Subscribing to Playlists",
|
||||||
|
"message": "Parsing form data",
|
||||||
|
}
|
||||||
|
RedisArchivist().set_message(
|
||||||
|
"message:subplaylist", message=message
|
||||||
|
)
|
||||||
subscribe_to.delay(url_str)
|
subscribe_to.delay(url_str)
|
||||||
|
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@ -929,10 +942,11 @@ class SettingsView(View):
|
|||||||
|
|
||||||
def progress(request):
|
def progress(request):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
"""endpoint for download progress ajax calls"""
|
"""resolves to /progress/
|
||||||
config = AppConfig().config
|
return list of messages for frontend
|
||||||
cache_dir = config["application"]["cache_dir"]
|
"""
|
||||||
json_data = RedisArchivist().get_dl_message(cache_dir)
|
all_messages = RedisArchivist().get_progress()
|
||||||
|
json_data = {"messages": all_messages}
|
||||||
return JsonResponse(json_data)
|
return JsonResponse(json_data)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user