hasgeek.tv icon indicating copy to clipboard operation
hasgeek.tv copied to clipboard

store iframe details in table

Open kracekumar opened this issue 13 years ago • 11 comments

When a user submits a video url, fetch all the required details and store the iframe related detail like frameborder, allowfullscreen, autoplay etc in a table ...

kracekumar avatar Aug 02 '12 13:08 kracekumar

Don't store frameborder, allowfullscreen, autoplay etc. They are not relevant details since they don't change per video. You only need the embed URL.

jace avatar Aug 02 '12 13:08 jace

E.G:


sqlite> select video_url, video_html from video;
http://www.youtube.com/watch?v=YQO4KwvtH0U&list=PL0ADA13A44BE32F76&index=1&feature=plpp_video|<iframe src="http://www.youtube.com/embed/YQO4KwvtH0U?wmode=transparent&autoplay=1" frameborder="0" allowfullscreen></iframe>
http://www.youtube.com/watch?v=nHinZiR71E8|<iframe src="http://www.youtube.com/embed/nHinZiR71E8?wmode=transparent&autoplay=1" frameborder="0" allowfullscreen></iframe>

Currently we store video_url & video_html in DB, video_id is sufficient to fetch details of video, so we can store only video_id & store youtube url http://www.youtube.com/embed & wmode=transparent&autoplay=1" frameborder="0" in settings.py ?

similarly for thumbnail_url too http://i.ytimg.com/vi/nHinZiR71E8/mqdefault.jpg. Do we need to have height & width ?

kracekumar avatar Aug 02 '12 14:08 kracekumar

Don't store that in settings because the URL will change with the context. For example, in the view page, we'll use autoplay=1, but in the edit page, we won't use it. Add a method Video.embed_for(action='view') that returns the correct iframe code depending on whether the parameter is view or edit.

jace avatar Aug 02 '12 14:08 jace

I had same idea but pull required details from settings.py with helpers.

kracekumar avatar Aug 02 '12 14:08 kracekumar

settings.py is meant for deployment-specific settings. YouTube doesn't change from your laptop to the server. I'm not convinced it should be outside our code.

jace avatar Aug 02 '12 15:08 jace

http://www.youtube.com/watch?v=nHinZiR71E
http://www.youtube.com/watch?v=YQO4KwvtH0U

In the above mentioned URLS only difference is video_id, we would store them in db and in fly we can build view iframe url .



YOUTUBE_SETTINGS = {'url': "http://www.youtube.com/embed", 'mode': "transparent"}

def generate_iframe_url(video_id, purpose='view'):         if purpose is  'edit':
                 c = requests.Request(url=YOUTUBE_SETTINGS['url']%video_id, params={'playback': '0'}, method="GET")
                 return '<iframe src=%s allowborder="0" allowfullscreen></iframe>'%c.full_url
         elif purpose is  'view':
                 c = requests.Request(url=YOUTUBE_SETTINGS['url']%video_id, params={'playback': '1'}, method="GET")
                 return '<iframe src=%s allowborder="0" allowfullscreen></iframe>'%c.full_url
In [41]: generate_iframe_url(3456, purpose='edit')Out[41]: '<iframe src=http://www.youtube.com/embed/3456?playback=0 allowborder="0" allowfullscreen></iframe>'

In [42]: generate_iframe_url(3456, purpose='view')
Out[42]: '<iframe src=http://www.youtube.com/embed/3456?playback=1 allowborder="0" allowfullscreen></iframe>'

agreed with settings.py. Currently in edit mode video is playing automatically, currently i am investigating how to stop it. Found by making playback = 0 will stop autoplay

kracekumar avatar Aug 02 '12 15:08 kracekumar

Remember that we have to support Vimeo, Blip.tv and other providers too, so don't assume just Youtube video id.

jace avatar Aug 02 '12 16:08 jace

Agreed .

kracekumar avatar Aug 02 '12 16:08 kracekumar

Check in changes directly to master. There's no need for branches yet becase this is not in production. Commit early and often, we'll have to iterate rapidy on this.

jace avatar Aug 02 '12 16:08 jace

ok, on quick analysis I feel, we should not store iframe details in separate field. If we store on separate field during view we need to assemble them, which may hinder performance. Only during edit we might need to change the iframe values. So I assume no modification required in iframe part ?

kracekumar avatar Aug 02 '12 17:08 kracekumar

The template is entirely about assembling strings. There's no measurable performance hit from assembling another string. On the other hand, the final iframe code will change over time as we learn new things and as the video hosting website's APIs change. Editing all videos then will be tedious.

Don't waste time thinking too much about all this. Others have thought it out already. :)

jace avatar Aug 02 '12 17:08 jace