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:
38 Make libquvi more verbose
40 libquvi currently supports the following environment settings that may
41 be used to amp up the verbosity of the library. This may be useful if
42 you find that the library is not picking up your scripts from the path.
45 env QUVI_SHOW_SCANDIR=1 quvi
46 env QUVI_SHOW_SCRIPT=1 quvi
48 The former causes the library to dump the Lua script search dirs to the
49 stderr. The latter is similar but prints the found Lua scripts (with full
50 paths to them) to stderr.
52 You may also want to use the --verbose-libcurl with quvi(1), this helps
53 debugging the HTTP traffic generated by the libcurl.
59 quvi uses Lua scripts to parse the video details. You can find the
60 current scripts from $prefix/share/quvi directory. Compare buzzhumor.lua
61 and youtube.lua scripts to see how different these scripts can be.
63 As far as the website Lua scripts go, they are by far the most
64 frequently changing part of the project. Although ideally you would work
65 with the current development source code, you could just as well work
66 with precompiled quvi binaries.
68 The scripts are dynamically loaded when you fire up quvi. You can even
69 drop new scripts in the path -- or remove and fix old ones without ever
76 Any flash based website will typically do. Remember, we are trying to
77 circumvent the need to use Adobe Flash altogether.
79 How difficult this turns out to be, depends on how the website was
80 designed. You can get a better understanding by looking over some of
81 the existing scripts and then looking for similar "fingerprints" in your
84 If you are willing to walk an extra mile, find yourself a system that can
85 execute flash object code (e.g. has the Adobe Flash plugin installed)
86 and capture the HTTP traffic. You may be able to figure out how the URLs
87 being constructed by analyzing the captured data. Note that this may not
88 always be even necessary as some websites often simply list the video
89 download URL within the HTML.
91 The (download) URL extraction, whether it is simply copied from the HTML or
92 put together from different chunks of data is the most time consuming
93 part of writing your script. Video IDs and titles are typically always
94 available and can be grabbed from the HTML with little effort.
97 2.2. Dissecting a website script
98 --------------------------------
100 We'll use git and the development code in this example. See 2.3. below,
101 if you choose not to work with the quvi source code but precompiled quvi
104 Let's assume you have figured out how to parse the video details (download
105 URL, video ID, video title), it's time to cook up a script. We'll go
106 over the steps below.
108 Grab the development code from the repo.
110 git clone git://repo.or.cz/quvi.git
112 Use an existing script as a template. buzzhumor.lua will do fine. We'll
113 use 'foo.lua' for our script's file name for brewity. You should choose
114 a name that matches the website.
116 cd quvi ; mkdir tmp ; cd tmp
117 cp ../share/lua/website/buzzhumor ../share/lua/website/foo.lua
120 Open the foo.lua file in your favorite editor, e.g.:
122 vim ../share/lua/website/foo.lua
124 Start by changing the details in the `ident' function, e.g.:
126 - t.domain = 'buzzhumor.com"
127 + t.domain = 'foo.bar'
129 You can leave t.formats untouched, unless you know that the website
130 supports more than one video format -- and you know how to get to those.
131 See youtube.lua, dailymotion.lua and vimeo.lua for examples of this.
133 Next there is the `parse' function. This is where the magic happens.
134 This function is responsible for parsing all of the video details (e.g.
135 title, ID, download URL and host ID).
137 - video.host_id = 'buzzhumor'
138 + video.host_id = 'foo'
140 Let's assume that our website "foo" resembles buzzhumor so that all that
141 we must do is to fetch a video page from the user specified URL and
142 parse the video details from the HTML.
144 local page = quvi.fetch (video.page_url)
146 The above fetches the page from the URL (video.page_url) and stores the
147 contents to a local variable `page'. We go over the page HTML and notice
148 that the video title can be parsed from <title>.
150 local _,_,s = page:find('<title>(.-)</title>')
151 video.title = s or error ('no match: video title')
153 We have now parsed the title and stored it to the `video' table. Next,
154 the video ID. Next, the video ID. This is usually an unique string of
155 characters. For example:
157 local _,_,s = page:find ('vid_id="(.-)"')
158 video.id = s or error ('no match: video id')
160 This leaves only the video download URL. This could be as simple as an
161 URL to an flv file on the server. For example:
163 local _,_,s = page:find('vid_url="(.-)"')
164 video.url = {s or error ('no match: video url')}
166 Note that we store the parsed URL to video.url table ({}). If there were
167 more than one download URL, we could append them to that table. At the
168 time of writing this, none of the current scripts provide multiple URLs.
170 All that remains is to return the updated `video' result table that
171 contains the parsed details.
173 To test your new script, make sure you set QUVI_BASEDIR, e.g.:
175 (assuming we're still in $top_srcdir/tmp directory)
176 env QUVI_BASEDIR=../share ./src/quvi TEST_URL
178 Tweak the script if needed, e.g. parsing fails or some of the regexps do
179 not return the expected values. Edit and re-run quvi as described above
180 until you're happy with the script.
182 It's time to create the patch. Here's one way to do it:
184 (still in the $top_srcdir/tmp)
185 git add ../share/lua/website/foo.lua
186 git commit -am 'add foo support'
187 git format-patch -M -1
189 And submit the patch to the upstream, see
190 $prefix/doc/quvi/HowtoSubmitPatches.
193 2.3. Dissecting a website script using precompiled quvi binaries
194 ----------------------------------------------------------------
196 We'll use git in this example also so get used to it. git uber alles.
197 We're not going to get into the gory details of writing a script
198 (read 2.2. above) but go over how you can work with only the quvi
199 binaries on your system.
201 Make sure you have quvi binaries installed to your path.
203 mkdir -p foo/lua/website ; cd foo
204 cp $prefix/share/quvi/lua/website/buzzhumor.lua lua/website/foo.lua
205 git init ; git add . ; git commit -am 'initial commit'
207 * Edit lua/website/foo.lua (as we did in 2.2. above)
208 * Run "quvi TEST_URL", you can skip setting QUVI_BASEDIR
209 * Repeat above two steps until happy with the results
211 git commit -am 'add foo support'
212 git format-patch -M -1
214 And submit the patch to the upstream, see
215 $prefix/doc/quvi/HowtoSubmitPatches.
221 Consider writing a test for your website script. Or at very least when
222 you submit your website script, add a test URL that we can work with
223 when we write a test for your script.
225 You can find the current tests from $top_srcdir/tests/ directory.
226 Note that these support-*.pl scripts depend on the test URLs hardcoded
227 into the quvi program ($top_srcdir/src/quvi.c).
233 If you are going to contribute a new file (e.g. a website script),
234 please add your copyright to it including your full name and an email
235 address from which we can reach you. We may need to contact you later.
237 Otherwise we'll apply the default one:
238 Copyright (C) (year) quvi team <http://quvi.sourceforge.net/>
241 5. Before you submit your website script
242 ----------------------------------------
244 * Does your script parse everything correctly?
250 * Does the website support more than one video format?
251 - If yes, see if you can add support for them
252 - We can, of course, add the support later
254 * Does the parsed video title contain extra characters?
255 - We want the video title *only*
256 - Anything else, e.g. domain name, should be left out
257 - If you are unsure, don't hesitate to ask
259 * Check the copyright (if you are submitting a new file)
260 - See also "4. Copyright" above