migrate to pathlib and importlib

This commit is contained in:
jonathan 2021-06-01 14:38:40 +02:00
parent 532a5462c9
commit 8acf3cc3fc

View File

@ -21,10 +21,9 @@ This is mainly for unify clips to have a unique output.
""" """
import math import math
import os
import re import re
from glob import glob from importlib import import_module
from pydoc import locate from pathlib import Path
from ..utils import (get_float, is_advertisement, lower_third, messenger, pre, from ..utils import (get_float, is_advertisement, lower_third, messenger, pre,
sync_op) sync_op)
@ -43,7 +42,7 @@ def text_filter():
font = '' font = ''
if lower_third.add_text and lower_third.over_pre: if lower_third.add_text and lower_third.over_pre:
if lower_third.fontfile and os.path.isfile(lower_third.fontfile): if lower_third.fontfile and Path(lower_third.fontfile).is_file():
font = f":fontfile='{lower_third.fontfile}'" font = f":fontfile='{lower_third.fontfile}'"
filter_chain = [ filter_chain = [
"null,zmq=b=tcp\\\\://'{}',drawtext=text=''{}".format( "null,zmq=b=tcp\\\\://'{}',drawtext=text=''{}".format(
@ -139,7 +138,7 @@ def overlay_filter(duration, advertisement, ad_last, ad_next):
logo_filter = '[v]null' logo_filter = '[v]null'
scale = '' scale = ''
if pre.add_logo and os.path.isfile(pre.logo) and not advertisement: if pre.add_logo and Path(pre.logo).is_file() and not advertisement:
logo_chain = [] logo_chain = []
if pre.logo_scale and \ if pre.logo_scale and \
re.match(r'\d+:-?\d+', pre.logo_scale): re.match(r'\d+:-?\d+', pre.logo_scale):
@ -258,12 +257,13 @@ def custom_filter(filter_type, node):
""" """
read custom filters from filters folder read custom filters from filters folder
""" """
filter_dir = os.path.dirname(os.path.abspath(__file__)) filter_dir = Path(__file__).parent.absolute()
filters = [] filters = []
for filter_file in glob(os.path.join(filter_dir, f'{filter_type}_*')): for filter_file in filter_dir.glob(f'{filter_type}_*'):
filter_ = os.path.splitext(os.path.basename(filter_file))[0] filter_ = Path(filter_file).stem
filter_function = locate(f'ffplayout.filters.{filter_}.filter_link') filter_function = import_module(
f'ffplayout.filters.{filter_}').filter_link
link = filter_function(node) link = filter_function(node)
if link is not None: if link is not None: