add overwrite feature
This commit is contained in:
parent
474e8f5773
commit
4596d11200
1 changed files with 17 additions and 3 deletions
|
@ -24,11 +24,17 @@ def test_dir(files: List[str], pattern: str) -> List[str]:
|
||||||
log.debug("trying:\n " + "\n ".join(files))
|
log.debug("trying:\n " + "\n ".join(files))
|
||||||
valid_files = fnmatch.filter(files, pattern)
|
valid_files = fnmatch.filter(files, pattern)
|
||||||
if valid_files:
|
if valid_files:
|
||||||
log.debug("found:\n " + "\n ".join(valid_files))
|
log.info("found:\n " + "\n ".join(valid_files))
|
||||||
return valid_files
|
return valid_files
|
||||||
|
|
||||||
|
|
||||||
def main(media_path: str, tag: str, pattern: str, recursive: bool = False) -> None:
|
def main(
|
||||||
|
media_path: str,
|
||||||
|
tag: str,
|
||||||
|
pattern: str,
|
||||||
|
recursive: bool = False,
|
||||||
|
overwrite: bool = False,
|
||||||
|
) -> None:
|
||||||
abs_media_path = os.path.abspath(media_path)
|
abs_media_path = os.path.abspath(media_path)
|
||||||
log.info(
|
log.info(
|
||||||
f"Scanning {abs_media_path}{' recursively' if recursive else ''} for {pattern}"
|
f"Scanning {abs_media_path}{' recursively' if recursive else ''} for {pattern}"
|
||||||
|
@ -58,7 +64,7 @@ def main(media_path: str, tag: str, pattern: str, recursive: bool = False) -> No
|
||||||
if config is None:
|
if config is None:
|
||||||
raise FileNotFoundError(f"Config file could not be loaded for tag id: {tag}")
|
raise FileNotFoundError(f"Config file could not be loaded for tag id: {tag}")
|
||||||
|
|
||||||
tracks: List[str] = config.get("tracks", [])
|
tracks: List[str] = config.get("tracks", []) if not overwrite else []
|
||||||
tracks.extend(sorted((f.replace("\\", "/") for f in valid_paths)))
|
tracks.extend(sorted((f.replace("\\", "/") for f in valid_paths)))
|
||||||
config["tracks"] = tracks
|
config["tracks"] = tracks
|
||||||
|
|
||||||
|
@ -94,6 +100,13 @@ if __name__ == "__main__":
|
||||||
help="Search recursively. Pattern applies to whole path (relative to media_path).",
|
help="Search recursively. Pattern applies to whole path (relative to media_path).",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-o",
|
||||||
|
"--overwrite",
|
||||||
|
action="store_true",
|
||||||
|
help="Overwrite and replace existing track list.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
@ -104,4 +117,5 @@ if __name__ == "__main__":
|
||||||
tag=args.tag,
|
tag=args.tag,
|
||||||
pattern=args.pattern,
|
pattern=args.pattern,
|
||||||
recursive=args.recursive,
|
recursive=args.recursive,
|
||||||
|
overwrite=args.overwrite,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue