How should I start this Ruby on Rails app? - ruby-on-rails

I want to create an app in Ruby on Rails that when a user pastes the link of a video, the thumbnail is embedded, and when the user clicks the thumbnail, the video is embedded with ajax. How should I start developing this functionality? I plan on using Embedly. My first question is how do I use it? I've read the documentation, but there are a bunch of different tutorials and I'm not sure which one to use. And specifically how do I get the thumbnail and the video? Also, should I have a separate model for both the thumbnail and the video? Or should the thumbnail be a field in the video table? What should I be storing in my database?
I would really, really appreciate any help.

Embed.ly API gives you a pretty wide range of options. Thumbnail is also included in the return hash. All you need to do is capture the url your users paste, plug it into this API url, and parse the returned hash for the thumbnail image.
You can then easily use the jQuery plugin to generate the embed link when the user clicks on the thumbnail.
$.embedly('http://www.youtube.com/watch?v=LfamTmY5REw',
{maxWidth: 600,
elems: $('#element'),
success: function(oembed, dict){
alert(oembed.title);
});
Note that in this function elems property is where you want your video to be embedded. oembed parameter contains the hash, which includes the thumbnail image link. So you can do everything in this one call. Embed the video as soon as the user pastes the link, and simply hide the embedded video until the user interacts with the thumbnail image.
You should probably save the thumbnail url as a field of the same model as everything else.

Related

For YouTube video, how to automatically display interactive transcript?

YouTube supports interactive-transcripts, using both machine-generated and user-uploaded transcripts. This is very useful for hearings, lectures, speeches, and educational videos where a visitor might want to read along or jump around. For example in this video:
https://www.youtube.com/watch?v=IY3U2GXhz44
The visitor can click on "...More" and then "Transcript" to view the interactive-transcript.
How does a video owner make that hidden feature automatically open for visitors? I cannot find any documented method for doing that through the API for either embed or linked videos. Is there an undocumented method in the API, or a URL parameter like "&action-panel-transcript=true" that works the way I'd expect it to?
As for url parameter, you can try adding &cc_load_policy=1 behind the rel=0 if it's an embedded video or &yt:cc=on at the end of the url if it's a link to the video.
Source: https://www.makeuseof.com/tag/force-subtitles-embedded-youtube-video/

Rails: upload a file OR store a url

I'm developing a form where I want to allow users to either upload a file, or enter a url to an existing file.
The idea is to allow users to attach various 'multimedia' files to entries, some of which may be files from their hard drives (think images, word documents, etc) and some may be urls (youtube videos, images on flickr, etc)
Any ideas on how I can accomplish this? I'm currently using carrierwave to handle file uploads, and it seems to work well, but I want to store url's as well.
What I will probably do is to have a drop down in the file upload form to select if the file is from the disk or from external url.
By default it will set to "from disk", and if they select external url, you could use some AJAX magic and hide the file upload text box and have a text box to use the external url/script etc..
in the table, you can keep another two columns,
1 - external url
2 - file category (external / uploaded file)
by that way you can distinguish the files and how they what to display in the view
HTH
Don't save the url unless you really have too. The thing is that when you save a url, you can't process it to create a thumbnail or multiple styles of the image. Also, when you display the images in a page you will have to make external calls and that can slow down the page or even worse, if the link breaks sometime in the future your users will see an empty image.
Which is also the case with youtube videos. However, with videos you typically want to store and display more information than just the video. You can have two tables - one for videos and one for images. In the video table you have title, desc, author, duration, embed code, thumbnail (image attachment).
You can download any image when a URL is given and save it like a normal file.
Using carrierwave -
#object.remote_image_url = "http://www.foo.com/file.png"
#object.save
In the view, you would have both options, perhaps side by side and you can let them post to different actions. So if a file is selected and posted you save it normally. If a url is entered, then you can check if it's a video site or not - if video, parse out the info using the video_info gem and store it. Otherwise just use the two lines above and save the url image.
Note
My answer doesn't discuss the quality / nature of user inputs. The likely-hood of someone entering an incorrect url is high in my opinion, so you want to wrap attempts to save the url as an image in a begin-rescue block and perhaps using JS limit the video domains to just a few websites which you will be able to parse.

How to allow users to embed YouTube & Vimeo videos?

How can I go about allowing users to embed YouTube and Vimeo videos in my Rails app?
I'd provide a text field or text area where users can add the link of the video they wish to embed.
Click add and have my app show a spinner while the details are being gathered.
When the details are found, I'd want them displayed on the page before user can finally submit the post.
I'm guessing the HTML, link details will need to be stored in the database so the video can automatically be displayed every time the page is visited.
HTML5 has a file API that gives me the ability to display users local file data on the fly. Wondering if there is something similar for display remote data or would normal ajax be used?
Is there a standard way of doing this? Also are there any tutorials out there on how to do this in rails? Would like to go about doing this in the most safest and securest way.
I love tutorials and screencasts so I'd really be thankful for info on where I can find one to achieve what I'm trying to achieve.
Try to use open graph protocol to fetch site information before user sending the form.
I suggest the following gem:
https://github.com/intridea/opengraph
Open graph protocol:
http://ogp.me/
And I guess you should store all the fetched information in database.
The Video Thumb gem is probably what you are looking for.
It handles vimeo, youtube and potentially others.
Then you just do:
<%= VideoPlayer::player(library_item.url, 700, 420).html_safe %>
In your view to display an automatically generated embed code.

How to read the first few lines of a website

I am trying to implement a feature to your web application, in which if a user saves a website's url, it is stored and displayed in the library. Now when a web url is saved in facebook, the first few lines of the webpage is also displayed. I also want to implement a similar feature.
I am using Ruby on Rails. I tried using the .load() method of jquery, but using that I am only able to retrieve description of pages which are in the application. I want to save a url in my app, eg, "api.jquery.com/load/";, and while displaying the list of urls, I want to display a description of the page, like its shown in facebook when you enter a url in the status update
Any suggestions on how to do it?

User Video Embedding in Rails 3

I am building an app using Rails 3 that allows users to submit videos. I would like to be able to accept simply the video URL from the user and using this, my app will generate the appropriate embed code (depending on the video source). Is there a good library for something like this that already exists? I'd rather not have to reinvent the wheel here and write my own regex/scripts to embed the videos if something already exists.
Think of how tumblr works...you just paste in the url of the video and it embeds it all automatically.
Thanks!
I would look into the embedly api it may be able to address your problem.

Resources