示例#1
0
文件: sync.py 项目: boyska/gpodder
    def close(self):
        if self.itdb is not None:
            self.notify('status', _('Saving iPod database'))
            gpod.itdb_write(self.itdb, None)
            self.itdb = None

            if self._config.ipod_write_gtkpod_extended:
                self.notify('status', _('Writing extended gtkpod database'))
                itunes_folder = os.path.join(self.mountpoint, 'iPod_Control', 'iTunes')
                ext_filename = os.path.join(itunes_folder, 'iTunesDB.ext')
                idb_filename = os.path.join(itunes_folder, 'iTunesDB')
                if os.path.exists(ext_filename) and os.path.exists(idb_filename):
                    try:
                        db = gpod.ipod.Database(self.mountpoint)
                        gpod.gtkpod.parse(ext_filename, db, idb_filename)
                        gpod.gtkpod.write(ext_filename, db, idb_filename)
                        db.close()
                    except:
                        logger.error('Error writing iTunesDB.ext')
                else:
                    logger.warning('Could not find %s or %s.',
                            ext_filename, idb_filename)

        Device.close(self)
        return True
示例#2
0
    def close(self):
        if self.itdb is not None:
            self.notify('status', _('Saving iPod database'))
            gpod.itdb_write(self.itdb, None)
            self.itdb = None

            if self._config.ipod_write_gtkpod_extended:
                self.notify('status', _('Writing extended gtkpod database'))
                itunes_folder = os.path.join(self.mountpoint, 'iPod_Control',
                                             'iTunes')
                ext_filename = os.path.join(itunes_folder, 'iTunesDB.ext')
                idb_filename = os.path.join(itunes_folder, 'iTunesDB')
                if os.path.exists(ext_filename) and os.path.exists(
                        idb_filename):
                    try:
                        db = gpod.ipod.Database(self.mountpoint)
                        gpod.gtkpod.parse(ext_filename, db, idb_filename)
                        gpod.gtkpod.write(ext_filename, db, idb_filename)
                        db.close()
                    except:
                        logger.error('Error writing iTunesDB.ext')
                else:
                    logger.warning('Could not find %s or %s.', ext_filename,
                                   idb_filename)

        Device.close(self)
        return True
示例#3
0
 def close(self):
     if self.itdb is not None:
         self.notify('status', _('Saving iPod database'))
         gpod.itdb_write(self.itdb, None)
         self.itdb = None
         
         if self._config.ipod_write_gtkpod_extended:
             self.notify('status', _('Writing extended gtkpod database'))
             ext_filename = os.path.join(self.mountpoint, 'iPod_Control', 'iTunes', 'iTunesDB.ext')
             idb_filename = os.path.join(self.mountpoint, 'iPod_Control', 'iTunes', 'iTunesDB')
             if os.path.exists(ext_filename) and os.path.exists(idb_filename):
                 try:
                     db = gpod.ipod.Database(self.mountpoint)
                     gpod.gtkpod.parse(ext_filename, db, idb_filename)
                     gpod.gtkpod.write(ext_filename, db, idb_filename)
                     db.close()
                 except:
                     log('Error when writing iTunesDB.ext', sender=self, traceback=True)
             else:
                 log('I could not find %s or %s. Will not update extended gtkpod DB.', ext_filename, idb_filename, sender=self)
         else:
             log('Not writing extended gtkpod DB. Set "ipod_write_gpod_extended" to True if I should write it.', sender=self)            
         
         
     Device.close(self)
     return True
示例#4
0
文件: sync.py 项目: xerxes2/gpodder
 def close(self):
     if self.itdb is not None:
         self.notify('status', _('Saving iPod database'))
         gpod.itdb_write(self.itdb, None)
         self.itdb = None
         
         if self._config.ipod_write_gtkpod_extended:
             self.notify('status', _('Writing extended gtkpod database'))
             ext_filename = os.path.join(self.mountpoint, 'iPod_Control', 'iTunes', 'iTunesDB.ext')
             idb_filename = os.path.join(self.mountpoint, 'iPod_Control', 'iTunes', 'iTunesDB')
             if os.path.exists(ext_filename) and os.path.exists(idb_filename):
                 try:
                     db = gpod.ipod.Database(self.mountpoint)
                     gpod.gtkpod.parse(ext_filename, db, idb_filename)
                     gpod.gtkpod.write(ext_filename, db, idb_filename)
                     db.close()
                 except:
                     log('Error when writing iTunesDB.ext', sender=self, traceback=True)
             else:
                 log('I could not find %s or %s. Will not update extended gtkpod DB.', ext_filename, idb_filename, sender=self)
         else:
             log('Not writing extended gtkpod DB. Set "ipod_write_gpod_extended" to True if I should write it.', sender=self)            
         
         
     Device.close(self)
     return True
