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

Re-downloading of a song #10420

Closed
kunal394 opened this issue Aug 23, 2016 · 3 comments
Closed

Re-downloading of a song #10420

kunal394 opened this issue Aug 23, 2016 · 3 comments

Comments

@kunal394
Copy link

@kunal394 kunal394 commented Aug 23, 2016

  • I've verified and I assure that I'm running youtube-dl 2016.08.22

What is the purpose of your issue?

  • Probable Bug report (encountered problems with youtube-dl)
  • Probable Feature request (request for a new functionality)
  • Question

Hi,

I have a couple of doubts which might be a bug request or a feature request or simply another stupid question:

  1. What is the default behavior of youtube-dl if I try to download the same file downloaded before in the same location assuming that the previously the file was not renamed either. In other words, if I try to download a file I downloaded before using youtube-dl then will it re download the file or will state that the file has already been downloaded? Because using the script given below when I try to simulate the above condition it re-downloads the song and then replaces the original file.
  2. When I download a song from youtube using the script given below, I can see the cover art of a song when it is playing in vlc but not in the ubuntu file browser. So, am I missing something in my code? Or is it something else? Please clarify.

Code:

#!/usr/bin/env python

from __future__ import unicode_literals
import youtube_dl, sys, argparse

common_settings = {
        'continue': True,
        'fixup': 'detect_or_warn',  # Automatically correct known faults of the file.
        'ignoreerrors' : True,
        'outtmpl': '%(title)s.%(ext)s',     # name the file the title of the video
        'verbose': True,
        'writethumbnail': True,
        }

def contruct_flac():
    #TODO:debug flac!! something's wrong!!!!
    flac = {
        'extractaudio' : True,      # only keep the audio
        'format': 'bestaudio/best', # choice of quality
        'noplaylist' : True,        # only download single song, not playlist
        }
    postprocessors = [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'flac',
        }]
    return flac, postprocessors

def contruct_mp3():
    mp3 = {
        #'audioformat' : "mp3",      # convert to mp3 
        'extractaudio' : True,      # only keep the audio
        'format': 'bestaudio/best', # choice of quality
        'noplaylist' : True,        # only download single song, not playlist
        }
    postprocessors = [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '320',
        }]
    return mp3, postprocessors

def contruct_mp3_playlist():
    mp3_playlist = {
        #'audioformat' : "mp3",      # convert to mp3 
        'extractaudio' : True,      # only keep the audio
        'format': 'bestaudio/best', # choice of quality
        'noplaylist' : False,        # only download single song, not playlist
        }
    postprocessors = [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '320',
        }]
    return mp3_playlist, postprocessors

def contruct_mp4():
    mp4 = {
        #'extractaudio' : True,      # only keep the audio
        'format': 'bestvideo+bestaudio/bestvideo[ext=mp4]+bestaudio/bestvideo[ext=mkv]+bestaudio/best', # choice of quality
        'noplaylist' : True,        # only download single song, not playlist
        'videoformat' : "mp4",      # convert to mp4
        }
    return mp4

def contruct_mp4_playlist():
    mp4_playlist = {
        'format': 'bestvideo+bestaudio/bestvideo[ext=mp4]+bestaudio/bestvideo[ext=mkv]+bestaudio/best', # choice of quality
        'noplaylist' : False,        # only download single song, not playlist
        'videoformat' : "mp4",     # convert to mp4 
        }
    return mp4_playlist

def download(args):
    global common_settings
    postprocessors = []

    if args['type'] == 'flac':
        options, p = contruct_flac()
    elif args['type'] == 'mp3':
        options, p = contruct_mp3()
    elif args['type'] == 'mp3p':
        options, p = contruct_mp3_playlist()
    elif args['type'] == 'mp4':
        options = contruct_mp4()
        p = []
    elif args['type'] == 'mp4p':
        options = contruct_mp4_playlist()
        p = []

    postprocessors.extend(p)
    postprocessors.append({
            'key': 'EmbedThumbnail',
            })
    options.update({'postprocessors' : postprocessors})

    if args['type'].endswith('p'):
        try:
            options.update({'playliststart': int(args['play_start'])})
        except:
            pass
        try:
            options.update({'playlistend': int(args['play_end'])})
        except:
            pass

    options.update(common_settings)


    print options
    ydl = youtube_dl.YoutubeDL(options)
    r = ydl.extract_info(args['url'])

if __name__ == "__main__":
    arg_names = ['command', 'type', 'url', 'play_start', 'play_end']
    args = dict(zip(arg_names, sys.argv))
    download(args)
@dstftw
Copy link
Collaborator

@dstftw dstftw commented Aug 23, 2016

  1. If the file to be downloaded has exactly the same name as one in filesystem it won't be redownloaded by default. In your script you don't store the original file but converted mp3 thus filenames does not match therefore the file is redownloaded and reconverted.
  2. Ask ubuntu file browser support.
@dstftw dstftw closed this Aug 23, 2016
@kunal394
Copy link
Author

@kunal394 kunal394 commented Aug 24, 2016

@dstftw As you mentioned, the file is being re-downloaded because I am downloading in a different final file extension. So I coded a method to check if a file exists in cases of mp3 and mp4, but I can't figure out how to do that with mp3playlist or mp4 playlist. So, can you please suggest some way to do that without touching the youtube-dl's code base. You can see my code here: ytdl-automater

One way I can think of is by extracting the info of the complete playlist without actually downloading it and then iterate over every entry one by one checking if it already exists, but that would waste a lot of time.

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Aug 24, 2016

Use --download-archive.

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
2 participants
You can’t perform that action at this time.