diff --git a/demos/_delete_videos_older_than_input_date.py b/demos/_delete_videos_older_than_input_date.py new file mode 100644 index 0000000..b539875 --- /dev/null +++ b/demos/_delete_videos_older_than_input_date.py @@ -0,0 +1,51 @@ +#This demo gives the user capability to enter a date and all the videos older than this date will be deleted. +import os, sys +import datetime + +dir_path = os.path.dirname(os.path.realpath(__file__)) +parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir)) +sys.path.insert(0, parent_dir_path) + +sys.path.append("..") + +from Ziggeo import Ziggeo + +if(len(sys.argv) < 3): + print("Error\n") + print("Usage: $>python _delete_videos_older_than_input_date.py YOUR_APP_TOKEN YOUR_PRIVATE_KEY") + sys.exit() + +app_token = sys.argv[1] +private_key = sys.argv[2] + +ziggeo = Ziggeo(app_token, private_key) + +def InputuserDate(): +#Will prompt the user to enter Target Date and validate it. Call Index Videos at the end. + + try: + global TargetDate + TargetDate = datetime.datetime.strptime(input("Enter Target Date in dd/mm/yyyy format, for example 06/12/2021: "),"%d/%m/%Y").date() + except ValueError: + print("Please enter a valid date") + sys.exit() + CurrentDate = datetime.date.today() + + Difference = CurrentDate - TargetDate + + if(Difference.days < 0): + print("You Cannot enter a date greater than today's date") + sys.exit() + indexVideos(0) + +def indexVideos(skip = 0): + video_list = ziggeo.videos().index({"limit":100,"skip":skip}) + for video in video_list: + creationDate = datetime.date.fromtimestamp(video["created"]) + if creationDate < TargetDate: + print(" The video " + video["token"] + " was created on " + str(creationDate) + ",marking for deletion") + ziggeo.videos().delete(video["token"]) + if(len(video_list) > 0): + indexVideos(skip+100) + pass +InputuserDate() \ No newline at end of file diff --git a/demos/_videos_delete_master_script.py b/demos/_videos_delete_master_script.py new file mode 100644 index 0000000..02645e6 --- /dev/null +++ b/demos/_videos_delete_master_script.py @@ -0,0 +1,62 @@ +import os +import sys +import subprocess +import json +import time + +# Ziggeo setup +dir_path = os.path.dirname(os.path.realpath(__file__)) +parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir)) +sys.path.insert(0, parent_dir_path) + +from Ziggeo import Ziggeo + +if len(sys.argv) < 3: + print("Error\n") + print("Usage: python _videos_delete_master_script.py YOUR_APP_TOKEN YOUR_PRIVATE_KEY\n") + sys.exit() + +app_token = sys.argv[1] +private_key = sys.argv[2] + +ziggeo = Ziggeo(app_token, private_key) + +processes = [] # To track running child processes + +def indexVideos(skip=0): + """Fetch videos in batches and spawn parallel deletion processes.""" + video_list = ziggeo.videos().index({"limit": 100, "skip": skip }) + chunk_size = 10 + + if not video_list: + return # No more videos + + print(f"Fetched {len(video_list)} videos at skip={skip}") + + # Process chunks in parallel + for i in range(0, len(video_list), chunk_size): + chunk = [video["token"] for video in video_list[i:i + chunk_size]] + if chunk: + cmd = [ + "python", + "videos_delete_child_script.py", + app_token, + private_key, + json.dumps(chunk) # Pass as JSON string + ] + print(f"Spawning deletion process for {len(chunk)} videos: {chunk}") + proc = subprocess.Popen(cmd) + processes.append(proc) + + # Immediately move to the next set of videos + time.sleep(10) + indexVideos(skip + 100) + +# Start fetching and deleting +indexVideos(0) + +# Wait for all child processes to complete before exiting +print("Waiting for all deletion processes to finish...") +for p in processes: + p.wait() +print("All deletions completed.") diff --git a/demos/videos_delete_child_script.py b/demos/videos_delete_child_script.py new file mode 100644 index 0000000..58f6fde --- /dev/null +++ b/demos/videos_delete_child_script.py @@ -0,0 +1,28 @@ +import os, sys +import json +import time + + +dir_path = os.path.dirname(os.path.realpath(__file__)) +parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir)) +sys.path.insert(0, parent_dir_path) + +from Ziggeo import Ziggeo + +if(len(sys.argv) < 4): + print("Error\n") + print("Usage: $>python videos_delete.py YOUR_APP_TOKEN YOUR_PRIVATE_KEY VIDEO_TOKEN\n") + sys.exit() + +app_token = sys.argv[1] +private_key = sys.argv[2] +video_list = json.loads(sys.argv[3]) + +print("Deleting tokens: " + str(video_list)) + +ziggeo = Ziggeo(app_token, private_key) + +for video in video_list: + print("Deleting Video: " + str(video)) + ziggeo.videos().delete(video) + time.sleep(100) \ No newline at end of file