#!/usr/bin/env python3 import MediaProcessor as mpClass import sqlite3 import json import sys # # addSingles.py -- Commad line program to process a list of media URLs and add # them to IPFS and record their hashes & metadata in a SQLite # database. # # Configuration template file for MediaGrabber, usually read from a JSON file. CFG = { "DLbase": "/home/ipfs/ytDL/", # Base folder for all files: "DLeLog": "error.log", # Log file appended to DLBase "DLarch": "youtube-dl.history", # yt_dlp download history id list "DLmeta": "metadataFields.json", # metadata schema for SQLite database "DLOpts": { # Download options for all grupes "retries": 5, "format": "best", "continuedl": True, "ignoreerrors": True, "merge-output-format": "mp4" # Ignored for non-video media }, "Grupes": { # List of grupes (channels, publishers) "singles": { # Aribtrary name of grupe/channel/publisher/topic "Quota": 0, # numberbytes or number only (file count) "Active": True, # Process this grupe or ignore flag "Duration": 0, # Minimum duration or 0 for any length "Start": None, # Date published string "yyyymmdd" "End": None, # Range end for date published, "yyyymmdd" "Stop": 300, # Maximum number of files per playlist URL "urls": [] # List of URLs or URLs to playists } }, "MetaColumns": [] # Will be read from DLmeta JSON file } # MAIN - Let us begin... mp = mpClass.MediaProcessor() try: with open(CFG['DLbase'] + CFG['DLmeta'], 'r') as jsn: CFG['MetaColumns'] = json.load(jsn)['MetaColumns'] except Exception as e: if len(CFG['MetaColumns']) == 0: print(f"Couldn't load the metadata file - Bye!\n\n{e}") exit(1) mp.Config = CFG # # Get 3 inputs from user: database file, grupe name, list of URLs # db = input("SQLite database file (default is 'ipfsDallas.sqlite'): ") if db == "": db = "ipfsIndex.sqlite" try: conn = mp.openSQLiteDB(db) # Open a SQLite database or create one conn.row_factory = sqlite3.Row # Results as python dictionary except Exception as e: if conn == None: print(f"An error occurred opening {db}\n\n{e}") exit(1) grupe = input("Grupe name (default is 'singles'): ") if grupe != "": # Create a new grupe and pull values from default CFG['Grupes'][grupe] = CFG['Grupes'].pop('singles') else: grupe = "singles" urls = input("Comma separated list of URLs: ") if urls: quoted = [] for url in urls.split(','): url = url.strip() if not url.lower().startswith("http"): print(f"Each URL must start with http - Bye!") exit(-1) else: quoted.append(f"{url}") else: print(f"You must provide at least 1 URL - Bye!") CFG['Grupes'][grupe]['urls'] = quoted mp.Config = CFG # Set class' download parameters yn = input(f"Using DB={db} grupe={grupe} for {len(quoted)} url(s). Proceed? (default is y) ") if yn == "" or yn == "y" or yn == "Y": mp.runScript(db, conn) m, u = mp.displaySummary(conn) print(f"mail={m}\n\nurls={u}\n")