Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py #1

Open
wants to merge 147 commits into
base: master
Choose a base branch
from
Open

py #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
ea50dfc
Added d/l by id+key
Feb 5, 2013
07a5248
Improved dest_id upload() check
Feb 5, 2013
0d1acf6
Initial commit
Feb 6, 2013
321aa65
Removed dupe functions in crpyto, input file close, added example fil…
Feb 6, 2013
bbc574e
Added PyCrypto
Feb 7, 2013
1eab67d
Added file search function and get public link function
Feb 7, 2013
0117b08
Merge remote-tracking branch 'origin/master'
Feb 7, 2013
a26a6e2
Added file search function and get public link function
Feb 7, 2013
50e565e
Added delete by search example
Feb 7, 2013
7ed5bce
Removed un-needed variables process_file()
Feb 7, 2013
b91f84c
get_link() working, added get_file() for single file
Feb 7, 2013
a28031c
updated features rundown
Feb 7, 2013
3cf4584
get_link() partially working
Feb 7, 2013
ec4b160
get_link() renamed get_upload_link()
Feb 7, 2013
e3fa3ab
var renaming, comments
Feb 7, 2013
d8ab4d1
Added get_link() and removed file['k'] from process_file()
Feb 8, 2013
e1eed44
Test updated
Feb 8, 2013
1d80921
Added get_link() example
Feb 8, 2013
29ede8f
download() now takes file obj, rather than public file id/handle
Feb 8, 2013
09268b1
features list
Feb 8, 2013
ff91521
readme
Feb 8, 2013
2493a10
fixed api resp issue #2, reformatted code pep 8 style
Feb 9, 2013
8dcd2d3
Added optional save destination path to download functions
Feb 11, 2013
e5ae47d
Fixed typo
Feb 12, 2013
d79dcca
Fixed utf-8 problem
carlesso Feb 13, 2013
8d2dbb5
Merge pull request #5 from carlesso/master
Feb 13, 2013
17b4d03
added setup.py, restructured files to be a python package. fixed issu…
Feb 16, 2013
1dc6275
added pip install info
Feb 16, 2013
0cd6daa
updated readme
Feb 16, 2013
4128609
get_files() updated to check each file has a name, thanks jlejeune
Feb 18, 2013
35c80f3
updated pip version info, added manifest to .gitignore
Feb 19, 2013
27b636a
Added python-requests version 0.10+ requirement
Feb 22, 2013
c77ec99
Added destory functions, empty trash, updated tests, other small refr…
Feb 23, 2013
9b9530f
print syntax
Feb 23, 2013
63d39dd
moved find()
Feb 23, 2013
fc8a03d
Decrypt now shared folders/files that do not belong to us
jlejeune Feb 28, 2013
236ffc6
Merge pull request #9 from jlejeune/pull_request
Feb 28, 2013
6ecbc2c
updated version number
Feb 28, 2013
46e5328
Forget to init self.users_keys variable
jlejeune Feb 28, 2013
9bbb2b8
Merge pull request #10 from jlejeune/pull_request
Feb 28, 2013
d444be9
changes to delete, destroy functions. see readme for updated usage. d…
Mar 5, 2013
9096e4c
Added syntax to readme
Mar 5, 2013
a7c8089
Added syntax to readme
Mar 5, 2013
b6ae058
Spacing
Mar 5, 2013
43296ee
Spacing
Mar 5, 2013
8f06435
Version number for pypi
Mar 5, 2013
83b1de1
added get_quota() and get_balance()
Mar 10, 2013
f84d5bf
added get_quota() and get_balance()
Mar 10, 2013
3743298
updated readme
Mar 10, 2013
b43e636
Add create_folder() function
jlejeune Mar 12, 2013
7b1e471
Send also request_id param in create_folder() function (useless but t…
jlejeune Mar 12, 2013
bd64c5d
Merge pull request #18 from jlejeune/pull_request
Mar 12, 2013
63b5a22
remove filesdict update
Mar 12, 2013
0592055
updated readme, create_folder() e.g
Mar 12, 2013
38db676
updated version
Mar 12, 2013
be7fa68
upload() minor tidy up
Mar 12, 2013
fd05186
pip install error fixed
Apr 8, 2013
692e774
Shared keys now works for file comming from shared folders that aren'…
gissehel Apr 15, 2013
10b4a88
Merge pull request #21 from gissehel/sharedfolders
Apr 15, 2013
8b1052a
Code to pep8 standards, shared folders working
Apr 15, 2013
5b141c9
Pip version updated
Apr 15, 2013
7e4d2ee
You can't download files in shared folders using public links because…
gissehel Apr 19, 2013
09c4b14
I don't think that printing on stdout is the right thing to do in thi…
gissehel Apr 19, 2013
89a4030
Downloading using a tempory filename is safer. The tempory filename p…
gissehel Apr 19, 2013
6ea2bfa
Merge pull request #22 from gissehel/evols
Apr 19, 2013
d1fd89d
it's more pep8 :)
Apr 19, 2013
4b0f0b2
pypi info updated
Apr 19, 2013
0332d91
Forgot to change the file_name to file_name_tmp when the destination …
gissehel Apr 19, 2013
ef47228
Merge pull request #23 from gissehel/tempofilename_typo
Apr 19, 2013
964157b
pypi info updated
Apr 19, 2013
dcbd17a
Explicitly declaring dependency in setup.py make 'pip install mega.py…
gissehel Apr 20, 2013
58d89c2
get_storage_space retrieve the used space and total space currently a…
gissehel Apr 21, 2013
ced5b61
comments
Apr 23, 2013
972bfd8
The code was not robust anymore in weird cases where file['k']=='', i…
gissehel Apr 27, 2013
fc96c96
Merge pull request #26 from gissehel/robustkey
Apr 27, 2013
115fcbc
class method bug fix, verbose output option added, download progress
Apr 28, 2013
d8df8bd
read me updated
Apr 28, 2013
675ff6b
Added upload progress
Apr 28, 2013
36bed09
Merge pull request #25 from gissehel/storagespace
Apr 28, 2013
d15be6d
read me update and tests
Apr 28, 2013
dd9f74b
pip version updated
Apr 28, 2013
200eaed
readme
Apr 28, 2013
b2e1d35
removed file
Apr 28, 2013
0d2e919
PEP8 style fixes
Apr 28, 2013
3b9b88e
Issue #31 fix
May 1, 2013
15cb6e0
pip version
May 1, 2013
40f9fb9
Renaming file and folders support
gissehel May 4, 2013
f7a43ed
Merge pull request #34 from gissehel/rename
May 5, 2013
1a349e3
Comment
May 5, 2013
24f4413
pip updated
May 5, 2013
b9ec62c
.move(...) can now move into any folder
gissehel May 5, 2013
c453a88
Big optimisation on download code for mac checking
gissehel May 5, 2013
c2befcb
Speedup the mac calculation on upload
gissehel May 5, 2013
5df8b71
allow setting file names on upload and download
ckornacker May 6, 2013
28f69e1
enable directory listing with get_files_in_node
ckornacker May 6, 2013
08b76ba
split get_id_from_public_handle
ckornacker May 6, 2013
330ee72
Merge pull request #35 from gissehel/move
May 8, 2013
3bd08be
Merge pull request #36 from gissehel/speedimprovement
May 8, 2013
20d865e
small restructuring
May 8, 2013
7788e43
adding moving to readme
May 8, 2013
18d8657
Merge pull request #38 from ckornacker/feature/filenames
May 8, 2013
9727ca9
renamed vars for specifying upload(),download() dest filenames
May 8, 2013
9773f1e
Merge pull request #40 from ckornacker/feature/dirlisting
May 8, 2013
b43c386
get_files_in_node() special target check
May 8, 2013
728b88c
updated readme
May 8, 2013
d00b34d
updated readme
May 8, 2013
7835c73
updated readme
May 8, 2013
3904ec5
Merge pull request #41 from ckornacker/feature/splitgetid
May 8, 2013
32d9c43
get_id_from_node_data -> get_id_from_obj
May 8, 2013
5c77818
todo removed
May 8, 2013
bd803b6
comments
May 8, 2013
52a2185
'other' code section
May 8, 2013
457a542
added add_contact()
May 8, 2013
8466a04
version
May 10, 2013
e490bf7
issue #44 manually added as would not merge. small spelling changes
May 11, 2013
878f095
pip version updated
May 11, 2013
2e0b1f1
add/remove contacts
May 11, 2013
913e128
version
May 11, 2013
574169c
files < 16bytes, upload/download bug fix, see pull #45
May 12, 2013
50ebd4f
basic unit testing
May 15, 2013
58aed39
basic unit testing
May 15, 2013
42f7736
basic unit testing
May 16, 2013
490941c
travis
May 17, 2013
3c94fa9
travis
May 17, 2013
fd42769
ignore update
May 17, 2013
ac4bf5c
travis
May 17, 2013
75854fc
travis
May 18, 2013
1991d8c
travis
May 18, 2013
198007b
reqs
May 18, 2013
0ec846e
travis
May 18, 2013
6e2dc60
travis
May 18, 2013
fe7a515
anonymous login
May 18, 2013
2b8f56a
removed pre test func
May 18, 2013
55edbdb
improved tests
May 18, 2013
245fee2
improved tests
May 18, 2013
40d8620
travis
May 18, 2013
752e2e8
api info file started
May 23, 2013
d20dcbd
api info file started
May 23, 2013
e6c38d9
api info file started
May 23, 2013
1b63ef1
updated readme
May 23, 2013
42a20b7
Added upload to destination e.g to readme
Jun 10, 2013
7c88b34
more PEP8 generally
Jun 27, 2013
9263d0c
more PEP8 generally
Jun 27, 2013
b1ada6a
Upload supports empty files
plutec Nov 9, 2013
3bd15a9
It is possible to find a folder with a "path"
plutec Nov 9, 2013
384519c
Merge pull request #63 from plutec/master
Nov 11, 2013
246d943
Updated readme
Jul 6, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Compiled source #
###################
*.pyc

# Hidden files #
###################
# Build files #
###################
build/
dist/
.pypirc
MANIFEST
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: python
python:
- "2.7"
install: pip install -r requirements.txt
script: python tests/unit-tests.py
53 changes: 53 additions & 0 deletions API_INFO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Mega API information
=====================

This file contains definitions for some of the properties within the API. The aim of the file is that more people will contribute through understanding.


### Node attributes (json properties)

* 'a' Type
* 'h' Id
* 'p' Parent Id
* 'a' encrypted Attributes (within this: 'n' Name)
* 'k' Node Key
* 'u' User Id
* 's' Size
* 'ts' Time Stamp

#### Node types

* 0 File
* 1 Folder
* 2 Root Folder
* 3 Inbox
* 4 Trash
* -1 Dummy


### Error responses

#### General errors:
* EINTERNAL (-1):
* EARGS (-2):
* EAGAIN (-3)
* ERATELIMIT (-4):

#### Upload errors:
* EFAILED (-5):
* ETOOMANY (-6):
* ERANGE (-7):
* EEXPIRED (-8):

#### Filesystem/Account level errors:
* ENOENT (-9):
* ECIRCULAR (-10):
* EACCESS (-11):
* EEXIST (-12):
* EINCOMPLETE (-13):
* EKEY (-14):
* ESID (-15):
* EBLOCKED (-16):
* EOVERQUOTA (-17):
* ETEMPUNAVAIL (-18):

159 changes: 130 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,155 @@
# Mega.py

Python library for the Mega.co.nz API, currently supporting login, uploading, downloading & deleting of files.
# Deprecated

This is a work in progress, further functionality coming shortly.
Mega.py is now deprecated, please use the official SDK https://github.com/meganz/sdk2.

## How To Use
I aim to write a wrapper for the SDK when i have the time to do so.

### Create an instance of Mega.py
------------------------

mega = Mega()

### Login to Mega
# Mega.py
[![Build Status](https://travis-ci.org/richardasaurus/mega.py.png?branch=master)](https://travis-ci.org/richardasaurus/mega.py)
[![Downloads](https://pypip.in/d/mega.py/badge.png)](https://crate.io/packages/mega.py/)

Python library for the Mega.co.nz API, currently supporting:
- login
- uploading
- downloading
- deleting
- searching
- sharing
- renaming
- moving files

m = mega.login(email, password)
This is a work in progress, further functionality coming shortly.

### Get user details
For more detailed information see API_INFO.md

details = m.get_user()
## How To Use

### Install mega.py package
```python
#Run the following command, or run setup from the latest github source
sudo pip install mega.py
```
### Import mega.py
```python
from mega import Mega
```
### Create an instance of Mega.py
```python
mega = Mega()
# add the verbose option for print output on some functions
mega = Mega({'verbose': True})
```
### Login to Mega
```python
m = mega.login(email, password)
# login using a temporary anonymous account
m = mega.login()
```
### Get user details
```python
details = m.get_user()
```
### Get account balance (Pro accounts only)
```python
balance = m.get_balance()
```
### Get account disk quota
```python
quota = m.get_quota()
```
### Get account storage space
```python
# specify unit output kilo, mega, gig, else bytes will output
space = m.get_storage_space(kilo=True)
```
### Get account files

files = m.get_files()

### Upload a file

m.upload('myfile.doc')

### Download a file from URL

m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')

### Trash a file from URL or it's ID

m.delete('utYjgSTQ')
m.delete_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
```python
files = m.get_files()
```
### Upload a file, and get its public link
```python
file = m.upload('myfile.doc')
m.get_upload_link(file)
# see mega.py for destination and filename options
```
### Upload a file to a destination folder
```python
folder = m.find('my_mega_folder')
m.upload('myfile.doc', folder[0])
```

### Download a file from URL or file obj, optionally specify destination folder
```python
file = m.find('myfile.doc')
m.download(file)
m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
m.download(file, '/home/john-smith/Desktop')
# specify optional download filename (download_url() supports this also)
m.download(file, '/home/john-smith/Desktop', 'myfile.zip')
```
### Import a file from URL, optionally specify destination folder
```python
m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
folder_node = m.find('Documents')[1]
m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc', dest_node=folder_node)
```
### Create a folder
```python
m.create_folder('new_folder')
```
### Rename a file or a folder
```python
file = m.find('myfile.doc')
m.rename(file, 'my_file.doc')
```
### Moving a file or a folder into another folder
```python
file = m.find('myfile.doc')
folder = m.find('myfolder')
m.move(file[0], folder)
```
### Search account for a file, and get its public link
```python
file = m.find('myfile.doc')
m.get_link(file)
```
### Trash or destroy a file from URL or its ID
```python
m.delete(file[0])
m.delete_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')

m.destroy(file[0])
m.destroy_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')

files = m.find('myfile.doc')
if files:
m.delete(files[0])
```
### Add/remove contacts
```python
m.add_contact('[email protected]')
m.remove_contact('[email protected]')
```

## Requirements

1. Python2.7+
2. Python requests - python-requests.org
2. Python requests (>0.10) - python-requests.org
3. PyCrypto - dlitz.net/software/pycrypto/

## Tests

Test .py files can be found in /tests, run these to ensure Mega.py is working 100%.
Test .py files can be found in tests.py, run these to ensure Mega.py is working 100%.

## Contribute

Feel free to pull the source and make changes and additions.

Learn about the API at Mega.co.nz
Learn about the API at Mega.co.nz, more documentation coming shortly.
- https://mega.co.nz/#developers



62 changes: 62 additions & 0 deletions examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from mega import Mega


def test():
"""
Enter your account details to begin
comment/uncomment lines to test various parts of the API
see readme.md for more information
"""

#user details
email = '[email protected]'
password = 'password'

mega = Mega()
#mega = Mega({'verbose': True}) # verbose option for print output

# login
m = mega.login(email, password)

# get user details
details = m.get_user()
print(details)

# get account files
files = m.get_files()

# get account disk quota in MB
print(m.get_quota())
# get account storage space
print(m.get_storage_space())

# example iterate over files
for file in files:
print(files[file])

# upload file
print(m.upload('examples.py'))

# search for a file in account
file = m.find('examples.py')

if file:
# get public link
link = m.get_link(file)
print(link)

# download file. by file object or url
print m.download(file, '/tmp')
#m.download_url(link)

#delete or destroy file. by id or url
print(m.delete(file[0]))
#print(m.destroy(file[0]))
#print(m.delete_url(link))
#print(m.destroy_url(link))

# empty trash
print(m.empty_trash())

if __name__ == '__main__':
test()
Loading