ehForwarderBot / efb-telegram-master

EFB Telegram Master Channel, a channel for EH Forwarder Bot.
GNU Affero General Public License v3.0
223 stars 78 forks source link

External programs cannot open temporary files created by Python on Windows via file name #90

Closed blueset closed 4 years ago

blueset commented 4 years ago

As documented in Python docs, due to the architecture design of Windows NT and later, despite the full file name is provided, NamedTemporaryFile cannot be reopened by its name again either within the same process or not.

EFB Telegram Master channel (ETM) currently strongly relies on external packages and programs like libmagic and ffmpeg to detect file type and re-encode media files. This restriction imposed by Windows prevents us from performing those actions. Meanwhile we haven’t managed to discover a way to let external programs to accept file handles from Python.

So here I’d like to seek help on this issue to allow external programs to access those temporary files while keeping its “lifecycle” feature — to delete the file automatically upon closing it.

blueset commented 4 years ago

Attempted to stream I/O with FFmpeg with stdin and stdout. This strategy said to be only working with a few encodings. It seems that Telegram GIF (MP4, h264, soundless) luckily felt in that range.

Haven't tested on a real NT environment (as I don’t currently have one). If the issue persists, reopen this issue and leave a comment with full trackback, and I will take a look if I can.