def main(): if len(sys.argv) <= 3: usage() sys.exit(2) mtp = pymtp.MTP() mtp.connect() source = sys.argv[1] target = sys.argv[2] parent = int(sys.argv[3]) id3data = pyid3lib.tag(source) metadata = pymtp.LIBMTP_Track() if (hasattr(id3data, 'artist')): metadata.artist = id3data.artist if (hasattr(id3data, 'title')): metadata.title = id3data.title if (hasattr(id3data, 'album')): metadata.album = id3data.album if (hasattr(id3data, 'tracknum')): metadata.tracknumber = id3data.tracknum track_id = mtp.send_track_from_file(source, target, metadata, parent=parent) print "Created new track with ID: %s" % (track_id) mtp.disconnect()
def main(): if len(sys.argv) <= 1: usage() sys.exit(2) mtp = pymtp.MTP() mtp.connect() object_ids = sys.argv[1:] for object_id in object_ids: mtp.delete_object(int(object_id)) print "Deleted object %s" % (object_id) mtp.disconnect()
def main(): if len(sys.argv) <= 1: usage() sys.exit(2) mtp = pymtp.MTP() mtp.connect() name = sys.argv[1] parent = int(sys.argv[2]) folder_id = mtp.create_folder(name, parent) print "Created new folder with ID: %s" % (folder_id) mtp.disconnect()
def main(): if len(sys.argv) <= 3: usage() sys.exit(2) mtp = pymtp.MTP() mtp.connect() source = sys.argv[1] target = sys.argv[2] parent = int(sys.argv[3]) file_id = mtp.send_file_from_file(source, target, parent=parent) print "Created new track with ID: %s" % (file_id) mtp.disconnect()
def loop(): global BASELINE_DEVICES, NUM_DEVICES devices = getCurrentDevices() if (len(devices) > NUM_DEVICES): NUM_DEVICES = len(devices) server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo() server.login('*****@*****.**', 'JimWaldo!!!') dcim_folder_id = 0 dev_out = [] for dev in devices: if not dev in BASELINE_DEVICES: dev_out.append(dev) try: # Connect to device device = pymtp.MTP() device.connect() dcim_folder_id = get_dcim_folder_id(device) print "DCIM folder id: %s" % dcim_folder_id device.disconnect() except: pass if (dcim_folder_id > 0): msg = MIMEText( str(datetime.datetime.now()) + ' ' + str(dev_out) + "DCIM folder found.") else: msg = MIMEText(str(datetime.datetime.now()) + ' ' + str(dev_out)) msg['Subject'] = 'New USB device connected' msg['From'] = '*****@*****.**' msg['To'] = '*****@*****.**' server.sendmail('*****@*****.**', '*****@*****.**', msg.as_string()) server.close() f = open('log_charging_usage.txt', 'a') f.write(str(datetime.datetime.now()) + ' ' + str(dev_out) + '\n\n') f.close() elif (len(devices) < NUM_DEVICES): NUM_DEVICES = len(devices)
def get_signature_http(): file_ = None data = None download_path = config.get('signature_driver', 'download_path') or \ '/tmp' signature_file = config.get('signature_driver', 'signature_file') or \ 'signature.svg' try: mtp = pymtp.MTP() mtp.connect() except Exception, err: app.logger.error('Unable to connect device %s' % str(err)) return jsonify(jsonrpc='2.0', result=data)
def main(): if len(sys.argv) <= 2: usage() sys.exit(2) mtp = pymtp.MTP() mtp.connect() name = sys.argv[1] tracks = sys.argv[2:] metadata = pymtp.LIBMTP_Playlist() for track in tracks: metadata.append(track) playlist_id = mtp.create_new_playlist(name, metadata) print "Created new playlist with ID: %s" % (playlist_id) mtp.disconnect()
def main(): mtp = pymtp.MTP() mtp.connect() print "Welcome to the PyMTP Shell" print "You are currently connected to '%s'" % (mtp.get_devicename()) print "Your MTP object is '%s'" % ("mtp") print "Your progress callback object is '%s'" % ("callback") print "To exit, type 'quit'" while True: try: if mtp.device: result = raw_input("(connected) >>> ") else: result = raw_input("(disconnected) >>> ") if result.startswith("quit"): mtp.disconnect() sys.exit() else: exec result except Exception, message: print "An exception occurred:" print message
def get_signature_http(): file_ = None data = None download_path = config.get('signature_driver', 'download_path') or \ '/tmp' signature_file = config.get('signature_driver', 'signature_file') or \ 'signature.svg' try: mtp = pymtp.MTP() mtp.connect() except Exception as err: app.logger.error('Unable to connect device %s' % str(err)) return jsonify(jsonrpc='2.0', result=data) for f in mtp.get_filelisting(): if f.filename == signature_file: file_ = f break if file_: dest_file = os.path.join(download_path, signature_file) try: mtp.get_file_to_file(file_.item_id, dest_file) app.logger.debug('file downloaded to %s' % dest_file) with open(dest_file, 'r') as f: data = f.read() app.logger.debug(data) mtp.delete_object(file_.item_id) except Exception as err: app.logger.error('error during file transfer %s' % str(err)) else: app.logger.error('file not found on the device: %s' % signature_file) mtp.disconnect() return jsonify(jsonrpc='2.0', result=data)
""" # https://github.com/guardianproject/keysync/blob/master/otrapps/util.py # gracefully handle it when pymtp doesn't exist import os, sys, ctypes class MTPDummy(): def detect_devices(self): return [] try: import pymtp mtp = pymtp.MTP() except ImportError as e: mtp = MTPDummy() sys.stderr.write("MTP not supported: %s\n" % e) except OSError as e: # OS error if all three libraries are not on the same path mtp = MTPDummy() sys.stderr.write("MTP not supported: %s\n" % e) sys.stderr.write( "verify that libusb, libiconv, and libmtp are available\n") except TypeError as e: # this is a bug in the current version of mtp on windows, # which tries to load a null path for the dll mtp = MTPDummy() sys.stderr.write("MTP not supported: (libmtp not found)\n") # GNOME GVFS mount point for MTP devices
def __init__(self): self.__model_name = None self.__MTPDevice = pymtp.MTP()
def mtp(): device = pymtp.MTP() device.connect() print(device)
def __init__(self, lst_files_synced): self._lst_files_synced = lst_files_synced self._device = pymtp.MTP() self._lst_files_to_sync = list()
new_length = len(folder_ids) return folder_ids def get_picture_file_list(device, folder_ids): picture_files = [] for f in device.get_filelisting(): if f.parent_id in folder_ids: picture_files.append(f) return picture_files # Connect to device device = pymtp.MTP() device.connect() print("\nConnected to device: %s" % device.get_devicename()) dcim_folder_id = get_dcim_folder_id(device) print("DCIM folder id: %s" % dcim_folder_id) folder_ids = get_child_folders(device, dcim_folder_id) print("Folder Ids: %s" % folder_ids) picture_files = get_picture_file_list(device, folder_ids) for f in picture_files: print("Picture: %s - ID: %s" % (f.filename, f.item_id)) device.disconnect()