|
2 | 2 | from contextlib import suppress |
3 | 3 | from shutil import which |
4 | 4 |
|
| 5 | +from pathlib import Path |
| 6 | + |
5 | 7 | from xklb import usage |
6 | 8 | from xklb.mediadb import db_history |
7 | 9 | from xklb.mediafiles import process_ffmpeg, process_image, process_text |
@@ -75,6 +77,7 @@ def parse_args() -> argparse.Namespace: |
75 | 77 | parser.add_argument("--transcoding-image-time", type=float, default=1.5, metavar="SECONDS") |
76 | 78 |
|
77 | 79 | parser.add_argument("--no-confirm", "--yes", "-y", action="store_true") |
| 80 | + parser.add_argument("--continue-from", help="Skip media until specific file path is seen") |
78 | 81 |
|
79 | 82 | arggroups.process_ffmpeg(parser) |
80 | 83 | arggroups.clobber(parser) |
@@ -143,6 +146,9 @@ def check_shrink(args, m) -> list: |
143 | 146 | m["duration"] = probe.duration |
144 | 147 | except processes.UnplayableFile: |
145 | 148 | m["duration"] = None |
| 149 | + if args.delete_unplayable: |
| 150 | + Path(m["path"]).unlink(missing_ok=True) |
| 151 | + return [] |
146 | 152 | if m["duration"] is None or not m["duration"] > 0: |
147 | 153 | log.debug("[%s]: Invalid duration", m["path"]) |
148 | 154 | m["duration"] = m["size"] / args.source_audio_bitrate * 8 |
@@ -201,6 +207,9 @@ def check_shrink(args, m) -> list: |
201 | 207 | m["duration"] = probe.duration |
202 | 208 | except processes.UnplayableFile: |
203 | 209 | m["duration"] = None |
| 210 | + if args.delete_unplayable: |
| 211 | + Path(m["path"]).unlink(missing_ok=True) |
| 212 | + return [] |
204 | 213 | if m["duration"] is None or not m["duration"] > 0: |
205 | 214 | log.debug("[%s]: Invalid duration", m["path"]) |
206 | 215 | m["duration"] = m["size"] / args.source_video_bitrate * 8 |
@@ -266,6 +275,16 @@ def process_media() -> None: |
266 | 275 | media, key=lambda d: d["savings"] / (d["processing_time"] or args.transcoding_image_time), reverse=True |
267 | 276 | ) |
268 | 277 |
|
| 278 | + if args.continue_from: |
| 279 | + seen_continue_from = False |
| 280 | + new_media = [] |
| 281 | + for m in media: |
| 282 | + if args.continue_from in m['path']: |
| 283 | + seen_continue_from = True |
| 284 | + if seen_continue_from: |
| 285 | + new_media.append(m) |
| 286 | + media = new_media |
| 287 | + |
269 | 288 | if not media: |
270 | 289 | processes.no_media_found() |
271 | 290 |
|
@@ -387,8 +406,12 @@ def process_media() -> None: |
387 | 406 | m["new_size"] = path_utils.folder_size(new_path) |
388 | 407 |
|
389 | 408 | if m["media_type"] in ("Audio", "Video"): |
390 | | - with suppress(processes.UnplayableFile): |
| 409 | + try: |
391 | 410 | m["duration"] = processes.FFProbe(new_path).duration |
| 411 | + except processes.UnplayableFile: |
| 412 | + if args.delete_unplayable: |
| 413 | + Path(new_path).unlink(missing_ok=True) |
| 414 | + continue |
392 | 415 |
|
393 | 416 | if not os.path.exists(m["path"]): |
394 | 417 | new_free_space += (m.get("compressed_size") or m["size"]) - m["new_size"] |
|
0 commit comments