ndrive manual

Introduction

ndrive is a python library that can provide an access to Naver Ndrive. This is not an official Ndrive python API, so some features may not be implemented, yet.

>>> from ndrive import Ndrive
>>> nd = Ndrive()
>>> nd.login("YOUR_ID","YOUR_PASSWORD")
>>> nd.uploadFile("test.txt",'/test.txt',True)

Key Features

  • Download and upload a file
  • Get file and directory list of Ndrive directories
  • Make a url share link for a specific directory or file
  • Search Ndrive file and directory
  • Get properties of file and directory

Installation

This package is available in PyPI. To install it in your system, use easy_install:

$ easy_install ndrive

Or use pip:

$ pip install ndrive

Or check out developement version:

$ git clone git://github.com/carpedm20/ndrive.git

Quick Start

If you want to start with Ndrive module, you need to login to Ndrive first. Just make a Ndrive object and use login method.

Login:

nd = Ndrive()
nd.login("YOUR_ID","YOUR_PASSWORD")

Then you might want to download a file from your Ndrive, but you might don’t know exact filename in Ndrive directory. Then, you can use getList method to get list of files and directory of given directory.

Don’t forget to put / in front of the Ndrive path, which indicate root directory of Ndrive

Get file and directory List:

nd_list = nd.getList('/', type=3)
print nd_list

If you find a file, then you can download the file to your local directory.

Download:

nd.download('/Picture/flower.png', './flower.png')

Or you can upload a file:

nd.puloadFile('./flower.png','/Picture/flower.png')

You can make a test directory at root directory:

nd.makeDirectory('/test')

and move a file from root to a created test directory:

nd.doMove('/flower.png','/test/flower.png')

API documentation

This is the information of class and method of ndrive.

class ndrive.Ndrive(debug=False, NID_AUT=None, NID_SES=None)

Initialize NdriveClient instance.

Using given user information, login to ndrive server and create a session

Parameters:
  • debug (bool) – (optional) print all metadata of http requests
  • NID_AUT (str) – (optional) Naver account authentication info
  • NID_SES (str) – (optional) Naver account session info

Usage:

>>> from ndrive import Ndrive
>>> nd = Ndrive()
GET(func, data)

Send GET request to execute Ndrive API

Parameters:
  • func – The function name you want to execute in Ndrive API.
  • params – Parameter data for HTTP request.
Returns:

metadata when success or False when failed

POST(func, data)

Send POST request to execute Ndrive API

Parameters:
  • func – The function name you want to execute in Ndrive API.
  • params – Parameter data for HTTP request.
Returns:

metadata when success or False when failed

checkStatus()

Check status

Check whether it is possible to access Ndrive or not.

Returns:True when success or False when failed.
checkUpload(file_obj, full_path='/', overwrite=False)

Check whether it is possible to upload a file.

>>> s = nd.checkUpload('~/flower.png','/Picture/flower.png')
Parameters:
  • file_obj – A file-like object to check whether possible to upload. You can pass a string as a file_obj or a real file object.
  • full_path (str) – The full path to upload the file to, including the file name. If the destination directory does not yet exist, it will be created.
  • overwrite – Whether to overwrite an existing file at the given path. (Default False.)
Returns:

True if possible to upload or False if impossible to upload.

Make a link of file

If you don’t know resourceno, you’d better use getFileLink.

Parameters:resourceno – Resource number of a file to create link
Returns:Shared url or False when failed to share a file
delete(full_path)

Delete a file in full_path

>>> nd.delete('/Picture/flower.png')
Parameters:full_path – The full path to delete the file to, including the file name.
Returns:True if success to delete the file or False
doMove(from_path, to_path, overwrite=False, bShareFireCopy='false', dummy=56147)

Move a file.

>>> nd.doMove('/Picture/flower.png', '/flower.png')
Parameters:
  • from_path – The path to the file or folder to be moved.
  • to_path – The destination path of the file or folder to be copied. File name should be included in the end of to_path.
  • overwrite – Whether to overwrite an existing file at the given path. (Default False.)
  • bShareFireCopy

    ???

Returns:

True if success to move a file or False.

doSearch(filename, filetype=None, type=3, full_path='/', sharedowner='A', datatype='all', sort='update', order='desc', searchtype='filesearch', startnum=0, pagingrow=100, includeworks='N', bodysearch='N', dummy=36644)

Get music album list.