示例#5
0
    def send_file_to_ipod(self, itdb, fname, tags):
        if not os.path.exists(fname):
            logger.error("File '%s' does not exist" % fname)
            return False

        logger.debug("Copying file '%s' to iPod..." % fname)
        podcasts = gpod.itdb_playlist_podcasts(itdb)
        track = gpod.itdb_track_new()
        track.visible = 1
        track.filetype = "mp3"
        track.ipod_path = fname
        track.album = str(tags['album'])
        track.artist = str(tags['artist'])
        track.title = str(tags['title'])
        track.genre = str(tags['genre'])
        track.tracklen = tags['length']
        track.playcount = 0
        gpod.itdb_track_add(itdb, track, -1)
        gpod.itdb_playlist_add_track(podcasts, track, -1)
        is_copied = gpod.itdb_cp_track_to_ipod(track, fname, None)
        if is_copied:
            logger.info("File '%s' has been successfully copied to iPod" % fname)
        else:
            # roll back
            logger.error("File '%s' could not be copied to iPod" % fname)
            gpod.itdb_playlist_remove_track(podcasts, track)
            gpod.itdb_track_remove(track)
        track = None
        gpod.itdb_write(itdb, None)
        return is_copied
示例#6
0
文件: sync.py 项目: timabell/gpodder
 def close(self):
     if self.itdb is not None:
         self.notify('status', _('Saving iPod database'))
         gpod.itdb_write(self.itdb, None)
         self.itdb = None
         
     Device.close(self)
     return True
示例#7
0
    def close(self):
        """Save and close the database.

        Note: If you are working with an iPod you should normally call
        copy_delayed_files() prior to close() to ensure that newly
        added or updated tracks are transferred to the iPod.

        """

        if not gpod.itdb_write(self._itdb, None):
            raise DatabaseException("Unable to save iTunes database %s" % self)
        itdbext_file = "%s.ext" % (self._itdb_file)
        gtkpod.write(itdbext_file, self, self._itdb_file)
示例#8
0
文件: ipod.py 项目: Babl0lka/libgpod
    def close(self):
        """Save and close the database.

        Note: If you are working with an iPod you should normally call
        copy_delayed_files() prior to close() to ensure that newly
        added or updated tracks are transferred to the iPod.

        """

        if not gpod.itdb_write(self._itdb, None):
            raise DatabaseException("Unable to save iTunes database %s" % self)
        itdbext_file = "%s.ext" % (self._itdb_file)
        gtkpod.write(itdbext_file, self, self._itdb_file)
示例#9
0
文件: peapod.py 项目: huwlynes/peapod
 def synciPod( self, mountPoint ):
     """
     Examine the download log for any files which have been downloaded since
     the last run.  Copies files to iPod.
     """
     mountPoint=mountPoint.encode()
     try:
         itdb=gpod.itdb_parse(mountPoint,None)
     except NameError:
         raise Exception("iPod support requires libgpod library and its python bindings")
     if not itdb:
         raise Exception('Cannot open iTunesDB at mount point: %s' % mountPoint)
     try:
         if os.path.exists( os.path.sep.join( (self.config["homedir"], "download.log") )):
             log = open( os.path.sep.join( (self.config["homedir"], "download.log") ), "r" )
             while 1:
                 line = log.readline()
                 if not line:
                     break
                 try:
                     filename = line.split( "||" )[0]
                     dtime = line.split( "||" )[2]
                 except:
                     logger.warn("Error in download log : %s\n" % line )
                     continue
                 if int( dtime ) > int( self.lasttime ):
                     logger.info("Copying %s to %s" % (filename, mountPoint))
                     if not self.config["dryrun"]:
                         self.copyToiPod(itdb, filename )
             log.close()
             if not self.config["dryrun"]:
                 self.updateLog()
     finally:
         if not self.config["dryrun"]:
             gpod.itdb_write(itdb, None)
             logger.info("Updating iTunesDB...")
示例#10
0
文件: toy_around.py 项目: eggpi/mc723
    print track.artist
    print track.tracklen
    print track.size
    if track.artist == "Placebo":
        print u"%-25s %-20s %-20s %-30s %s" % (track.title,
                                               track.album,
                                               track.artist,
                                               gpod.itdb_filename_on_ipod(track),
                                               repr(u",".join([l.name for l in lists])))

        if gpod.itdb_track_set_thumbnail(track,"/tmp/placebo.jpg") != 0:
            print "Failed to save image thumbnail"
        print track.orig_image_filename

    if track.title == remove_track:
        print "Removing track.."
        print "..disk"
        os.unlink(gpod.itdb_filename_on_ipod(track))
        for l in lists:
            print u"..playlist %s" % l.name
            gpod.itdb_playlist_remove_track(l, track)
        print "..db"
        gpod.itdb_track_unlink(track)
        print "Track removed."

gpod.itdb_write(itdb, None)
print "Saved db"



示例#11
0
 def save(self):
     self._stop_sync()
     gpod.itdb_write(self.db._itdb, None)