Skip to content

Commit

Permalink
reset key and don't cache until confirm new path
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Sep 11, 2024
1 parent 22f2419 commit f30d9f9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ofscraper/actions/actions/download/utils/keyhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,15 @@ async def un_encrypt(item, c, ele, input_=None):
if not key:
raise Exception(f"{get_medialog(ele)} Could not get key")
key=key.strip()
await asyncio.get_event_loop().run_in_executor(
common_globals.thread,
partial(
cache.set, ele.license, key, expire=constants.getattr("KEY_EXPIRY")
),
)
log.debug(f"{get_medialog(ele)} got key")
log.debug(f"{get_medialog(ele)} got key {key}")
newpath = pathlib.Path(
re.sub("\.part$", f".{item['ext']}", str(item["path"]), flags=re.IGNORECASE)
)
ffmpeg_key = get_ffmpeg_key(key)
log.debug(f"{get_medialog(ele)} got ffmpeg key {ffmpeg_key}")
log.debug(
f"{get_medialog(ele)} renaming {pathlib.Path(item['path']).absolute()} -> {newpath}"
)
ffmpeg_key = get_ffmpeg_key(key)
r = run(
[
settings.get_ffmpeg(),
Expand All @@ -84,13 +79,25 @@ async def un_encrypt(item, c, ele, input_=None):
]
)
if not pathlib.Path(newpath).exists():
log.debug(f"{get_medialog(ele)} ffmpeg decryption failed")
log.debug(f"{get_medialog(ele)} ffmpeg {r.stderr.decode()}")
log.debug(f"{get_medialog(ele)} ffmpeg {r.stdout.decode()}")
await asyncio.get_event_loop().run_in_executor(
common_globals.thread,
partial(
cache.set, None, key, expire=constants.getattr("KEY_EXPIRY")
),
)
raise Exception(f"{get_medialog(ele)} ffmpeg decryption failed")
else:
log.debug(f"{get_medialog(ele)} ffmpeg decrypt success {newpath}")
pathlib.Path(item["path"]).unlink(missing_ok=True)
item["path"] = newpath
await asyncio.get_event_loop().run_in_executor(
common_globals.thread,
partial(
cache.set, ele.license, key, expire=constants.getattr("KEY_EXPIRY")
),
)
return item
except Exception as E:
log.traceback_(E)
Expand Down

0 comments on commit f30d9f9

Please sign in to comment.