All threads / How do I make an app to get a video by url from youtube download it / process it/ and uploaded to a local db?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I make an app to get a video by url from youtube download it / process it/ and uploaded to a local db?

emil mircea asked in Gems / Libraries

I liked the shrine tutorials and would like to use that as an upload to local disk solution.
I also found a gem called youtube-dl (https://github.com/layer8x/youtube-dl.rb) to help download from Youtube.
I have no clear idea about how to combine the two gems into a solution (user puts in url -> video is being downloaded and uploaded to local db)

Hey Emil,

For the most part, you can just plug in Shrine by opening up a File object in Ruby and then assigning it to the shrine attribute and calling save. That's basically the same process that Shrine uses on a browser upload so there is little to no difference to do this from an already downloaded file.

download = File.open("PATHTOFILE", "rb")
@record = Record.where(youtube_id: ID).first_or_create
@record.video = download
@record.save

You might need to delete the file you downloaded once this is complete so you don't have duplicate files on disk.

Thanks for the answer. I'll give it a try

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 34,885+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.