There are 4 kinds in type:
  • 1 : only directories with idxfolder property
  • 2 : only files
  • 3 : directories and files with thumbnail info (like viewHeight, viewWidth for Image file)
  • 4 : only directories except idxfolder
  • 5 : directories and files without thumbnail info
Tyere are 5 kindes of filetype:
ex) None: all, 1: document, 2:image, 3: video, 4: msuic, 5: zip
Parameters:
  • filename – Query to search.
  • filetype – Type of a file to search.
  • full_path – Directory path to search recursively.
  • sharedowner – File priority to search. (P: priority files only, A: all files.)
  • datatype – Data type of a file to search
  • sort – Order criteria of search result. (‘update’, ‘date’ ...)
  • order – Order of files. (‘desc’ or ‘inc’)
  • searchtype

    ???

  • includeworks – Whether to include Naver Work files to result.
  • bodysearch – Search content of file.
Returns:

metadata or False

Metadata:
  • authtoken
  • content
  • copyright
  • creationdate
  • domaintype
  • filelink
  • fileuploadstatus
  • getcontentlength
  • getlastmodified
  • hilightfilename
  • href
  • lastaccessed
  • owner
  • ownerid
  • owneridc
  • owneridx
  • ownership
  • protect
  • resourceno
  • resourcetype
  • root
  • root_shareno
  • s_type
  • sharedfoldername
  • sharedinfo
  • shareno
  • subpath
  • thumbnailpath
  • virusstatus
downloadFile(from_path, to_path='')

Download a file.

>>> nd.downloadFile('/Picture/flower.png', '~/flower.png')
Parameters:
  • from_path – The full path to download the file to, including the file name. If the destination directory does not yet exist, it will be created.
  • to_path – The full path of a file to be saved in local directory.
Returns:

File object

getDiskSpace()

Get disk space information.

>>> disk_info = nd.getDiskSpace()
Returns:

metadata if success or error message

Metadata:
  • expandablespace
  • filemaxsize
  • largefileminsize
  • largefileunusedspace
  • largefileusedspace
  • paymentspace
  • totallargespace
  • totalspace
  • unusedspace
  • usedspace

Get a link of file

>>> file_link = nd.getFileLink('/Picture/flower.png')
Parameters:full_path – The full path of file to get file link. Path should start and end with ‘/’.
Returns:Shared url or False if failed to share a file or directory through url
getList(full_path, type=1, dept=0, sort='name', order='asc', startnum=0, pagingrow=1000, dummy=56184)

Get a list of files

>>> nd_list = nd.getList('/', type=3)
>>> print nd_list
There are 5 kinds of type:
  • 1 => only directories with idxfolder property
  • 2 => only files
  • 3 => directories and files with thumbnail info (like viewHeight, viewWidth for Image file)
  • 4 => only directories except idxfolder
  • 5 => directories and files without thumbnail info
There are 5 kindes of sort:
  • file : file type, 종류
  • length : size of file, 크기
  • date : edited date, 수정한 날짜
  • credate : creation date, 올린 날짜
  • protect : protect or not, 중요 표시
Parameters:
  • full_path – The full path to get the file list.
  • type – 1, 2, 3, 4 or 5
  • depth – Dept for file list
  • sort – name => 이름
  • order – Order by (asc, desc)
Returns:

metadata (list of dict) or False when failed to get list

Metadata:
  • u’copyright’: u’N’,
  • u’creationdate’: u‘2013-05-12T21:17:23+09:00’,
  • u’filelink’: None,
  • u’fileuploadstatus’: u‘1’,
  • u’getcontentlength’: 0,
  • u’getlastmodified’: u‘2014-01-26T12:23:07+09:00’,
  • u’href’: u’/Codes/’,
  • u’lastaccessed’: u‘2013-05-12T21:17:23+09:00’,
  • u’lastmodifieduser’: None,
  • u’priority’: u‘1’,
  • u’protect’: u’N’,
  • u’resourceno’: 204041859,
  • u’resourcetype’: u’collection’,
  • u’sharedinfo’: u’F’,
  • u’sharemsgcnt’: 0,
  • u’shareno’: 0,
  • u’subfoldercnt’: 5,
  • u’thumbnailpath’: u’N’,
  • u’virusstatus’: u’N’
getMusicAlbumList(tagtype=0, startnum=0, pagingrow=100, dummy=51467)

Get music album list.

Parameters:

tagtype

?

Returns:

metadata or False

