How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when
I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
On Mon, 7/7/2025 12:39 AM, VanguardLH wrote:
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the
existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when
I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL> >>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing
through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent
stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
Would there be an option to add a date-field instead of an
autonumber ? That might make a slightly more unique identifier,
except date fields don't go down to the second level.
In a Google, I can see the autonumber start value can be assigned.
But I don't know if that really helps matters.
"Instead of %(playlist_index)s, you should use
youtube-dl --autonumber-start 5 $URL -o "%(autonumber)s_stuff"
It will start %(autonumber)s at 5 in this case.
"
You could also create a folder for each run, and
store the output in the folder. Your script design
would then control the folder name created just
before the run.
Paul
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when
I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
Paul <nospam@needed.invalid> wrote:
On Mon, 7/7/2025 12:39 AM, VanguardLH wrote:
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the
existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when >>> I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL> >>>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing
through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
As I say, I _think_ I have seen that, so I think it is possible. No ideaor something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent >>> stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
The problem with autonumber is it is not remembered between yt-dlp
sessions. When I run yt-dlp the first time, yes, a number will get
added to the filename, like 00001. Whenever I later run yt-dlp again, autonumber starts at 00001, so yt-dlp overwrites an existing file
instead of increment to 00002.
1st run: file = dogbarking 00001.mp4
2nd run: file = dogbarking 00001.mp4 (overwrites existing file)
As you noted, and I've read in yt-dlp's documentation, autonumber is
oriented when you batch capture several videos. The indexing is not remembered between separate yt-dlp sessions. There is no filename
collision avoidance in yt-dlp. Not even a pause to prompt on overwrite.
I've tried a couple GUI frontends to yt-dlp, but they don't increment a numeric index if the output file already exists, either. Either they
end up overwriting the existing file (and without prompting before overwriting), or they error (the video capture is lost). At best, in
trying to avoid filename collisions, they may be optioned to save the
videos in a folder named for the web site's domain, so the video is
saved under <outputFolder>\<domain>\<filename>.
That would provide collision avoidance when saving different videos at different sites that happen to have the same filename, but not if you
save again the same video at the same site. I realize the next question
is "Why save a duplicate of a video?" Actually that's not what I want.
overwrite an existing file by the same name. Even File Manager willI'm pretty sure yt-dlp is very low-level, i. e. does its file management itself, rather than calling Windows functions - I'm not sure what it's
prompt if I try to copy a file from one folder to another that already
has a file by the same name. Even the 'copy' command will prompt on an overwrite (unless you use the /y parameter).
On 7/7/2025 12:39 AM, VanguardLH wrote:
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the
existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when
I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL> >>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing
through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent
stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
I have never used yt-dlp but "filesystem Options" -w, --no-overwrites
looks like what you want.
Alternative is a batch which runs yt-dlp and uses SETX = SETX+1 as an
index to be used for the next download.
Zaidy036 <Zaidy036@air.isp.spam> wrote:SetX is environmental and maintained for use by following runs of any
On 7/7/2025 12:39 AM, VanguardLH wrote:
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the
existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when >>> I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL> >>>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing
through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent >>> stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
I have never used yt-dlp but "filesystem Options" -w, --no-overwrites
looks like what you want.
Doesn't help. yt-dlp still does the download (into temp files), and
then saves to an output file. yt-dlp would waste the time and bandwidth
to get the video only to abort at the end with the output file write.
Yeah, in a way, it prevents filename collisions, but that's by not
writing at all.
Alternative is a batch which runs yt-dlp and uses SETX = SETX+1 as an
index to be used for the next download.
Thanks for mention of the set command to increment an envvar, but that
would work only when running multiple sequential yt-dlp commands within
the same session (i.e., inside the same shell). After doing a download,
I close the console window (cmd shell), so envvars are lost, and I
really don't want to attempt to set global envvars to keep track across shells. The next time I load the shell to run yt-dlp again, setx would
start undefined (nul), would increment, but would not prevent a filename collision on an existing file. My script would have to add code
checking if the file exists, and then do some post-downloading code.
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the existing file.
VanguardLH wrote:
Zaidy036 <Zaidy036@air.isp.spam> wrote:
Alternative is a batch which runs yt-dlp and uses SETX = SETX+1 as
an index to be used for the next download.
Thanks for mention of the set command to increment an envvar, but
that would work only when running multiple sequential yt-dlp
commands within the same session (i.e., inside the same shell).
After doing a download, I close the console window (cmd shell), so
envvars are lost, and I really don't want to attempt to set global
envvars to keep track across shells. The next time I load the shell
to run yt-dlp again, setx would start undefined (nul), would
increment, but would not prevent a filename collision on an existing
file. My script would have to add code checking if the file exists,
and then do some post-downloading code.
SetX is environmental and maintained for use by following runs of any
program or batch and not affected even by shut downs but only by
specific commands
setx=setx+1
Error: Invalid sytax.
setx = setx+1
ERROR: The name of an environment variable cannot include an equal sign (=).
Zaidy036 <Zaidy036@air.isp.spam> wrote:
VanguardLH wrote:
Zaidy036 <Zaidy036@air.isp.spam> wrote:
Alternative is a batch which runs yt-dlp and uses SETX = SETX+1 as
an index to be used for the next download.
Thanks for mention of the set command to increment an envvar, but
that would work only when running multiple sequential yt-dlp
commands within the same session (i.e., inside the same shell).
After doing a download, I close the console window (cmd shell), so
envvars are lost, and I really don't want to attempt to set global
envvars to keep track across shells. The next time I load the shell
to run yt-dlp again, setx would start undefined (nul), would
increment, but would not prevent a filename collision on an existing
file. My script would have to add code checking if the file exists,
and then do some post-downloading code.
SetX is environmental and maintained for use by following runs of any
program or batch and not affected even by shut downs but only by
specific commands
setx=setx+1
Error: Invalid sytax.
setx = setx+1
ERROR: The name of an environment variable cannot include an equal sign (=).
Don't remember using setx, or it has been way too long since previously
used, so I ran "setx /?" to find out how to use it. Your syntax is
invalid for setx, but is valid for set (not setx) for a local envvar
within a shell, like:
set vname=0
set /a vname=%vname% + 1 > nul
echo %vname%
The /a switch is needed for the set command to do arithmetic; i.e, /a
makes set evaluate an expression. envvars are always strings, even
'set var=0' or 'setx var 0' has var hold a string of "0", not a numeric
value of zero. Alas, a defect with /a is it also echoes out the
evaluated value which can be confusing in the stdout of the batch
script, so I redirect stdout for 'set /a' to nul.
setx defines global envvars, but does not update the current shell to
use the new envvar perhaps to delayed execution, by default, in commands
ran in a shell. The envvar gets defined, but envvars are loaded when a
shell loads, so the envvar is available in later shells.
"On a local system, variables created or modified by this tool will be
available in future command windows but not in the current CMD.exe
command window."
(from "setx /?")
setx has no /a switch to make it evaluate a string as an expression, so
I'd have to add var to the envvar list beforehand, like use sysdm.cpl to
add a new envvar, or run a batch script as a startup item on login to
run, say:
setx vname_global 1
and call a batch script using:
yt "<url>"
where the double-quotes must be added to prevent the command-line parser
from seeing any ampersands (&) in the URL used to delineate arguments in
the URL, and where the script did:
ytp-dl.exe --output <template> %1
set /a vname_local=%vname_global% + 1 > nul
setx vname_global %vname_local%
I would still need to figure out the syntax for <template>, but it would include vname_global to index the output file created by yt-dlp to help
to avoid filename collisions.
So, setx could be used to track indexing across separate command shells,
but, boy, it can get confusing to maintain the script, and relies on a
global envvar that I'd like to avoid just to workaround not recognizing
a file already exists by the same name, and affix an index onto the
output file. Rather than bother with a global envvar (which I would
have to remember since other batch script or programs could possibly
step on the same name for the envvar), I can add post-processing code to
the the batch script to avoid the filename collisions that yt-dlp
doesn't avoid, and neither do the GUI frontends. I've hunted through
the vast list of command-line args and switches to yt-dlp, but don't see anything to avoid filename collisions, and from what I've found posted
by others seems a common affliction with yt-dlp.
Sorry but I was just talking about the logic flow and not the batch
commands themselves.
So don't use SETX but rather let yt-dlp download into a specified folder followed by batch commands to transfer into the "real" folder you want
it in. If there is a name collision then the transfer will error and can
ask what name would you like to use or just cycle thru its name with an
added letter or number until the transfer succeeds.
On 2025-07-07 05:39, VanguardLH wrote:
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the
existing file.
Whenever in the past I've used You-TubeDL or You-TubeDL+ I get a
filename where the random number key from the original YouTube video URL
is appended to the filename in square brackets. As these numbers are
unique, why not just leave them in the filename to avoid the problem you describe?
For a real example ...
Chris Norman - Blame It On My Jealous Heart https://www.youtube.com/watch?v=TL0bxtX35Ng
... results in (after renaming by myself)
Chris Norman - Jealous Heart (official video) [TL0bxtX35Ng].webm
VanguardLH wrote:
setx=setx+1
Error: Invalid sytax.
setx = setx+1
ERROR: The name of an environment variable cannot include an equal sign (=).
SETX /?
How do I get yt-dlp from overwriting an existing file, and instead
append a number to create a new output file, so both the existing and
next captured video still survive? Otherwise, yt-dlp just steps on the existing file.
Say I go to site1 to capture dogbarking.mp4. I go to site2 where there
is also dogbarking.mp4, but it is a different video with the same
filename. I don't want yt-dlp to step on dogbarking.mp4 from site1 when
I capture dogbarking.mp4 from site2, or even if I recapture multiple
times the same dogbarking.mp4 video from the same site.
I've tried the -o output template argument, like:
yt-dlp.exe -o "%(title)s %(autonumber)s.%(ext)s" --no-overwrites <someURL>
That has yt-dlp add a 5-digit number at the end of filename, like
dogbarking 00001.mp4, from site1 but then the same filename is used at
site2, so yt-dlp steps atop the existing file despite the
--no-overwrites argument. Since autonumber ends up appending the same
00001 to every output file, I suspect it is of use only when recursing through multiple video streams, like capturing from a playlist.
What I'd like when capturing videos that happen to have the same
filename at multiple sites is to end up with:
dogbarking.mp4
dogbarking (1).mp4
dogbarking (2).mp4
dogbarking (3).mp4
or something similar. Same filename (since it is the same filename at
each site), but differentiated by an appended index to avoid conflict.
If there is an output file conflict, index the current output to prevent stepping on an existing same-named file.
Or, is that a scheme of which yt-dlp is incapable, and I have to move
from the command line to a GUI frontend that will handle the
same-filename conflict?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 507 |
Nodes: | 16 (2 / 14) |
Uptime: | 184:52:41 |
Calls: | 9,958 |
Files: | 13,825 |
Messages: | 6,355,759 |