mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
* Batch reorganization is supported for both Domain and Channel Collections. * Batch reorganization happens when any Collection does not match the respective file format. For example, a Channel Collection file format that does not match the `yt_dlp_options.file_name_format` will show `needs_reorganization`. * Individual Collections can always be reorganized. The reorganization is a little more aggressive. Useful for when some files may have been missed in the batch reorganization.
34 lines
1,004 B
Python
34 lines
1,004 B
Python
import pathlib
|
|
from typing import Union
|
|
|
|
from sqlalchemy import types
|
|
|
|
PATH_TYPE = Union[str, pathlib.Path]
|
|
|
|
|
|
class MediaPathType(types.TypeDecorator): # noqa
|
|
impl = types.String
|
|
|
|
def process_bind_param(self, value, dialect):
|
|
"""Convert paths into what the DB expects. (pathlib.Path -> str)"""
|
|
if value is None:
|
|
return value
|
|
|
|
if value == '':
|
|
raise ValueError('MediaPath cannot be empty')
|
|
|
|
if isinstance(value, pathlib.Path):
|
|
if not value.is_absolute():
|
|
# Resolve relative paths against media directory, not cwd
|
|
from wrolpi.common import get_media_directory
|
|
value = get_media_directory() / value
|
|
value = str(value)
|
|
|
|
if not isinstance(value, str):
|
|
raise ValueError(f'Invalid MediaPath type ({type(value)}): {value}')
|
|
|
|
return value
|
|
|
|
def process_result_value(self, value, dialect):
|
|
if value:
|
|
return pathlib.Path(value)
|