Skip to content

feat: made the frag files to be created in the tmp/ folder instead of target download folder - #1975

Merged
port19x merged 10 commits into
pystardust:masterfrom
emre-tiryaki:tmp-dir-as-fragment-download-folder
Nov 10, 2026
Merged

port19x merged 10 commits into
pystardust:masterfrom
emre-tiryaki:tmp-dir-as-fragment-download-folder

Conversation

@emre-tiryaki

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • Feature
  • Documentation update

Description

Closes #1955

When downloading with yt-dlp, the intermediate files (.part, .ytdl, and the -FragN files created by concurrent fragment downloads) were written into the download directory. This is noisy for file managers, causes needless write churn on SSDs, and makes it hard to tell finished episodes from in-progress ones while a range is still downloading.

This PR moves yt-dlp's temporary files into a separate directory. Only the finished file ends up in the download directory.

Changes

  • New variable tmp_dir, defaulting to ${TMPDIR:-/tmp}/ani-cli, overridable with ANI_CLI_TMP_DIR. No new CLI flag, in line with the other ANI_CLI_* settings.
  • download() now passes -P "home:$download_dir" -P "temp:$tmp_dir" to yt-dlp and only the file name to -o.

Notes

  • A fixed directory is used instead of mktemp -d on purpose, so yt-dlp can still resume an interrupted download from its .part file.
  • If /tmp is a tmpfs, the in-progress file lives in RAM until the episode is finished. Users with limited RAM can point ANI_CLI_TMP_DIR to a disk-backed location.
  • The ffmpeg code path (used when a separate audio track exists) is untouched. It writes directly to the destination and does not create fragment files.

Usage

Default behaviour, fragments go to ${TMPDIR:-/tmp}/ani-cli, the result lands in the current directory:

./ani-cli -d -e 1-5 Violet Evergarden

Absolute download directory, fragments still stay out of it:

ANI_CLI_DOWNLOAD_DIR="$HOME/Videos/anime" ./ani-cli -d -e 1-3 Violet Evergarden

Custom temp location, e.g. when the default tmpfs is too small:

ANI_CLI_TMP_DIR="$HOME/.cache/ani-cli" ./ani-cli -d -e 1-6 Violet Evergarden

Checking the result while a download is running:

ls /tmp/ani-cli           # .part / -Frag* files appear here
ls "$ANI_CLI_DOWNLOAD_DIR" # only finished .mp4 files appear here

Checklist

  • any anime playing
  • bumped version

  • next, prev, replay and select work
  • -c history and continue work
  • -d downloads work
  • -e (select episode) aka -r (range selection) works
  • -S select index works
  • -q quality works
  • -s syncplay works
  • -v vlc works
  • --dub and regular (sub) mode both work
  • --nextep-countdown countdown to next ep works

  • -h help info is up to date
  • Readme is up to date
  • Man page is up to date

Additional Testcases

