Files: b38fff921639daeb0858f973d29e73f904c3fadf / addSingles.py
3309 bytesRaw
1 | |
2 | import MediaProcessor as mpClass |
3 | import sqlite3 |
4 | import json |
5 | import 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. |
14 | CFG = { |
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... |
42 | mp = mpClass.MediaProcessor() |
43 | try: |
44 | with open(CFG['DLbase'] + CFG['DLmeta'], 'r') as jsn: |
45 | CFG['MetaColumns'] = json.load(jsn)['MetaColumns'] |
46 | except 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) |
50 | mp.Config = CFG |
51 | |
52 | # |
53 | # Get 3 inputs from user: database file, grupe name, list of URLs |
54 | # |
55 | db = input("SQLite database file (default is 'ipfsDallas.sqlite'): ") |
56 | if db == "": db = "ipfsIndex.sqlite" |
57 | try: |
58 | conn = mp.openSQLiteDB(db) # Open a SQLite database or create one |
59 | conn.row_factory = sqlite3.Row # Results as python dictionary |
60 | except Exception as e: |
61 | if conn == None: |
62 | print(f"An error occurred opening {db}\n\n{e}") |
63 | exit(1) |
64 | |
65 | grupe = input("Grupe name (default is 'singles'): ") |
66 | if grupe != "": # Create a new grupe and pull values from default |
67 | CFG['Grupes'][grupe] = CFG['Grupes'].pop('singles') |
68 | else: grupe = "singles" |
69 | |
70 | urls = input("Comma separated list of URLs: ") |
71 | if 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}") |
80 | else: print(f"You must provide at least 1 URL - Bye!") |
81 | |
82 | CFG['Grupes'][grupe]['urls'] = quoted |
83 | |
84 | mp.Config = CFG # Set class' download parameters |
85 | |
86 | yn = input(f"Using DB={db} grupe={grupe} for {len(quoted)} url(s). Proceed? (default is y) ") |
87 | if 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