Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"--all-formats" overwrite existing files #334

Closed
andreabravetti opened this issue Apr 14, 2012 · 1 comment
Closed

"--all-formats" overwrite existing files #334

andreabravetti opened this issue Apr 14, 2012 · 1 comment

Comments

@andreabravetti
Copy link

@andreabravetti andreabravetti commented Apr 14, 2012

"--all-formats" overwrite existing files and keep only one file per extension even if more than one exists.

Example:

[andrea@sibilla ~]$ youtube-dl --all-formats http://www.youtube.com/watch?v=00000000000

[youtube] Setting language
[youtube] 00000000000: Downloading video webpage
[youtube] 00000000000: Downloading video info webpage
[youtube] 00000000000: Extracting video information
[download] Destination: 00000000000.webm
[download] 100.0% of 3.71M at 779.58k/s ETA 00:00
[download] Destination: 00000000000.flv
[download] 100.0% of 3.03M at 257.87k/s ETA 00:00
[download] Destination: 00000000000.webm
[download] 100.0% of 2.80M at 771.26k/s ETA 00:00
[download] Destination: 00000000000.flv
[download] 100.0% of 2.68M at 222.57k/s ETA 00:00
[download] Destination: 00000000000.mp4
[download] 100.0% of 2.24M at 743.58k/s ETA 00:00
[download] Destination: 00000000000.flv
[download] 100.0% of 1.92M at 162.52k/s ETA 00:00

[andrea@sibilla ~]$ ls -l

-rw-rw-r--. 1 andrea andrea 3173446 16 set 2011 00000000000.flv
-rw-rw-r--. 1 andrea andrea 2347362 16 set 2011 00000000000.mp4
-rw-rw-r--. 1 andrea andrea 3886456 16 set 2011 00000000000.webm

It should be:

[andrea@sibilla ~]$ youtube-dl --all-formats http://www.youtube.com/watch?v=00000000000

[youtube] Setting language
[youtube] 00000000000: Downloading video webpage
[youtube] 00000000000: Downloading video info webpage
[youtube] 00000000000: Extracting video information
[download] Destination: 00000000000.webm
[download] 100.0% of 3.71M at 779.58k/s ETA 00:00
[download] Destination: 00000000000.flv
[download] 100.0% of 3.03M at 257.87k/s ETA 00:00
[download] Destination: 00000000000-1.webm
[download] 100.0% of 2.80M at 771.26k/s ETA 00:00
[download] Destination: 00000000000-1.flv
[download] 100.0% of 2.68M at 222.57k/s ETA 00:00
[download] Destination: 00000000000.mp4
[download] 100.0% of 2.24M at 743.58k/s ETA 00:00
[download] Destination: 00000000000-2.flv
[download] 100.0% of 1.92M at 162.52k/s ETA 00:00

[andrea@sibilla ~]$ ls -l

-rw-rw-r--. 1 andrea andrea 2807035 16 set 2011 00000000000-1.flv
-rw-rw-r--. 1 andrea andrea 2939698 16 set 2011 00000000000-1.webm
-rw-rw-r--. 1 andrea andrea 2008777 16 set 2011 00000000000-2.flv
-rw-rw-r--. 1 andrea andrea 3173446 16 set 2011 00000000000.flv
-rw-rw-r--. 1 andrea andrea 2347362 16 set 2011 00000000000.mp4
-rw-rw-r--. 1 andrea andrea 3886456 16 set 2011 00000000000.webm

Please add this code on top of sanitize_open():

# do not overwrite existing files
if filename != u'-':
    if filename.endswith(u'.part'):
        _addpart = u'.part'
        _name, _ext = os.path.splitext(filename[:-len(u'.part')])
        filename = filename[:-len(u'.part')]
    else:
        _addpart = u''
        _name, _ext = os.path.splitext(filename)
    _count = 0
    while os.path.isfile(filename):
        _count += 1
        filename = "%s-%s%s" % (_name, _count, _ext)
    filename = "%s%s" % (filename,_addpart)
@andreabravetti
Copy link
Author

@andreabravetti andreabravetti commented May 28, 2012

created as a pull request (#351)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.