add add_link.py and improve hamndling of MediaFile
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
read file with URLs and store in DB
|
||||
"""
|
||||
import logging.config
|
||||
import requests
|
||||
import yaml
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
from pathlib import Path
|
||||
from platformdirs import PlatformDirs
|
||||
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('-u', '--url', help='file with links')
|
||||
parser.add_argument('--video', help='store Url as VideoFile', action="store_true")
|
||||
parser.add_argument('--config', '-c', default='kontor-docker')
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
def get_logger(level: int, config: str):
|
||||
dirs = PlatformDirs(config)
|
||||
logging_config = Path(dirs.user_config_dir, 'logging-config.yaml')
|
||||
with open(logging_config, 'rt') as f:
|
||||
configDict = yaml.safe_load(f.read())
|
||||
logging.config.dictConfig(configDict)
|
||||
logger = logging.getLogger('development')
|
||||
if level is not None:
|
||||
match level:
|
||||
case 0:
|
||||
logger.setLevel(logging.INFO)
|
||||
case 1:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
case _:
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
return logger
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger = get_logger(args.verbose, args.config)
|
||||
logger.info('kontor.add_link started')
|
||||
link: str = args.url
|
||||
data = {"url": link}
|
||||
if args.video:
|
||||
request: str = "http://127.0.0.1:8800/api/video/files"
|
||||
else:
|
||||
request: str = "http://127.0.0.1:8800/api/media/files"
|
||||
response = requests.post(request, json=data)
|
||||
logger.info(f"Status: {response.status_code}")
|
||||
data = response.json()
|
||||
logger.info('kontor.add_link finished')
|
||||
|
||||
Reference in New Issue
Block a user