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