use ElasticWrap to delete item from pending

This commit is contained in:
simon 2022-03-23 11:09:21 +07:00
parent 5b1c9c64de
commit 1f7d6871cf
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -11,11 +11,10 @@ import shutil
from datetime import datetime from datetime import datetime
from time import sleep from time import sleep
import requests
import yt_dlp import yt_dlp
from home.src.download.queue import PendingList from home.src.download.queue import PendingList
from home.src.download.subscriptions import PlaylistSubscription from home.src.download.subscriptions import PlaylistSubscription
from home.src.es.connect import IndexPaginate from home.src.es.connect import ElasticWrap, IndexPaginate
from home.src.index.channel import YoutubeChannel from home.src.index.channel import YoutubeChannel
from home.src.index.playlist import YoutubePlaylist from home.src.index.playlist import YoutubePlaylist
from home.src.index.video import YoutubeVideo, index_new_video from home.src.index.video import YoutubeVideo, index_new_video
@ -370,14 +369,11 @@ class VideoDownloader:
if host_uid and host_gid: if host_uid and host_gid:
os.chown(new_file_path, host_uid, host_gid) os.chown(new_file_path, host_uid, host_gid)
def _delete_from_pending(self, youtube_id): @staticmethod
def _delete_from_pending(youtube_id):
"""delete downloaded video from pending index if its there""" """delete downloaded video from pending index if its there"""
es_url = self.config["application"]["es_url"] path = f"ta_download/_doc/{youtube_id}"
es_auth = self.config["application"]["es_auth"] _, _ = ElasticWrap(path).delete()
url = f"{es_url}/ta_download/_doc/{youtube_id}"
response = requests.delete(url, auth=es_auth)
if not response.ok and not response.status_code == 404:
print(response.text)
def _add_subscribed_channels(self): def _add_subscribed_channels(self):
"""add all channels subscribed to refresh""" """add all channels subscribed to refresh"""