Due to some circumstances, it was decided to write a client to work with Smotri.com through the
API provided by them. I must say, a similar topic has already skipped over to the habr (
here ), but it described an application of a slightly different nature.
So, the mandatory requirements for the project - cross-platform and the presence of a relatively user-friendly GUI - imposed some restrictions on languages and platforms. A rather standard bundle was chosen - C ++ and Qt, as familiar and convenient.
The API itself is a collection of XML-RPC or JSON-RPC calls, its description is
here . It consists, in fact, of a set of basic entities (a la video, user, comment, etc.) and a set of commands for working with content. In general, the API is quite convenient, although the publicly available version has some flaws, but this is another story :) Its echoes can be found in the tracker's tickets, the address is slightly higher.
')
Description of the technical part
To work with the API, we chose the option c JSON. Having a little torment, problems with JSON <-> Qt were solved through QScriptValue and writing a small bicycle. The first stage is completed, you can rest :)
Next came the question of writing a very stupid monotonous code for all entities and commands. Of course, an idea was immediately born in my head about a generator tearing up a description from a wiki and issuing a plus code. And of course, she was immediately rejected by the Stimian as not obvious in terms of effort, and the code could have been written by hand, after all. In general, all this is true, but after looking at a bunch of entities and a much larger pile of commands in the evening I felt very sad and it was decided, reluctantly, to write a damn generator. The advantages of the solution are obvious - after writing the basic part, it will be easy to construct the necessary output after writing the wiki format. In general, for a couple of evenings, this utility was written in python, and for about the same amount it began to generate something that almost completely satisfies us and the compiler. In parallel, I learned that my Stimian had written by hand during this time almost everything that my tulza generates: D
In general, after a week and a half, we generated everything to work with the teams and got almost a fully working and quite convenient Qt-style API for working with smotri.com. A little later, unit-tests were written, and we made sure that they all passed.
This part is currently stable and framed as a separate library with approximately the same interface in the main class
SmotriApi (not all commands are shown):
public:
uint videosListConverting (OptionalArgs o = OptionalArgs ());
uint commentsAdd (QString text, SmotriVideoId videoId, OptionalArgs o = OptionalArgs ());
uint commentsDelete (int commentId);
uint videosRubriclist ();
uint authAuthUser (QString login, QString password, OptionalArgs o = OptionalArgs ());
uint testPreved (QString message);
signals:
void videosListConvertingDone (const smotrelka :: SmotriVideosListConvertingReply & reply, uint id);
void commentsAddDone (const smotrelka :: SmotriCommentsAddReply & reply, uint id);
void commentsDeleteDone (const smotrelka :: SmotriCommentsDeleteReply & reply, uint id);
void commentsListDone (const smotrelka :: SmotriCommentsListReply & reply, uint id);
void videosRubricListDone (const smotrelka :: SmotriVideosRubricListReply & reply, uint id);
void authAuthUserDone (const smotrelka :: SmotriAuthAuthUserReply & reply, uint id);
void testPrevedDone (const smotrelka :: SmotriTestPrevedReply & reply, uint id);
Next was written a fitting version of the GUI, which gradually acquired the features to the desired state. Currently it supports the following features:
- getting list of video logs
- getting a list of new videos
- get a list of popular videos
- user authorization
- adding video
- watching video through a browser
- video removal
The main goal - the implementation of video upload - was successfully completed. Video uploading is done via a POST request with a content type multipart / form-data with a single field - the file itself (any format allowed by smotri.com is supported). It should be noted that at the moment the commands for viewing their videos that are in the process of conversion, as well as deleting their videos are not implemented in the publicly available version of the API. As soon as smotri.com hosting updates its version of the API to a fixed one, the specified functionality will work in this application (for now, an error message is displayed).
It should also be noted that the upload does not quite scale well to large files due to the fact that before sending via POST, the contents of the file are completely read into memory (for sequential reading, you must define your QIODevice, which will return HTTP headers when reading it file). Therefore, loading a 200-meter video (the maximum size supported by smotri.com) will require the same amount of memory for the client. This deficiency is planned to be corrected.
The rest of the functionality is implemented in a fairly rough form. For example, a video for viewing is opened via a browser (with the release of Qt 4.5, where QtWebkit supports Flash, this will also be fixed).
About development
This open-source project (GPL). The code is available through the
SVN repository , there is also a wiki and a bug tracker at
this address, where you can read the documentation, download the latest version of tarballs or ready-made assemblies.
If someone wants to join the development, create a ticket in the tracker indicating
twee in the
Cc: field and indicating your contact information, agree.