Exemple #1
0
    def copy_delayed_files(self, callback=False):
        """Copy files not marked as transferred to the iPod.

        callback is an optional function that will be called for each
        track that is copied.  It will be passed the following
        arguments:

            database -> the database object
            track    -> the track being copied
            iterator -> the current track number being copied
            total    -> the total tracks to be copied

        """

        if not gpod.itdb_get_mountpoint(self._itdb):
            # we're not working with a real ipod.
            return
        to_copy = []
        for track in self:
            try:
                transferred = int(track['userdata']['transferred'])
            except (KeyError, TypeError):
                transferred = 1
            if not transferred:
                to_copy.append(track)
        i = 0
        total = len(to_copy)
        for track in to_copy:
            if callback:
                i = i + 1
                callback(self, track, i, total)
            track.copy_to_ipod()
Exemple #2
0
    def copy_delayed_files(self,callback=False):
        """Copy files not marked as transferred to the iPod.

        callback is an optional function that will be called for each
        track that is copied.  It will be passed the following
        arguments:

            database -> the database object
            track    -> the track being copied
            iterator -> the current track number being copied
            total    -> the total tracks to be copied

        """

        if not gpod.itdb_get_mountpoint(self._itdb):
            # we're not working with a real ipod.
            return
        to_copy=[]
        for track in self:
            try:
                transferred = int(track['userdata']['transferred'])
            except (KeyError, TypeError):
                transferred = 1
            if not transferred:
                to_copy.append(track)
        i = 0
        total = len(to_copy)
        for track in to_copy:
            if callback:
                i=i+1
                callback(self,track, i, total)
            track.copy_to_ipod()
Exemple #3
0
 def copy_to_ipod(self):
     """Copy the track to the iPod."""
     self['userdata']['sha1_hash'] = gtkpod.sha1_hash(self._userdata_into_default_locale('filename'))
     mp = gpod.itdb_get_mountpoint(self._track.itdb)
     if not mp:
         return False
     if gpod.itdb_cp_track_to_ipod(self._track,
                                   self._userdata_into_default_locale('filename'),
                                   None) != 1:
         raise TrackException('Unable to copy %s to iPod as %s' % (
             self._userdata_into_default_locale('filename'),
             self))
     fname = self.ipod_filename().replace(mp, '').replace(os.path.sep, ':')
     self['userdata']['filename_ipod'] = fname
     self['userdata']['transferred'] = 1
     return True
Exemple #4
0
 def copy_to_ipod(self):
     """Copy the track to the iPod."""
     self['userdata']['sha1_hash'] = gtkpod.sha1_hash(
         self._userdata_into_default_locale('filename'))
     mp = gpod.itdb_get_mountpoint(self._track.itdb)
     if not mp:
         return False
     if gpod.itdb_cp_track_to_ipod(
             self._track, self._userdata_into_default_locale('filename'),
             None) != 1:
         raise TrackException(
             'Unable to copy %s to iPod as %s' %
             (self._userdata_into_default_locale('filename'), self))
     fname = self.ipod_filename().replace(mp, '').replace(os.path.sep, ':')
     self['userdata']['filename_ipod'] = fname
     self['userdata']['transferred'] = 1
     return True
Exemple #5
0
    def __init__(self, mountpoint="/mnt/ipod", local=False, localdb=None):
        """Create a Database object.

        You can create the object from a mounted iPod or from a local
        database file.

        To use a mounted iPod:

            db = gpod.Database('/mnt/ipod')

        To use a local database file:

            db = gpod.Database(localdb='/path/to/iTunesDB')

        If you specify local=True then the default local database from
        gtkpod will be used (~/.gtkpod/local_0.itdb):

            db = gpod.Database(local=True)

        """

        if local or localdb:
            if localdb:
                self._itdb_file = localdb
            else:
                self._itdb_file = os.path.join(os.environ['HOME'], ".gtkpod",
                                               "local_0.itdb")
            self._itdb = gpod.itdb_parse_file(self._itdb_file, None)
        else:
            self._itdb = gpod.itdb_parse(mountpoint, None)
            if not self._itdb:
                raise DatabaseException(
                    "Unable to parse iTunes database at mount point %s" %
                    mountpoint)
            else:
                self._itdb.mountpoint = mountpoint
            self._itdb_file = gpod.itdb_get_itunesdb_path(
                gpod.itdb_get_mountpoint(self._itdb))
        self._load_gtkpod_extended_info()
Exemple #6
0
    def __init__(self, mountpoint="/mnt/ipod", local=False, localdb=None):
        """Create a Database object.

        You can create the object from a mounted iPod or from a local
        database file.

        To use a mounted iPod:

            db = gpod.Database('/mnt/ipod')

        To use a local database file:

            db = gpod.Database(localdb='/path/to/iTunesDB')

        If you specify local=True then the default local database from
        gtkpod will be used (~/.gtkpod/local_0.itdb):

            db = gpod.Database(local=True)

        """

        if local or localdb:
            if localdb:
                self._itdb_file = localdb
            else:
                self._itdb_file = os.path.join(os.environ['HOME'],
                                               ".gtkpod",
                                               "local_0.itdb")
            self._itdb = gpod.itdb_parse_file(self._itdb_file, None)
        else:
            self._itdb = gpod.itdb_parse(mountpoint, None)
            if not self._itdb:
                raise DatabaseException("Unable to parse iTunes database at mount point %s" % mountpoint)
            else:
                self._itdb.mountpoint = mountpoint
            self._itdb_file = gpod.itdb_get_itunesdb_path(
                                gpod.itdb_get_mountpoint(self._itdb)
                              )
        self._load_gtkpod_extended_info()