There was a desire in one of the projects to use the video provided by video hosting sites. The choice fell on youtube and smotri.com. I will not write much about youtube, so much has been written about them =) Besides, there are ready-made implementations.
The original source was a site describing the use of the API -
http://api.smotri.com/ . References to written classes (in source and collected) below. In the meantime, a small description of the process and impressions.
It all started with the fact that, like many others, to work with the API you need to get a key. But, unlike many others, it is not generated automatically, but you need to write a letter to the support service. Since it was happening on Friday evening, then writing a letter, I realized that I would most likely have to wait until Monday. So I decided to study the documentation for now.
')
Documentation
The documentation as a whole seems to be clear and to the point, but the details indicated that the pieces were copied without proofreading. For example, the method "
smotri.videos.list.converting ". The name suggests a list of user clips in the process of conversion. The description with my thoughts did not agree and said that "The team returns a list of all the videos of the specified user." The parameters, it seems, had their own opinion about the personal purpose, otherwise how to explain the parameter “the necessary number of similar ones, from 1 to 100”. I registered and subscribed to Trac to keep abreast of new errors and their fixes, at the same time I wrote a few comments on the documentation. For the time remaining until Monday, he sketched out the skeleton of the future implementation, relying on understandable parts of the documentation and common sense. Mostly in the documentation there were loud phrases about what can be done with the help of the API. See your own duplicate see. Com, although the information provided was clearly not enough. But some of the missing teams were able to fill up with common sense, and some are not enough, it may appear in the future.
Hooray! Key!
On Monday, I received a letter from the support service asking me to describe why I needed the key and what I was going to develop. After my answer, I soon received a developer ID and password, with a proposal to register with trac to get prompt answers from developers. The letters are clearly formulaic, but they are well written, pleasant to read =) The impressions of the correspondence are positive.
The key is, you can start the first tests. I wanted to see a page where you can drive in parameters and look at the result of the method call, but there was no such one. Therefore, I made an html file on the disk that the AJAX sent a request and showed the result. However, given the fact that between domains AJAX browsers should block requests, I had to test in IE6, which does not bother about this. As a result, this page helped me catch a few errors. It would be nice to see such a page on the api site.
Then I wrote the code, read the documentation, scolded myself for stupid mistakes and the site for incomplete and / or incorrect information.
What happened
It turned out a set of classes that allow you to work with video in approximately the following style:
//
SmotriComService service = new SmotriComService(devId, devPassword);
//
//
AuthService auth = service.getAuthService();
auth.startSession();
auth.authUser(userLogin, userPassword);
//
VideoService video = service.getVideoService();
//
List <Rubric> rubrics = video.getRubricList();
//
VideoSearchResults res = video.getTopVideoList(rubrics. get (0));
// ,
System. out .println( ": " + rubrics. get (0).getName());
// , =)
System. out .println( ":" +res.getVideos(). get (0).getTitle());
System. out .println( "URL:" +res.getVideos(). get (0).getUrl());
// ,
CommentsService comment = service.getCommentsService();
comment.addComment( "!" , res.getVideos(). get (0).getVideoId());
// =)
* This source code was highlighted with Source Code Highlighter .
Of the flaws
- The smotri.videos.list.converting method is not implemented. I could not figure it out =)
- Do not implement the smotri.broadcast.rubric.list method, because without other commands to work with broadcasts, in my opinion it makes no sense
- Comments in the source are almost absent
- Tests are not written for all methods, therefore errors are possible (if anything - write, I will correct)
- Getting top video can throw an exception when a video with a long description is encountered. Here I am powerless, because problems by smotri. In the trac a week ago it was written that this error was fixed, but the new version was not posted on the server.
- Some things are not done in the most convenient way. If the topic finds support, I will refine, write documentation and implement support for new versions.
Files
Sources (
Rapid Mirror, Yandex Disk Mirror ),
compiled version (
Rapid Mirror, Yandex Disk Mirror ).
Dependencies:
log4j ,
HttpClientWork demo source. In the demo insert your ID and password.