Skip to content

Commit b9d0ae3

Browse files
committed
shrink:--continue-from
1 parent e9a6dcb commit b9d0ae3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

xklb/mediafiles/process_ffmpeg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ def process_path(args, path, include_timecode=False, subtitle_streams_unsupporte
360360

361361
if not output_path.exists():
362362
return path if path.exists() else None
363+
elif not path.exists():
364+
return output_path
363365

364366
output_stats = output_path.stat()
365367

xklb/mediafiles/process_media.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from contextlib import suppress
33
from shutil import which
44

5+
from pathlib import Path
6+
57
from xklb import usage
68
from xklb.mediadb import db_history
79
from xklb.mediafiles import process_ffmpeg, process_image, process_text
@@ -75,6 +77,7 @@ def parse_args() -> argparse.Namespace:
7577
parser.add_argument("--transcoding-image-time", type=float, default=1.5, metavar="SECONDS")
7678

7779
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")
7881

7982
arggroups.process_ffmpeg(parser)
8083
arggroups.clobber(parser)
@@ -143,6 +146,9 @@ def check_shrink(args, m) -> list:
143146
m["duration"] = probe.duration
144147
except processes.UnplayableFile:
145148
m["duration"] = None
149+
if args.delete_unplayable:
150+
Path(m["path"]).unlink(missing_ok=True)
151+
return []
146152
if m["duration"] is None or not m["duration"] > 0:
147153
log.debug("[%s]: Invalid duration", m["path"])
148154
m["duration"] = m["size"] / args.source_audio_bitrate * 8
@@ -201,6 +207,9 @@ def check_shrink(args, m) -> list:
201207
m["duration"] = probe.duration
202208
except processes.UnplayableFile:
203209
m["duration"] = None
210+
if args.delete_unplayable:
211+
Path(m["path"]).unlink(missing_ok=True)
212+
return []
204213
if m["duration"] is None or not m["duration"] > 0:
205214
log.debug("[%s]: Invalid duration", m["path"])
206215
m["duration"] = m["size"] / args.source_video_bitrate * 8
@@ -266,6 +275,16 @@ def process_media() -> None:
266275
media, key=lambda d: d["savings"] / (d["processing_time"] or args.transcoding_image_time), reverse=True
267276
)
268277

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+
269288
if not media:
270289
processes.no_media_found()
271290

@@ -387,8 +406,12 @@ def process_media() -> None:
387406
m["new_size"] = path_utils.folder_size(new_path)
388407

389408
if m["media_type"] in ("Audio", "Video"):
390-
with suppress(processes.UnplayableFile):
409+
try:
391410
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
392415

393416
if not os.path.exists(m["path"]):
394417
new_free_space += (m.get("compressed_size") or m["size"]) - m["new_size"]

0 commit comments

Comments
 (0)