git ssb

0+

thomas-dev-patchwork / MediaProcessor



Tree: b46e4ec37c3250819bcfec6a303708c4994256a0

Files: b46e4ec37c3250819bcfec6a303708c4994256a0 / addSingles.py

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

Built with git-ssb-web