49 lines
2.0 KiB
Python
Executable File
49 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import requests
|
|
import os
|
|
import time
|
|
import csv
|
|
|
|
import linux
|
|
from database import Database
|
|
|
|
CHANNEL_NAME = 'teampgp'
|
|
DB = None
|
|
|
|
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 undownload videos and download them."""
|
|
undownloaded = DB.get_undownloaded()
|
|
|
|
print(f"Download...")
|
|
for 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 in undownloaded:
|
|
data = [[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]]
|
|
print(f"ID: {id} | Date: {created_at} | Game: {game_name} | Title: {title}")
|
|
if not clip_is:
|
|
output = linux.run_command(f"TwitchDownloaderCLI videodownload --id {id} -o download/videos/{id}/{id}.mp4 --collision Overwrite")
|
|
output2 = linux.run_command(f"TwitchDownloaderCLI chatdownload --id {id} -o download/videos/{id}/{id}_chat.json -E --collision Overwrite")
|
|
write_csv(data, f"download/videos/{id}/{id}.csv")
|
|
elif clip_is:
|
|
output = linux.run_command(f"TwitchDownloaderCLI clipdownload --id {id} -o download/clips/{id}/{id}.mp4 --collision Overwrite")
|
|
write_csv(data, f"download/clips/{id}/{id}.csv")
|
|
|
|
time.sleep(1)
|
|
|
|
if output["success"] is True:
|
|
print(f"ID: {id} | Date: {created_at} | Game: {game_name} | Title: {title} | was successful")
|
|
DB.mark_as_downloaded(id)
|
|
else:
|
|
print(f"ID: {id} | Download Process failed. {output["stdout"]}. Error: {output["stderr"]}")
|
|
|
|
print(f"Finished Downloading...")
|
|
|
|
if __name__ == "__main__":
|
|
DB = Database()
|
|
download() |