ncutils

niconico douga module


License
BSD-3-Clause
Install
pip install ncutils==0.3.0

Documentation

ncutils

A python module for niconico douga.

Ncutils are developed at github and distributed at PyPI

WARN As of today(2015) ncutils.Search doesnot work caz niconico spec changed.

Concepts

Easy to deploy
You can install via pip. It's a pure python module without any required modules.
Easy to use
APIs are extremely simple. Any niconico douca API call is encapsulated.
Ruduced consumption of N/W resources:
Almost all of properites are evaluated lazily. And there exists a flow control mechanism of niconico douga API calls.
Easy to inspect
Syslog handles logging(default).

Overview

ncutils provides a few important functions and classes.

ncutils.login(username,password)
You can login to niconico via this function. It returns True when it is successful. Login to niconico is equivalent to retrieving a session-cookie. ncutils realizes this by registering cookie-handlable opener to urllib2 module.
ncutils.Video(smid)
All video has its unique ID matching ^[sn]m\d+$. You can see that by its watch URL. For example, sm9 is a famous Onmoji video. ncutils.Video has to be instanciated with this ID. Once instanciated, you can access varieties of attributes such as title, comment_num, and so on. These attributes originally needs API call to niconico, but you need not care about it, because this attribute accessor internally calls them. This class has some method to add_comment() and download(). For more details, see pydoc ncutils.Video.
ncutils.Mylist(mid)
There exists two types of mylist. One is public mylist by other users, and the other is mylist owned by me. Naturally the former is readonly, and the latter is controllable. This class handles both types of mylist. Every mylist has its unique ID matching ^\d+$. This ID is required to instantiated except when creating a brand new mylist (in this case, ID is set to None, and later mylist.mid will be filled). You can access attribute without caring anything, niconico API will be called internally. You can retrieve videos in one mylist, add_video, and truncate mylist, and so on. For more details, see pydoc ncutils.Mylist.
ncutils.Search(word, mode='tag')
niconico provides search API. We have two methods for searching video, one is keywordsearch, and the other is tagsearch. This class handles both by passing ''mode'' keword when instantiated. If you need more than 32 videoes, max_pages keyword is required. For more details, see pydoc ncutils.Search.
ncutils.Watch()
niconico provides fav API, which enables us to register favorite users, public mylists, and tags. This object handles those things. For more details, see pydoc.

Install

pip install ncutils

Examples

Followings are typical examples. See also wiki and testcases

Download sm9

This script will download sm9:

import ncutils
ncutils.login("username@example.net", "mypassword") #returns True if success.
video = ncutils.Video("sm9")
print "start downloading %s" % (video.title, )
video.download()

Create a new mylist

This script will create a brand new mylist titled 'test' and add sm9.:

import ncutils
ncutils.login("username@example.net", "mypassword")
mylist = ncutils.Mylist(None)
mylist.create("test")
mylist.add_video(ncutils.Video("sm9"))

LICENSE

ncutils are distributed under (2-clause) BSD license. For more detail, see LICENSE.txt.

Thanks

This project is owe to the following references.