Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
YoutubeDL - How to get a status object after download has completed #7120
Comments
|
I don't see any problem with first approach. When download is finished |
|
@dstftw I don't see how to pass the hook the relevant variables it needs in order to update the db or even get the row ID in order to do so. I've tried altering this Not only that, but then the line Can you show an example where I can pass parameters to my_hook? |
|
You don't need to pass them to hook. You should resolve def handle_finished(d):
song = get_song_by_filename(d['filename'])
db = get_db()
db.write(song)
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]))
handle_finished(d)
if d['status'] == 'downloading':
print(d['filename'], d['_percent_str'], d['_eta_str']) |
|
Yes, sorry I absolutely agree that I can create a new |
|
|
I didn't explain that well, the song file is not unique within the "song" table, it's possible for multiple entries in that table to be pointing at the same file. It's actually more like a "song request" that has a "song file" entry but all in one table. Anyway thinking about it from the POV of your comments this may point to problems in the model itself, because of the one to many nature of "song requests" to "song files" I should break it down, this will make the file name unique in the "song file" entry, and I can fetch by youtubeID. Thanks for your help! |
|
Hi Michael, Would you be willing to share your code how to add downloaded descriptions to the database? Did you use MySQL? Thanks |
|
Hi, the database I was using doesn't matter - I was using http://www.sqlalchemy.org/ which would allow me to connect the code to any supported database. It's usually quickest to simply create and connect to a SQLite DB for dev, then test on the target prod type DB, then deploy. Have a read up on how sqlalchemy works, you simply define a model, objects with attributes represent tables and columns, you can then populate that model into a connected DB. The code it out in the open if you want to take a look: |
|
Here's what I used:
Hope that helps |
I'm trying basically to get information out of what seems to be a status object that's hitting the hook in Youtube-DL, and then I'm trying to save it to the db. I've got a 'song' object with attributes such as "filename" I'm trying to save once the download is complete, and maybe even continually update the database with progress.
There's three ways I can think of to do this but I've not been able to get them to work
ydl.download([song.url])to return a status object that I can process, I don't think it does this though