(these don't block a merge)

  • --skip ani-skip works
  • --no-detach no detach works
  • --exit-after-play auto exit after playing works

Copy Pasta

./ani-cli -V
./ani-cli -S 1 -e 1 -d flcl
./ani-cli -S 1 -e 1 -q worst -v flcl
./ani-cli -c -s --dub

@port19x port19x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of the feature is to reduce Disk writes by leveraging tmpfs mountpoints / directories where available.
$HOME/tmp lives on disk on standard linux distros.
Please change the default

@emre-tiryaki

emre-tiryaki commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

I know this isn't what you suggested, but I added /dev/shm before /tmp in the fallback, because /tmp isn't a tmpfs on every distro (Ubuntu, for example). The catch is that /dev/shm can be small in some setups like Docker. If you'd rather keep it simple, I can remove it, just say so.

@emre-tiryaki
emre-tiryaki force-pushed the tmp-dir-as-fragment-download-folder branch 2 times, most recently from 1f48203 to 59c4880 Compare October 27, 2026 12:29
@emre-tiryaki
emre-tiryaki requested a review from port19x November 4, 2026 11:22
@port19x

port19x commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Apologies for the delay in review.
I doubt I'll find the time to test and review this week, but I have not forgotten this PR

@port19x port19x left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked into how the paths behave across platforms and find this to be quite error prone, especially on Windows and in Docker Containers.

I'd like to revise my earlier call to make this default.
I'd prefer this to be off by default, with ANI_CLI_TMP_DIR retained as an option for users with fragile/slow disks.
That way we can also drastically debloat this PR by getting rid of L129-L142 and L363.
L470 would be tmp_dir="${ANI_CLI_TMP_DIR:-$ANI_CLI_DOWNLOAD_DIR}" or tmp_dir="${ANI_CLI_TMP_DIR:-.}", the choice of which I'll leave to your discretion for now.

Comment thread ani-cli Resolved
… the target download directory when downloading episodes.
…ory from `$XDG_RUNTIME_DIR`, `/dev/shm`, then `${TMPDIR:-/tmp}`, so a tmpfs is preferred where available. `ANI_CLI_TMP_DIR` still overrides it.
…nto the loop when XDG_RUNTIME_DIR variable is empty. Also for the defaul_tmp_dir function to not work everytime now it only called in download function
…e download_dir and removed the tmp_dir variable check in download function.
@emre-tiryaki
emre-tiryaki force-pushed the tmp-dir-as-fragment-download-folder branch from 1637e0d to da98f11 Compare November 9, 2026 13:37
Copilot AI balanced review requested due to automatic review settings November 9, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@port19x

port19x commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

I like the scope of it now and it's almost done.
I made a mistake regarding the handling of -o and -P earlier, let me provide a suggestion in review for how we can preserve backwards compatibility without breaking the feature

@port19x port19x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After my code suggestions, it should behave as follows:
Image

What would remain is some brief testing on my machine at home, I'm optimistic about a swift merge

Comment thread ani-cli Resolved
Comment thread ani-cli Resolved
…the tmp folder feature. added documentation for it to.

@port19x port19x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise, I'll try to test tonight

Comment thread README.md Resolved

@port19x port19x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works beautifully, thanks for your contribution and patience

@port19x
port19x merged commit 8527f18 into pystardust:master Nov 10, 2026
13 checks passed
@candrapersada

candrapersada commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

By default, files are saved in %TEMP% on Windows if ANI_CLI_TMP_DIR is not set.

@emre-tiryaki

Copy link
Copy Markdown
Contributor Author

@candrapersada

Is it a problem?

Maybe bad for backwards compatibility?

@candrapersada

Copy link
Copy Markdown
Contributor

because by default, Windows uses %TEMP%

@port19x

port19x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

That sounds pretty great, does this include downloaded files?

@candrapersada

candrapersada commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

That sounds pretty great, does this include downloaded files?

just for temporary files before the download is complete
and by default, it uses %TEMP% on Windows.

Comment thread ani-cli

mode="${ANI_CLI_MODE:-sub}"
download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
tmp_dir="${ANI_CLI_TMP_DIR:-.}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tmp_dir="${ANI_CLI_TMP_DIR:-.}"
tmp_dir="${ANI_CLI_TMP_DIR:-${TEMP:-.}}"

@emre-tiryaki

Copy link
Copy Markdown
Contributor Author

I didn't understand the issue.

is it working or not?

@port19x

port19x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Me neither @emre-tiryaki

@candrapersada pls make a proper issue or at the very least explain in full sentences

@port19x

port19x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Not even GPT-6-Astra can make sense of his suggestion/comment btw, kinda funny

@candrapersada

Copy link
Copy Markdown
Contributor

What I mean is adding a temp directory by default—without requiring ANI_CLI_TMP_DIR—on Windows.

@port19x

port19x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Do you mean you want that or do you mean that this is the current behaviour?

@candrapersada

candrapersada commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Do you mean you want that

By default, on Windows, it uses the TEMP directory for temporary files, without requiring ANI_CLI_TMP_DIR to be set.

@emre-tiryaki

Copy link
Copy Markdown
Contributor Author

But every other os is manually configuring ANI_CLI_TMP_DIR.

Should windows be an exception?

@port19x

port19x commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

I don't think this is worth changing the code over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

place yt-dlp download fragments into a tempdir

4 participants