"""
Types shared by all the files in this project, used as interfaces for moving data.
"""
from configparser import ConfigParser
from dataclasses import dataclass
from typing import List
import os
import configparser
import re
import sys
import string
from pathlib import Path, PurePath
import logging
import random
from pathvalidate import Platform, sanitize_filename
logger = logging.getLogger('types')
def _verify_dir(name: str, file_name: Path) -> bool:
"""
verify a config directory exist. return false if verification fails
"""
if file_name is not None and not file_name.is_dir():
logger.error("Configured directory %s: %s is not a directory or not accessible", name, file_name)
return False
return True
def _verify_name_string(name: str, name_string: str) -> bool:
"""
Verify the name format string.
"""
info = LookedUpFileInfo()
try:
formatter = PartialFormatter()
formatter.format(name_string, **info.asdict())
return True
except KeyError as key_error:
logger.error("Configuration %s is not a valid file name format, please check %s", name, name_string)
logger.error("Error message: %s", key_error)
return False
class PartialFormatter(string.Formatter):
"""
Used for formating NamerConfig.inplace_name and NamerConfig.
"""
supported_keys = ['date','description','name','site','full_site','performers','all_performers','act','ext','trans']
def __init__(self, missing='~~', bad_fmt='!!'):
self.missing, self.bad_fmt=missing, bad_fmt
def get_field(self, field_name, args, kwargs):
# Handle a key not found
try:
val=super().get_field(field_name, args, kwargs)
except (KeyError, AttributeError) as err:
val=None,field_name
if not field_name in self.supported_keys:
raise KeyError(f"Key {field_name} not in support keys: {self.supported_keys}") from err
return val
def format_field(self, value, format_spec: str):
if value is None:
return self.missing
try:
if re.match(r'.\d+s', format_spec):
value = value + format_spec[0] * int(format_spec[1:-1])
format_spec = ''
if re.match(r'.\d+p', format_spec):
value = format_spec[0] * int(format_spec[1:-1]) + value
format_spec = ''
if re.match(r'.\d+i', format_spec):
value = format_spec[0] * int(format_spec[1:-1]) + value + format_spec[0] * int(format_spec[1:-1])
format_spec = ''
return super().format_field(value, format_spec)
except ValueError:
if self.bad_fmt is not None:
return self.bad_fmt
raise
@dataclass(init=False, repr=False, eq=True, order=False, unsafe_hash=True, frozen=False)
class NamerConfig():
"""
Configuration for namer and namer_watchdog
"""
# pylint: disable=too-many-instance-attributes
porndb_token: str = None
"""
token to access porndb.
sign up here: https://metadataapi.net/
"""
name_parser: str = '{_site}{_sep}{_date}{_sep}{_ts}{_name}{_dot}{_ext}'
# pylint: disable=anomalous-backslash-in-string disable=line-too-long
"""
This config may be a regex you provide, or a set of token used to build a regex.
Supported token:
```
_sep r'[\.\- ]+'
_site r'(?P<site>[a-zA-Z0-9\.\-\ ]+[a-zA-Z0-9])'
_date r'(?P<year>[0-9]{2}(?:[0-9]{2})?)[\.\- ]+(?P<month>[0-9]{2})[\.\- ]+(?P<day>[0-9]{2})'
_ts r'((?P<trans>[T|t][S|s])'+_sep+'){0,1}'
_name r'(?P<name>.*)'
_dot r'\.'
_ext r'(?P<ext>[a-zA-Z0-9]{3,4})$'
```
Full default regex:
```
r'(?P<site>[a-zA-Z0-9\.\-\ ]+[a-zA-Z0-9])[\.\- ]+(?P<year>[0-9]{2}(?:[0-9]{2})?)[\.\- ]+(?P<month>[0-9]{2})[\.\- ]+(?P<day>[0-9]{2})((?P<trans>[T|t][S|s])[\.\- ]+){0,1}(?P<name>.*)\.(?P<ext>[a-zA-Z0-9]{3,4})$'
```
The parts extracted from the file will be used in matching.
_ts is optional, and is mostly useful in stripping the marker from the _name, aiding in matching.
_date if present is used to ensure the match is within 24 hours of your date.
If the year/month/day capture groups are not present (due to you not using the supplied _date regex)
dates will not be used in matching, possibly allowing false positives.
"""
# pylint: enable=anomalous-backslash-in-string enable=line-too-long
inplace_name: str = '{site} - {date} - {name}.{ext}'
"""
How to write output file name. When namer.py is run this is applied in place
(next to the file to be processed).
When run from namer_watchdog.py this will be written in to the successdir.
Supports stand python 3 formating, as well as:
* a prefix:
{site: 1p} - in this case put one space in front of the 'site', so ' Vixen'
* a suffix:
{date:_1s} - in this case put one underscore after the 'date', so '2020-01-01_'
* an infix:
{date:_2i} - in this case put two underscore before and after the 'date', so '__2020-01-01__'
Examples:
* {site} - {date} - {scene}.{ext}
* {site}/{date}.{scene}.{ext}
Missing values will be ignored.
Allowed replacements:
* 'date' - in the format of YYYY-MM-DD.
* 'description' - too long, don't use in a name.
* 'name' - the scene name
* 'site' - the site name, BrazzersExxtra, AllHerLuv, Deeper, etc with spaces removed.
* 'full_site' - the site name from porndb, unmodified, i.e: Brazzers Exxtra, All Her Luv, etc.
* 'performers' - space seperated list of female performers
* 'all_performers' - space seperated list of all performers
* 'act' - an act, parsed from original file name, don't use.
* 'ext' - original file's extension, you should keep this.
* 'trans' - 'TS', or 'ts' if detected in original file name.
"""
min_file_size = 300
"""
minimum file size to process in MB, ignored if a file is to be processed
"""
prefer_dir_name_if_available = True
"""
If a directory name is to be prefered over a file name.
"""
set_uid = None
"""
UID Settings for new/moved files/dirs.
"""
set_gid = None
"""
GID Settings for new/moved files/dirs.
"""
write_namer_log = False
"""
Should a log of comparisons be written next to processed video files.
"""
set_dir_permissions = 775
"""
Permissions Settings for new/moved dirs.
"""
set_file_permissions = 664
"""
Permissions Settings for new/moved file.
"""
enabled_tagging: bool = True
"""
Currently metadata pulled from the porndb can be added to mp4 files.
This metadata will be read in fully by Plex, and Apple TV app, partially by Jellyfin (no artist support).
Metadata includes, Title, Release Date, Scene Name, Artist, Source URL, XXX Movie rating.
If a file is an mkv adding metadata at this time isn't supported.
Should metadata fetched from the porn db be written in to the metadata of the mp4.
No flags in this section will be used if this is not set to true.
"""
enabled_poster: bool = True
"""
Should the poster fetched from the porn db be written in to the metadata of the mp4.
This poster will be displayed in Plex, Jellyfin and Apple TV app.
Only applicable if enabled_tagging is True
"""
enable_metadataapi_genres: bool = False
"""
Should genres pulled from the porndb be added to the file? These genres are noisey and
not recommend for use. If this is false a single default genere will be used.
"""
default_genre: str = "Adult"
"""
If genre's are not copied this is the default genere added to files.
Default value is adult.
"""
language: str = None
"""
if language is set it will be used to select the default audio stream in an mp4 t
Python库 | namer-0.7.0.tar.gz
版权申诉
129 浏览量
2022-04-12
01:07:29
上传
评论
收藏 27KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 适用于tensorflow-2.11.0 CUDA版本11.2的cuDNN8.1版本
- 5Y study学习平台2016计算机基础-综合测试(8)_哔哩哔哩_bilibili_2580252704.mp4
- (大赛作品)STM32实现的F072RB NUCLEO智能家居控制.zip
- STM32实现的数字示波器源码+数字信号处理教程、配套实例.zip
- 【cookie续续】【cookie续续】【cookie续续】
- 低功耗STM32实现的F411开发板(原理图+PCB源文件+官方例程+驱动等).zip
- 基于stm32实现的 nucleo-L476的智能灯(操作说明+源码).zip
- 基于STM32实现的 NUCLEO板设计彩色LED照明灯(纯cubeMX开发).zip
- 基于STM32实现的 的联合调试侦听设备解决方案(原理图、PCB源文件、调试工具、视频).zip
- 基于STM32实现的 人群定位、调速智能风扇设计(程序、设计报告、视频演示).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