rearange files and updateing files
This commit is contained in:
1 parent
20acb4bc9f
commit
2de2c461e2
28 files changed
+285
-188
No files matched your search
Executable
+103
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python3
|
||||
import csv
|
||||
import subprocess
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import package.utils as utils
|
||||
from package.config import DB as DB
|
||||
|
||||
def write_csv(data, file_name):
|
||||
# Open file with newline='' to prevent extra blank rows across platforms
|
||||
with open(file_name, "w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.writer(file)
|
||||
|
||||
# Write all rows at once
|
||||
writer.writerows(data)
|
||||
|
||||
def download():
|
||||
"""Find all undownloaded videos and clips, and download them safely."""
|
||||
undownloaded = DB.get_undownloaded()
|
||||
|
||||
print("Starting downloads...")
|
||||
for row in undownloaded:
|
||||
# Unpack variables clearly
|
||||
(
|
||||
id,
|
||||
title,
|
||||
created_at,
|
||||
view_count,
|
||||
duration,
|
||||
url,
|
||||
thumbnail_url,
|
||||
game_id,
|
||||
game_name,
|
||||
stream_id,
|
||||
creator_name,
|
||||
clip_is,
|
||||
downloaded,
|
||||
uploaded_yt,
|
||||
uploaded_yt_chats,
|
||||
uploaded_yt_shorts,
|
||||
) = row
|
||||
|
||||
# 1. Define your data's timestamp (Example: April 10, 2026, at 10:00 AM)
|
||||
#datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ")
|
||||
data_timestamp = datetime.fromisoformat(created_at)
|
||||
|
||||
# 2. Get the exact current date and time
|
||||
current_time = datetime.now(timezone.utc)
|
||||
|
||||
# 3. Calculate the difference between the two times
|
||||
time_difference = current_time - data_timestamp
|
||||
|
||||
# 4. Check if the difference is greater than 24 hours
|
||||
if time_difference > timedelta(hours=24):
|
||||
print("The data is more than 24 hours old.")
|
||||
else:
|
||||
#lets wait 24 hours befor downloading
|
||||
print("The data is less than 24 hours old.")
|
||||
continue
|
||||
|
||||
data = [list(row)]
|
||||
print(
|
||||
f"ID: {id} | Date: {created_at} | Game: {game_name} | Title: {title}"
|
||||
)
|
||||
|
||||
# 1. Define paths and isolate base directory
|
||||
if clip_is:
|
||||
target_dir = f"download/clips/{id}"
|
||||
cmd = f"TwitchDownloaderCLI clipdownload --id {id} -o {target_dir}/{id}.mp4 --collision Overwrite --temp-path download/temp"
|
||||
else:
|
||||
target_dir = f"download/videos/{id}"
|
||||
# FIXED: Removed the duplicated command string combined with '&&'
|
||||
cmd = f"TwitchDownloaderCLI videodownload --id {id} -o {target_dir}/{id}.mp4 --collision Overwrite --threads 2 --temp-path download/temp"
|
||||
|
||||
csv_file = f"{target_dir}/{id}.csv"
|
||||
|
||||
# 3. FIXED: Use the live streaming function to prevent Out-Of-Memory crashes
|
||||
output = utils.run_command(cmd, look_for=["[STATUS]"])
|
||||
output2 = utils.run_command(f"TwitchDownloaderCLI chatdownload --id {id} -o {target_dir}/{id}_chat.json -E --collision Overwrite --temp-path download/temp", look_for=["[STATUS]"])
|
||||
|
||||
if output:
|
||||
# Only write CSV and update database if download actually completed
|
||||
write_csv(data, csv_file)
|
||||
print(f"✅ Success: TwitchDownloaderCLI video. {target_dir}")
|
||||
DB.mark_as_downloaded(id)
|
||||
else:
|
||||
print(f"ID: {id} | Download Process failed.")
|
||||
#print(f"❌ Reason/Error: {output.get('error', 'Unknown Error')}")
|
||||
#if output.get("stderr"):
|
||||
# print(f"Details: {output['stderr']}")
|
||||
|
||||
# Clear temporary chunk clutter immediately if a VOD crashes out
|
||||
if not clip_is:
|
||||
print("Flushing temporary crash chunks...")
|
||||
subprocess.run("rm -rf download/temp/*", shell=True)
|
||||
|
||||
print("Finished Downloading Pipeline.")
|
||||
|
||||
def main():
|
||||
download()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user