Metadata:
  • u’album’:u’Greatest Hits Coldplay’,
  • u’artist’:u’Coldplay’,
  • u’href’:u’/Coldplay - Clocks.mp3’,
  • u’musiccount’:1,
  • u’resourceno’:12459548378,
  • u’tagtype’:1,
  • u’thumbnailpath’:u’N’,
  • u’totalpath’:u’/’
getProperty(full_path, dummy=56184)

Get a file property

Parameters:

full_path – The full path to get the file or directory property.

Returns:

metadata if success or False if failed to get property

Metadata:
  • creationdate
  • exif
  • filelink
  • filelinkurl
  • filetype => 1: document, 2: image, 3: video, 4: music, 5: zip
  • fileuploadstatus
  • getcontentlength
  • getlastmodified
  • href
  • lastaccessed
  • protect
  • resourceno
  • resourcetype
  • thumbnail
  • totalfilecnt
  • totalfoldercnt
  • virusstatus
getRegisterUserInfo(svctype='Android NDrive App ver', auth=0)

Retrieve information about useridx

Parameters:
  • svctype – Information about the platform you are using right now.
  • auth – Authentication type
Returns:

True when success or False when failed

getVersionList(full_path, startnum=0, pagingrow=50, dummy=54213)

Get a version list of a file or dierectory.

Parameters:
  • full_path – The full path to get the file or directory property. Path should start with ‘/’
  • startnum – Start version index.
  • pagingrow – Max # of version list in one page.
Returns:

metadata if succcess or False (failed to get history or there is no history)

Metadata:
  • createuser
  • filesize
  • getlastmodified
  • href
  • versioninfo
  • versionkey
getVersionListCount(full_path, dummy=51234)

Get a count of version list.

Parameters:full_path – The full path to get the file or directory property.
Returns:Integer (number of version lists) or False if failed to get a version list
login(user_id, password, svctype='Android NDrive App ver', auth=0)

Log in Naver and get cookie

>>> s = nd.login("YOUR_ID", "YOUR_PASSWORD")
Parameters:
  • user_id (str) – Naver account’s login id
  • password (str) – Naver account’s login password
  • svctype (str) – Service type
  • auth

    ???

Returns:

True when success to login or False

makeDirectory(full_path, dummy=40841)

Make a directory

>>> nd.makeDirectory('/test')
Parameters:full_path – The full path to get the directory property. Should be end with ‘/’.
Returns:True when success to make a directory or False
makeShareUrl(full_path, passwd)

Make a share url of directory

>>> nd.makeShareUrl('/Picture/flower.png', PASSWORD)
Args:
full_path:
The full path of directory to get share url. Should be end with ‘/’. ex) /folder/
passwd:
Access password for shared directory
Returns:
URL:
share url for a directory
False:
Failed to share a directory
put(file_obj, full_path, overwrite=False)

Upload a file.

>>> nd.put('./flower.png','/Picture/flower.png')
>>> nd.put(open('./flower.png','r'),'/Picture/flower.png')
Parameters:
  • file_obj – A file-like object to check whether possible to upload. You can pass a string as a file_obj or a real file object.
  • full_path – The full path to upload the file to, including the file name. If the destination directory does not yet exist, it will be created.
Returns:

True when succcess to upload a file or False

setProperty(full_path, protect, dummy=7046)

Set property of a file.

Parameters:
  • full_path – The full path to get the file or directory property.
  • protect – ‘Y’ or ‘N’, 중요 표시
Returns:

True when success to set property or False

uploadFile(file_obj, full_path, overwrite=False)

Upload a file as Ndrive really do.

>>> nd.uploadFile('~/flower.png','/Picture/flower.png',True)
This function imitates the process when Ndrive uploads a local file to its server. The process follows 7 steps:
  1. POST /CheckStatus.ndrive
  2. POST /GetDiskSpace.ndrive
  3. POST /CheckUpload.ndrive
  4. PUT /FILE_PATH
  5. POST /GetList.ndrive
  6. POST /GetWasteInfo.ndrive
  7. POST /GetDiskSpace.ndrive

nd.uploadFile(‘./flower.png’,’/Picture/flower.png’)

Parameters:
  • file_obj – A file-like object to check whether possible to upload. You can pass a string as a file_obj or a real file object.
  • full_path – The full path to upload the file to, including the file name. If the destination directory does not yet exist, it will be created.
  • overwrite – Whether to overwrite an existing file at the given path. (Default False.)

Changelog

Version 0.1

First public preview release.

License and Author

This Ndrive package is opened under the MIT license. See LISENCE file for a further information.

I’m Kim Tae Hoon, a student who want to be a great developer :)

Fork me on GitHub