Обновить test.py
This commit is contained in:
parent
3ba23834f6
commit
5401209c72
16
test.py
16
test.py
@ -1,6 +1,5 @@
|
||||
import subprocess
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
import concurrent.futures
|
||||
|
||||
@ -12,27 +11,26 @@ paths = "~/Downloads/staging"
|
||||
paths_temp = "temp:~/Downloads/temp"
|
||||
cache_dir = "~/Downloads/cache"
|
||||
ffmpeg_location = "~/"
|
||||
num_retries = 10
|
||||
fragment_retries = 10
|
||||
concur_fragments = 1
|
||||
num_threads = 16
|
||||
|
||||
url_file = "video_urls.txt"
|
||||
log_file = "download_log.txt"
|
||||
metadata_file = "metadata.json"
|
||||
successful_downloads_file = "successful_downloads.txt"
|
||||
failed_downloads_file = "failed_downloads.txt"
|
||||
|
||||
|
||||
def load_downloaded_urls(file):
|
||||
if os.path.exists(file):
|
||||
with open(file, "r") as f:
|
||||
return set(line.strip() for line in f if line.strip())
|
||||
return set()
|
||||
|
||||
|
||||
def save_downloaded_url(file, url):
|
||||
with open(file, "a") as f:
|
||||
f.write(f"{url}\n")
|
||||
|
||||
|
||||
def download_video(url):
|
||||
if url in successful_downloads:
|
||||
print(f"Video {url} already downloaded. Skipping.")
|
||||
@ -58,18 +56,22 @@ def download_video(url):
|
||||
url
|
||||
]
|
||||
print(f"Start: {' '.join(command)}")
|
||||
subprocess.run(command, check=True)
|
||||
subprocess.run(command, check=True, capture_output=True, text=True)
|
||||
end_time = datetime.now()
|
||||
log_download(url, start_time, end_time)
|
||||
save_downloaded_url(successful_downloads_file, url)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"ERROR VIDEO {url}: {e}")
|
||||
error_message = e.stderr if e.stderr else str(e)
|
||||
print(f"ERROR VIDEO {url}: {error_message}")
|
||||
if "This video has been removed" in error_message or "Video unavailable" in error_message:
|
||||
save_downloaded_url(failed_downloads_file, url)
|
||||
|
||||
|
||||
def log_download(url, start_time, end_time):
|
||||
with open(log_file, "a") as log:
|
||||
log.write(f"{url} Download.\nStart: {start_time}\nEnd: {end_time}\n\n")
|
||||
|
||||
|
||||
if not os.path.exists(url_file):
|
||||
print(f"File {url_file} Empty.")
|
||||
exit(1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user