mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-22 01:40:12 +00:00
fix dl error retry logic, store and return error, #477
This commit is contained in:
parent
7082718c14
commit
5e92d06f21
@ -48,11 +48,11 @@ class YtWrap:
|
|||||||
with yt_dlp.YoutubeDL(self.obs) as ydl:
|
with yt_dlp.YoutubeDL(self.obs) as ydl:
|
||||||
try:
|
try:
|
||||||
ydl.download([url])
|
ydl.download([url])
|
||||||
except yt_dlp.utils.DownloadError:
|
except yt_dlp.utils.DownloadError as err:
|
||||||
print(f"{url}: failed to download.")
|
print(f"{url}: failed to download.")
|
||||||
return False
|
return False, str(err)
|
||||||
|
|
||||||
return True
|
return True, True
|
||||||
|
|
||||||
def extract(self, url):
|
def extract(self, url):
|
||||||
"""make extract request"""
|
"""make extract request"""
|
||||||
|
@ -203,12 +203,13 @@ class VideoDownloader:
|
|||||||
def _get_next(self, auto_only):
|
def _get_next(self, auto_only):
|
||||||
"""get next item in queue"""
|
"""get next item in queue"""
|
||||||
must_list = [{"term": {"status": {"value": "pending"}}}]
|
must_list = [{"term": {"status": {"value": "pending"}}}]
|
||||||
|
must_not_list = [{"exists": {"field": "message"}}]
|
||||||
if auto_only:
|
if auto_only:
|
||||||
must_list.append({"term": {"auto_start": {"value": True}}})
|
must_list.append({"term": {"auto_start": {"value": True}}})
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"size": 1,
|
"size": 1,
|
||||||
"query": {"bool": {"must": must_list}},
|
"query": {"bool": {"must": must_list, "must_not": must_not_list}},
|
||||||
"sort": [
|
"sort": [
|
||||||
{"auto_start": {"order": "desc"}},
|
{"auto_start": {"order": "desc"}},
|
||||||
{"timestamp": {"order": "asc"}},
|
{"timestamp": {"order": "asc"}},
|
||||||
@ -344,7 +345,9 @@ class VideoDownloader:
|
|||||||
if youtube_id in file_name:
|
if youtube_id in file_name:
|
||||||
obs["outtmpl"] = os.path.join(dl_cache, file_name)
|
obs["outtmpl"] = os.path.join(dl_cache, file_name)
|
||||||
|
|
||||||
success = YtWrap(obs, self.config).download(youtube_id)
|
success, message = YtWrap(obs, self.config).download(youtube_id)
|
||||||
|
if not success:
|
||||||
|
self._handle_error(youtube_id, message)
|
||||||
|
|
||||||
if self.obs["writethumbnail"]:
|
if self.obs["writethumbnail"]:
|
||||||
# webp files don't get cleaned up automatically
|
# webp files don't get cleaned up automatically
|
||||||
@ -356,6 +359,12 @@ class VideoDownloader:
|
|||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _handle_error(youtube_id, message):
|
||||||
|
"""store error message"""
|
||||||
|
data = {"doc": {"message": message}}
|
||||||
|
_, _ = ElasticWrap(f"ta_download/_update/{youtube_id}").post(data=data)
|
||||||
|
|
||||||
def move_to_archive(self, vid_dict):
|
def move_to_archive(self, vid_dict):
|
||||||
"""move downloaded video from cache to archive"""
|
"""move downloaded video from cache to archive"""
|
||||||
videos = self.config["application"]["videos"]
|
videos = self.config["application"]["videos"]
|
||||||
|
@ -380,6 +380,9 @@
|
|||||||
},
|
},
|
||||||
"auto_start": {
|
"auto_start": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"message": {
|
||||||
|
"type": "text"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected_set": {
|
"expected_set": {
|
||||||
|
@ -97,6 +97,9 @@
|
|||||||
<a href="https://www.youtube.com/watch?v={{ video.source.youtube_id }}" target="_blank"><h3>{{ video.source.title }}</h3></a>
|
<a href="https://www.youtube.com/watch?v={{ video.source.youtube_id }}" target="_blank"><h3>{{ video.source.title }}</h3></a>
|
||||||
</div>
|
</div>
|
||||||
<p>Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}</p>
|
<p>Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}</p>
|
||||||
|
{% if video.source.message %}
|
||||||
|
<p class="danger-zone">{{ video.source.message }}</p>
|
||||||
|
{% endif %}
|
||||||
<div>
|
<div>
|
||||||
{% if show_ignored_only %}
|
{% if show_ignored_only %}
|
||||||
<button data-id="{{ video.source.youtube_id }}" onclick="forgetIgnore(this)">Forget</button>
|
<button data-id="{{ video.source.youtube_id }}" onclick="forgetIgnore(this)">Forget</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user