python - YoutubeDL - How to get a status object after download has completed -
i'm trying information out of seems status object that's hitting hook in youtube-dl, , i'm trying save db. i've got 'song' object attributes such "filename" i'm trying save once download complete, , maybe continually update database progress.
there's 4 ways can think of i've not been able them work
- send my_hook function db , song object , save in there once status == finished. problem i'm unable pass additional parameters hook unless i'm missing something
- get my_hook function return d , save that, problem don't think can access return (youtube-dl source)
- get ydl.download([song.url]) return status object can process, don't think though
- i don't want this, can output .json file , there, or guess name of file given i'm dictating :(
code looks this:
def my_hook(d): if d['status'] == 'finished': file_tuple = os.path.split(os.path.abspath(d['filename'])) print("done downloading {}".format(file_tuple[1])) if d['status'] == 'downloading': print(d['filename'], d['_percent_str'], d['_eta_str']) class mylogger(object): def debug(self, msg): pass def warning(self, msg): pass def error(self, msg): print(msg) class downloader(object): def get_opts(self): ydl_opts = { 'format': 'bestaudio/best', 'outtmpl': os.path.join(app.config['videos_folder'], '%(id)s.%(ext)s'), 'logger': mylogger(), 'progress_hooks': [my_hook], } return ydl_opts def download(self, song): ydl = youtube_dl.youtubedl(self.get_opts()) ydl.download([song.url])
i got answer here: https://github.com/rg3/youtube-dl/issues/7120
basically 1 many model of song files song requests wrong - rewriting relationship allowed me use hook db updates.
Comments
Post a Comment