hasgeek.tv
hasgeek.tv copied to clipboard
store iframe details in table
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 ...
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.
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 ?
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.
I had same idea but pull required details from settings.py with helpers.
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.
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
Remember that we have to support Vimeo, Blip.tv and other providers too, so don't assume just Youtube video id.
Agreed .
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.
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 ?
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. :)