5 1. Before you get started
6 -------------------------
8 *) quvi exists primarily for the following reasons
9 - Adobe Flash poorly is supported on non-mswindows systems
10 - It hogs system resources, exposes system to vulnerabilities
12 *) We do not include websites to quvi that
13 - Allow downloading already
14 - Use the RTMP protocol (at this time)
16 *) If you are proposing a change to the library API
17 - Consider this carefully, we try to keep API changes minimal
24 Work with the development code
26 Grab the code from <git://repo.or.cz/quvi.git>. The web interface can be
27 found at <http://repo.or.cz/w/quvi.git>.
31 Although not required, this is certainly recommended. The examples below
32 demonstrate this. Be sure to name and email in your ~/.gitconfig:
40 Setting this variable may prove helpful if for some reason libquvi does
41 not appear to find your lua scripts. For example:
43 env QUVI_SHOW_SCANDIR=1 quvi
49 quvi uses Lua scripts to parse the video details. You can find the
50 current scripts from $prefix/share/quvi directory. Compare buzzhumor.lua
51 and youtube.lua scripts to see how different these scripts can be.
53 As far as the website Lua scripts go, they are by far the most
54 frequently changing part of the project. Although ideally you would work
55 with the current development source code, you could just as well work
56 with precompiled quvi binaries.
58 The scripts are dynamically loaded when you fire up quvi. You can even
59 drop new scripts in the path -- or remove and fix old ones without ever
66 Any flash based website will typically do. Remember, we are trying to
67 circumvent the need to use Adobe Flash altogether.
69 How difficult this turns out to be, depends on how the website was
70 designed. You can get a better understanding by looking over some of
71 the existing scripts and then looking for similar "fingerprints" in your
74 If you are willing to walk an extra mile, find yourself a system that can
75 execute flash object code (e.g. has the Adobe Flash plugin installed)
76 and capture the HTTP traffic. You may be able to figure out how the URLs
77 being constructed by analyzing the captured data. Note that this may not
78 always be even necessary as some websites often simply list the video
79 download URL within the HTML.
81 The (download) URL extraction, whether it is simply copied from the HTML or
82 put together from different chunks of data is the most time consuming
83 part of writing your script. Video IDs and titles are typically always
84 available and can be grabbed from the HTML with little effort.
87 2.2. Dissecting a website script
88 --------------------------------
90 We'll use git and the development code in this example. See 2.3. below,
91 if you choose not to work with the quvi source code but precompiled quvi
94 Let's assume you have figured out how to parse the video details (download
95 URL, video ID, video title), it's time to cook up a script. We'll go
98 Grab the development code from the repo.
100 git clone git://repo.or.cz/quvi.git
102 Use an existing script as a template. buzzhumor.lua will do fine. We'll
103 use 'foo.lua' for our script's file name for brewity. You should choose
104 a name that matches the website.
106 cd quvi ; mkdir tmp ; cd tmp
107 cp ../share/lua/website/buzzhumor ../share/lua/website/foo.lua
110 Open the foo.lua file in your favorite editor, e.g.:
112 vim ../share/lua/website/foo.lua
114 Start by changing the details in the `ident' function, e.g.:
116 - t.domain = 'buzzhumor.com"
117 + t.domain = 'foo.bar'
119 You can leave t.formats untouched, unless you know that the website
120 supports more than one video format -- and you know how to get to those.
121 See youtube.lua, dailymotion.lua and vimeo.lua for examples of this.
123 Next there is the `parse' function. This is where the magic happens.
124 This function is responsible for parsing all of the video details (e.g.
125 title, ID, download URL and host ID).
127 - video.host_id = 'buzzhumor'
128 + video.host_id = 'foo'
130 Let's assume that our website "foo" resembles buzzhumor so that all that
131 we must do is to fetch a video page from the user specified URL and
132 parse the video details from the HTML.
134 local page = quvi.fetch (video.page_url)
136 The above fetches the page from the URL (video.page_url) and stores the
137 contents to a local variable `page'. We go over the page HTML and notice
138 that the video title can be parsed from <title>.
140 local _,_,s = page:find('<title>(.-)</title>')
141 video.title = s or error ('no match: video title')
143 We have now parsed the title and stored it to the `video' table. Next,
144 the video ID. Next, the video ID. This is usually an unique string of
145 characters. For example:
147 local _,_,s = page:find ('vid_id="(.-)"')
148 video.id = s or error ('no match: video id')
150 This leaves only the video download URL. This could be as simple as an
151 URL to an flv file on the server. For example:
153 local _,_,s = page:find('vid_url="(.-)"')
154 video.url = {s or error ('no match: video url')}
156 Note that we store the parsed URL to video.url table ({}). If there were
157 more than one download URL, we could append them to that table. At the
158 time of writing this, none of the current scripts provide multiple URLs.
160 All that remains is to return the updated `video' result table that
161 contains the parsed details.
163 To test your new script, make sure you set QUVI_BASEDIR, e.g.:
165 (assuming we're still in $top_srcdir/tmp directory)
166 env QUVI_BASEDIR=../share ./src/quvi TEST_URL
168 Tweak the script if needed, e.g. parsing fails or some of the regexps do
169 not return the expected values. Edit and re-run quvi as described above
170 until you're happy with the script.
172 It's time to create the patch. Here's one way to do it:
174 (still in the $top_srcdir/tmp)
175 git add ../share/lua/website/foo.lua
176 git commit -am 'add foo support'
177 git format-patch -M -1
179 And submit the patch to the upstream, see
180 $prefix/doc/quvi/HowtoSubmitPatches.
183 2.3. Dissecting a website script using precompiled quvi binaries
184 ----------------------------------------------------------------
186 We'll use git in this example also so get used to it. git uber alles.
187 We're not going to get into the gory details of writing a script
188 (read 2.2. above) but go over how you can work with only the quvi
189 binaries on your system.
191 Make sure you have quvi binaries installed to your path.
193 mkdir -p foo/quvi/lua/website ; cd foo
194 cp $prefix/share/quvi/lua/website/buzzhumor.lua lua/website/foo.lua
195 git init ; git add . ; git commit -am 'initial commit'
197 * Edit lua/website/foo.lua (as we did in 2.2. above)
198 * Run "quvi TEST_URL", you can skip setting QUVI_BASEDIR
199 * Repeat above two steps until happy with the results
201 git commit -am 'add foo support'
202 git format-patch -M -1
204 And submit the patch to the upstream, see
205 $prefix/doc/quvi/HowtoSubmitPatches.
211 Consider writing a test for your website script. Or at very least when
212 you submit your website script, add a test URL that we can work with
213 when we write a test for your script.
215 You can find the current tests from $top_srcdir/tests/ directory.
216 Note that these support-*.pl scripts depend on the test URLs hardcoded
217 into the quvi program ($top_srcdir/src/quvi.c).
223 If you are going to contribute a new file (e.g. a website script),
224 please add your copyright to it including your full name and an email
225 address from which we can reach you. We may need to contact you later.
227 Otherwise we'll apply the default one:
228 Copyright (C) (year) quvi team <http://quvi.googlecode.com/>
231 5. Before you submit your website script
232 ----------------------------------------
234 * Does your script parse everything correctly?
240 * Does the website support more than one video format?
241 - If yes, see if you can add support for them
242 - We can, of course, add the support later
244 * Does the parsed video title contain extra characters?
245 - We want the video title *only*
246 - Anything else, e.g. domain name, should be left out
247 - If you are unsure, don't hesitate to ask
249 * Check the copyright (if you are submitting a new file)
250 - See also "4. Copyright" above