Git Product home page Git Product logo

python-mtp's Introduction

python-mtp

python wrapper around libmtp to talk the media transfer protocol

About

python-mtp is a wrapper for libmtp, allowing python applications to communicate with all MTP devices that are supported by libmtp. For supported & tested devices see there. It is implemented using cython.

Simple test scripts can be found in examples/ for all major operations.

Little warning: MTP is a crap and doesn't work well or reliable. Neither this wrapper nor libmtp are to blame.

Usage

The wrapper makes use of the with statement and can be used as simple as:

from mtp import MediaTransfer
with MediaTransfer() as mtp:
	print('Infos: {}'.format(mtp.get_deviceinfo())

The examples include a simple backup script that copies all files reachable by MTP from the device to the local directory creating a backup directory named after the serialnumber of the device.

Tools

- backup: there is a script in the examples/ section that implemtns a
  backup of your mtp-capable device

- playlist: 

Major Pitfalls

libmtp has a big drawback that is a cache filled at startup. This takes alot of time due to usb initialisation. Depending on the number of files it takes a minute or more. A flag was given to the MediaTransfer-class construtor that allows creating a connection without caching. This renders some functions unusual, others require this mode.

On Andriod devices MTP sometimes doesn't not work if USB-debugging is enabled.

If the screenlock is active MTP is known not to work well on some devices.

Some devices have problems if you wait too long with the connect after plugging in.

A windows phones did a factory reset during MTP reset after connection errors (the reset was issues by libmtp automatically during initialisation).

While libmtp provides errorcodes some functions just return -1 (which is not a listed error). Other functions return a pointer and have no way to determine the cause of the error (they just return NULL).

If you for example upload a file to a location / name that already exists you get no explicit error code but often just a -1.

Setting the debugging level is of some help (LIBMTP_DEBUG=255)

Some files doesn't seem to be "Media" and are not shown via mtp (for me .gpx files did not apear).

python-mtp's People

Contributors

nick125 avatar nthnca avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.