code before moving database code to its own file.
This commit is contained in:
+21
-8
@@ -21,7 +21,8 @@ def create_database():
|
||||
title TEXT NOT NULL,
|
||||
gamename TEXT NOT NULL,
|
||||
downloaded INTEGER NOT NULL,
|
||||
uploaded_yt INTEGER NOT NULL
|
||||
uploaded_yt INTEGER NOT NULL,
|
||||
chat_upload_yt INTEGER NOT NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
@@ -41,8 +42,8 @@ def download_vods():
|
||||
|
||||
for record_id, record_date, title, game_name, downloaded in undownload_vods:
|
||||
print(f"ID: {record_id} | Date: {record_date} | Game: {game_name} | Title: {title}")
|
||||
output = run_linux_command(f"TwitchDownloaderCLI videodownload --id {record_id} -o save/{record_id}/{record_id}.mp4")
|
||||
output2 = run_linux_command(f"TwitchDownloaderCLI chatdownload --id {record_id} -o save/{record_id}/{record_id}_chat.json -E")
|
||||
output = run_linux_command(f"TwitchDownloaderCLI videodownload --id {record_id} -o save/vod/{record_id}/{record_id}.mp4")
|
||||
output2 = run_linux_command(f"TwitchDownloaderCLI chatdownload --id {record_id} -o save/vod/{record_id}/{record_id}_chat.json -E")
|
||||
if output["success"] is True:
|
||||
print(f"ID: {record_id} | Date: {record_date} | Game: {game_name} | Title: {title} | was successful")
|
||||
mark_as_downloaded(record_id)
|
||||
@@ -77,6 +78,20 @@ def mark_as_downloaded(record_id: int):
|
||||
|
||||
CONN.commit()
|
||||
|
||||
def get_unuploaded_clips():
|
||||
"""Retrieves all clip rows remaining to be chat uploaded."""
|
||||
CURSOR.execute(
|
||||
"SELECT id, date, title, gamename, clip_by, view_count, downloaded, uploaded_yt, chat_uploaded_yt FROM vods WHERE downloaded = 1 AND chat_uploaded_yt = 0"
|
||||
)
|
||||
return CURSOR.fetchall()
|
||||
|
||||
def get_unuploaded_clips():
|
||||
"""Retrieves all clip rows remaining to be uploaded."""
|
||||
CURSOR.execute(
|
||||
"SELECT id, date, title, gamename, clip_by, view_count, downloaded, uploaded_yt FROM vods WHERE downloaded = 1 AND uploaded_yt = 0"
|
||||
)
|
||||
return CURSOR.fetchall()
|
||||
|
||||
def get_undownloaded_vods():
|
||||
"""Retrieves all rows where downloaded status is False (0)."""
|
||||
|
||||
@@ -84,9 +99,7 @@ def get_undownloaded_vods():
|
||||
CURSOR.execute(
|
||||
"SELECT id, date, title, gamename, downloaded FROM vods WHERE downloaded = 0"
|
||||
)
|
||||
records = CURSOR.fetchall()
|
||||
|
||||
return records
|
||||
return CURSOR.fetchall()
|
||||
|
||||
def insert_record(record_id: int, record_date: datetime_date, title: str, gamename: str):
|
||||
"""Inserts a record with ID, date, gamename, and title into a SQLite database."""
|
||||
@@ -94,8 +107,8 @@ def insert_record(record_id: int, record_date: datetime_date, title: str, gamena
|
||||
|
||||
# Inserts data using parameterized queries to prevent SQL injection
|
||||
CURSOR.execute(
|
||||
"INSERT OR IGNORE INTO vods (id, date, title, gamename, downloaded, uploaded_yt) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
(record_id, str(record_date), title, gamename, False, False),
|
||||
"INSERT OR IGNORE INTO vods (id, date, title, gamename, downloaded, uploaded_yt, chat_uploaded_yt) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
(record_id, str(record_date), title, gamename, False, False, False),
|
||||
)
|
||||
|
||||
# Saves changes and closes the connection
|
||||
|
||||
Reference in New Issue
Block a user