Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
("default_zencast_folder", ctypes.c_uint32),
("default_album_folder", ctypes.c_uint32),
("default_text_folder", ctypes.c_uint32),
("cd", ctypes.c_void_p),
("next", ctypes.POINTER(LIBMTP_MTPDevice))]
class LIBMTP_File(ctypes.Structure):
"""
LIBMTP_File
Contains the ctypes structure for LIBMTP_file_t
"""
def __repr__(self):
return "%s (%s)" % (self.filename, self.item_id)
LIBMTP_File._fields_ = [("item_id", ctypes.c_uint32),
("parent_id", ctypes.c_uint32),
("storage_id", ctypes.c_uint32),
("filename", ctypes.c_char_p),
("filesize", ctypes.c_uint64),
("filetype", ctypes.c_int),
("next", ctypes.POINTER(LIBMTP_File))]
class LIBMTP_Track(ctypes.Structure):
"""
LIBMTP_Track
Contains the ctypes structure for LIBMTP_track_t
"""
def __repr__(self):
return "%s - %s (%s)" % (self.artist, self.title, self.item_id)
# End Data Model Definitions
# ----------
# ----------
# Type Definitions
# ----------
_libmtp.LIBMTP_Get_Friendlyname.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Serialnumber.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Modelname.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Manufacturername.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Deviceversion.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Filelisting_With_Callback.restype = ctypes.POINTER(LIBMTP_File)
_libmtp.LIBMTP_Get_Tracklisting_With_Callback.restype = ctypes.POINTER(LIBMTP_Track)
_libmtp.LIBMTP_Get_Filetype_Description.restype = ctypes.c_char_p
_libmtp.LIBMTP_Get_Filemetadata.restype = ctypes.POINTER(LIBMTP_File)
_libmtp.LIBMTP_Get_Trackmetadata.restype = ctypes.POINTER(LIBMTP_Track)
_libmtp.LIBMTP_Get_First_Device.restype = ctypes.POINTER(LIBMTP_MTPDevice)
_libmtp.LIBMTP_Get_Playlist_List.restype = ctypes.POINTER(LIBMTP_Playlist)
_libmtp.LIBMTP_Get_Playlist.restype = ctypes.POINTER(LIBMTP_Playlist)
_libmtp.LIBMTP_Get_Folder_List.restype = ctypes.POINTER(LIBMTP_Folder)
_libmtp.LIBMTP_Find_Folder.restype = ctypes.POINTER(LIBMTP_Folder)
_libmtp.LIBMTP_Get_Errorstack.restype = ctypes.POINTER(LIBMTP_Error)
# This is for callbacks with the type of LIBMTP_progressfunc_t
Progressfunc = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_uint64, ctypes.c_uint64)
# ----------
# End Type Definitions
# ----------
class MTP:
"""
receive callbacks from ptp. Callback function must
take two arguments, sent and total (in bytes)
@rtype: int
@return: The object ID of the new file
"""
if (self.device == None):
raise NotConnected
if (os.path.isfile(source) == False):
raise IOError
if (callback != None):
callback = Progressfunc(callback)
metadata = LIBMTP_File(filename=target, \
filetype=self.find_filetype(source), \
filesize=os.stat(source).st_size)
ret = self.mtp.LIBMTP_Send_File_From_File(self.device, source, \
ctypes.pointer(metadata), callback, None, parent)
if (ret != 0):
self.debug_stack()
raise CommandFailed
return metadata.item_id