git ssb

0+

thomas-dev-patchwork / MediaProcessor



Tree: b38fff921639daeb0858f973d29e73f904c3fadf

Files: b38fff921639daeb0858f973d29e73f904c3fadf / addSingles.py

3309 bytesRaw
1
2import MediaProcessor as mpClass
3import sqlite3
4import json
5import sys
6
7#
8# addSingles.py -- Commad line program to process a list of media URLs and add
9# them to IPFS and record their hashes & metadata in a SQLite
10# database.
11#
12
13# Configuration template file for MediaGrabber, usually read from a JSON file.
14CFG = {
15 "DLbase": "/home/ipfs/ytDL/", # Base folder for all files:
16 "DLeLog": "error.log", # Log file appended to DLBase
17 "DLarch": "youtube-dl.history", # yt_dlp download history id list
18 "DLmeta": "metadataFields.json", # metadata schema for SQLite database
19 "DLOpts": { # Download options for all grupes
20 "retries": 5,
21 "format": "best",
22 "continuedl": True,
23 "ignoreerrors": True,
24 "merge-output-format": "mp4" # Ignored for non-video media
25 },
26
27 "Grupes": { # List of grupes (channels, publishers)
28 "singles": { # Aribtrary name of grupe/channel/publisher/topic
29 "Quota": 0, # number<space>bytes or number only (file count)
30 "Active": True, # Process this grupe or ignore flag
31 "Duration": 0, # Minimum duration or 0 for any length
32 "Start": None, # Date published string "yyyymmdd"
33 "End": None, # Range end for date published, "yyyymmdd"
34 "Stop": 300, # Maximum number of files per playlist URL
35 "urls": [] # List of URLs or URLs to playists
36 }
37 },
38 "MetaColumns": [] # Will be read from DLmeta JSON file
39}
40
41# MAIN - Let us begin...
42mp = mpClass.MediaProcessor()
43try:
44 with open(CFG['DLbase'] + CFG['DLmeta'], 'r') as jsn:
45 CFG['MetaColumns'] = json.load(jsn)['MetaColumns']
46except Exception as e:
47 if len(CFG['MetaColumns']) == 0:
48 print(f"Couldn't load the metadata file - Bye!\n\n{e}")
49 exit(1)
50mp.Config = CFG
51
52#
53# Get 3 inputs from user: database file, grupe name, list of URLs
54#
55db = input("SQLite database file (default is 'ipfsDallas.sqlite'): ")
56if db == "": db = "ipfsIndex.sqlite"
57try:
58 conn = mp.openSQLiteDB(db) # Open a SQLite database or create one
59 conn.row_factory = sqlite3.Row # Results as python dictionary
60except Exception as e:
61 if conn == None:
62 print(f"An error occurred opening {db}\n\n{e}")
63 exit(1)
64
65grupe = input("Grupe name (default is 'singles'): ")
66if grupe != "": # Create a new grupe and pull values from default
67 CFG['Grupes'][grupe] = CFG['Grupes'].pop('singles')
68else: grupe = "singles"
69
70urls = input("Comma separated list of URLs: ")
71if urls:
72 quoted = []
73 for url in urls.split(','):
74 url = url.strip()
75 if not url.lower().startswith("http"):
76 print(f"Each URL must start with http - Bye!")
77 exit(-1)
78 else:
79 quoted.append(f"{url}")
80else: print(f"You must provide at least 1 URL - Bye!")
81
82CFG['Grupes'][grupe]['urls'] = quoted
83
84mp.Config = CFG # Set class' download parameters
85
86yn = input(f"Using DB={db} grupe={grupe} for {len(quoted)} url(s). Proceed? (default is y) ")
87if yn == "" or yn == "y" or yn == "Y":
88 mp.runScript(db, conn)
89 m, u = mp.displaySummary(conn)
90 print(f"mail={m}\n\nurls={u}\n")
91

Built with git-ssb-web