コード例 #1
0
ファイル: iPod.py プロジェクト: stafio/XBMC-iPod-plugin
def copyInfo(mp):
    "Copy all info from iPod Database to a local file"
    import gpod
    artists = dict()
    i_itdb = gpod.itdb_parse(mp,None)
    for track in gpod.sw_get_tracks(i_itdb):
        album = track.album
        artist = track.artist
        song = dict()
        song['file']=gpod.itdb_filename_on_ipod(track)
        song['title']=track.title
        song['track number']=track.track_nr
        if artist not in artists:
            artists[artist]=dict()
            artists[artist]['name']=artist
            artists[artist]['albums']=dict()
        if album not in artists[artist]['albums']:
            artists[artist]['albums'][album]=dict()
            artists[artist]['albums'][album]['title']=album
            artists[artist]['albums'][album]['songs']=list()
        artists[artist]['albums'][album]['songs'].append(song)
    pass
    d = shelve.open(ipodDB)
    d[mp]=artists
    d.close()
コード例 #2
0
    def open(self):
        Device.open(self)
        if not gpod_available:
            logger.error(
                'Please install the gpod module to sync with an iPod device.')
            return False
        if not os.path.isdir(self.mountpoint):
            return False

        self.notify('status', _('Opening iPod database'))
        self.itdb = gpod.itdb_parse(self.mountpoint, None)
        if self.itdb is None:
            return False

        self.itdb.mountpoint = self.mountpoint
        self.podcasts_playlist = gpod.itdb_playlist_podcasts(self.itdb)
        self.master_playlist = gpod.itdb_playlist_mpl(self.itdb)

        if self.podcasts_playlist:
            self.notify('status', _('iPod opened'))

            # build the initial tracks_list
            self.tracks_list = self.get_all_tracks()

            return True
        else:
            return False
コード例 #3
0
def copyInfo(mp):
    "Copy all info from iPod Database to a local file"
    import gpod
    artists = dict()
    i_itdb = gpod.itdb_parse(mp, None)
    for track in gpod.sw_get_tracks(i_itdb):
        album = track.album
        artist = track.artist
        song = dict()
        song['file'] = gpod.itdb_filename_on_ipod(track)
        song['title'] = track.title
        song['track number'] = track.track_nr
        if artist not in artists:
            artists[artist] = dict()
            artists[artist]['name'] = artist
            artists[artist]['albums'] = dict()
        if album not in artists[artist]['albums']:
            artists[artist]['albums'][album] = dict()
            artists[artist]['albums'][album]['title'] = album
            artists[artist]['albums'][album]['songs'] = list()
        artists[artist]['albums'][album]['songs'].append(song)
    pass
    d = shelve.open(ipodDB)
    d[mp] = artists
    d.close()
コード例 #4
0
    def _send_to_ipod(self, episodes):
        itdb = gpod.itdb_parse(self.ipod_mount, None)
        if not itdb:
            logger.error('Could not open iPod database at %s' % self.ipod_mount)
            self.ipod_mount = None
            return

        for episode in reversed(episodes):
            filename = episode.local_filename(create=False)
            if filename is None:
                continue

            extension = episode.extension()
            basename = os.path.splitext(os.path.basename(filename))[0]

            if episode.file_type() != 'audio':
                continue

            sent = False  # set to true if file transfer was successful
            # for each file type:
            # 1. extract (id3) tags
            # 2. fix missing tags using available information
            # 3. convert file to mp3 if necessary
            # 4. send to iPod
            if extension.lower() == '.mp3':
                tags = _get_MP3_tags(filename)
                sent = self.send_file_to_ipod(itdb, filename, _fix_tags(tags, episode, basename))
            elif extension.lower() == '.ogg':
                tmpname = _convert_to_mp3(filename)
                if tmpname:
                    sent = self.send_file_to_ipod(itdb, tmpname, _get_OGG_tags(filename))
                    os.unlink(tmpname);
            elif extension.lower() == '.wav':
                tags = {}
                tmpname = _convert_to_mp3(filename)
                if tmpname:
                    sent = self.send_file_to_ipod(itdb, tmpname, _fix_tags({}, episode, basename))
                    os.unlink(tmpname);
            else:
                continue

            if sent:
                episode.mark_old()
                logger.info("File '%s' has been marked 'old'" % filename)
                if not episode.archive:
                  episode.delete_from_disk()
                  logger.info("File '%s' has been deleted from gPodder database and file system"
                              % filename)
                # update UI
                if self.ui:
                  self.ui.episode_list_status_changed([episode])

        gpod.itdb_free(itdb)
コード例 #5
0
ファイル: sync.py プロジェクト: uberchicgeekchick/alacast
    def open(self):
        if not os.path.isdir(self.mountpoint):
            return False

        self.notify('status', _('Opening iPod database'))
        self.itdb=gpod.itdb_parse(self.mountpoint, None)
        if self.itdb is None:
            return False

        self.itdb.mountpoint=self.mountpoint
        self.podcasts_playlist=gpod.itdb_playlist_podcasts(self.itdb)

        if self.podcasts_playlist:
            self.notify('status', _('iPod opened'))
            return True
        else:
            return False
コード例 #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()
コード例 #7
0
ファイル: ipod.py プロジェクト: Babl0lka/libgpod
    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()
コード例 #8
0
ファイル: sync.py プロジェクト: boyska/gpodder
    def open(self):
        Device.open(self)
        if not gpod_available or not os.path.isdir(self.mountpoint):
            return False

        self.notify('status', _('Opening iPod database'))
        self.itdb = gpod.itdb_parse(self.mountpoint, None)
        if self.itdb is None:
            return False

        self.itdb.mountpoint = self.mountpoint
        self.podcasts_playlist = gpod.itdb_playlist_podcasts(self.itdb)
        self.master_playlist = gpod.itdb_playlist_mpl(self.itdb)

        if self.podcasts_playlist:
            self.notify('status', _('iPod opened'))

            # build the initial tracks_list
            self.tracks_list = self.get_all_tracks()

            return True
        else:
            return False
コード例 #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
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this code; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import gpod
import mutagen.mp3

# please specify your iPod mountpoint here..
IPOD_MOUNT = '/mnt/ipod/'

itdb = gpod.itdb_parse( IPOD_MOUNT, None)

if not itdb:
    print 'Cannot open iPod at %s' % ( IPOD_MOUNT )
    sys.exit( 2)

# just for some stats..
counter_upd = 0
counter_left = 0

for track in gpod.sw_get_tracks( itdb):
    if track.artist is None or track.title is None or track.album is None:
        # silently ignore
        continue

    filename = gpod.itdb_filename_on_ipod( track)
コード例 #11
0
ファイル: toy_around.py プロジェクト: eggpi/mc723
import os, os.path
import gpod
import sys

ipod_mount = '/mnt/ipod'

remove_track = "The Dancer"

#dbname = os.path.join(os.environ['HOME'],".gtkpod/iTunesDB")
#dbname = os.path.join(os.environ['HOME'],".gtkpod/local_0.itdb")
dbname = os.path.join(ipod_mount,"iPod_Control/iTunes/iTunesDB")

#itdb = gpod.itdb_parse_file(dbname, None)
# the image related functions require us to use parse and give it the
# mount point; and they won't work without an actual ipod.
itdb = gpod.itdb_parse(ipod_mount, None)
if not itdb:
    print "Failed to read %s" % dbname
    sys.exit(2)
itdb.mountpoint = ipod_mount

if True:
    for playlist in gpod.sw_get_playlists(itdb):
        print playlist.name
        print type(playlist.name)
        print gpod.itdb_playlist_tracks_number(playlist)
        for track in gpod.sw_get_playlist_tracks(playlist):
            print track.title
    
for track in gpod.sw_get_tracks(itdb):
    lists = []
コード例 #12
0
##  License along with this code; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


import gpod
import time
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-m", "--mountpoint", dest="mountpoint",
                  default="/mnt/ipod",
                  help="use iPod at MOUNTPOINT", metavar="MOUNTPOINT")
(options, args) = parser.parse_args()


itdb = gpod.itdb_parse(options.mountpoint, None)
if not itdb:
    print "Failed to read iPod at %s" % options.mountpoint
    sys.exit(2)
itdb.mountpoint = options.mountpoint

for playlist in gpod.sw_get_playlists(itdb):
  if playlist.is_spl:
      n = gpod.sw_get_list_len(playlist.splrules.rules)
      splrules = [gpod.sw_get_rule(playlist.splrules.rules,i) for i in xrange(n)]
      print "Playlist: %s" % playlist.name
      for i in xrange(gpod.sw_get_list_len(playlist.splrules.rules)):
          rule = gpod.sw_get_rule(playlist.splrules.rules, i)
          print "|  field: %4d          action: %4d    |"  % (rule.field,rule.action)
          print "|  string: %25s    |"                     % rule.string
          print "|  fromvalue: %4d    fromdate: %4d    |"  % (rule.fromvalue,rule.fromdate)
コード例 #13
0
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this code; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import gpod
import mutagen.mp3

# please specify your iPod mountpoint here..
IPOD_MOUNT = '/mnt/ipod/'

itdb = gpod.itdb_parse(IPOD_MOUNT, None)

if not itdb:
    print 'Cannot open iPod at %s' % (IPOD_MOUNT)
    sys.exit(2)

# just for some stats..
counter_upd = 0
counter_left = 0

for track in gpod.sw_get_tracks(itdb):
    if track.artist is None or track.title is None or track.album is None:
        # silently ignore
        continue

    filename = gpod.itdb_filename_on_ipod(track)
コード例 #14
0
ファイル: syncipod.py プロジェクト: imclab/syncipod
                new_files.append((full_local_filepath, full_ipod_filepath))
            else:
                if os.path.getsize(full_local_filepath) != os.path.getsize(full_ipod_filepath):
                    if "#" in full_local_filepath:
                        os.rename(full_local_filepath, full_local_filepath.replace("#","_"))
                        full_local_filepath = full_local_filepath.replace("#","_")
                        relative_filepath = relative_filepath.replace("#","_")
                    print "Copying: " + full_local_filepath
                    subprocess.call(["gvfs-copy", full_local_filepath, "afc://" + uuid + "/" + ipod_path_prefix + "/" + relative_filepath])
                    new_files.append((full_local_filepath, full_ipod_filepath))
                    deleted_files.append(full_ipod_filepath[len(mp):].replace('/',':'))

### Done syncing the music directory with the ipod. Now let's rebuild the database with
### the new changes.

db = gpod.itdb_parse(mp, None)

### First delete the removed/modified files from ipod database. This is an annoying part because we can only lookup track by id
### but we don't have an id, so we basically need to check every track to see if its been deleted/modified
if deleted_files:   
    print "Removing deleted & outdated tracks from the ipod database"
    tracks = gpod.sw_get_tracks(db)
    for track in tracks:
        if track.ipod_path in deleted_files:
        # Remove it from any playlists it might be on
            for pl in gpod.sw_get_playlists(db):
                if gpod.itdb_playlist_contains_track(pl, track):
                    gpod.itdb_playlist_remove_track(pl, track)
    
            # Remove it from the master playlist
            gpod.itdb_playlist_remove_track(gpod.itdb_playlist_mpl(db), track)
コード例 #15
0
##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import gpod
import time
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-m",
                  "--mountpoint",
                  dest="mountpoint",
                  default="/mnt/ipod",
                  help="use iPod at MOUNTPOINT",
                  metavar="MOUNTPOINT")
(options, args) = parser.parse_args()

itdb = gpod.itdb_parse(options.mountpoint, None)
if not itdb:
    print "Failed to read iPod at %s" % options.mountpoint
    sys.exit(2)
itdb.mountpoint = options.mountpoint

for playlist in gpod.sw_get_playlists(itdb):
    if playlist.is_spl:
        n = gpod.sw_get_list_len(playlist.splrules.rules)
        splrules = [
            gpod.sw_get_rule(playlist.splrules.rules, i) for i in xrange(n)
        ]
        print "Playlist: %s" % playlist.name
        for i in xrange(gpod.sw_get_list_len(playlist.splrules.rules)):
            rule = gpod.sw_get_rule(playlist.splrules.rules, i)
            print "|  field: %4d          action: %4d    |" % (rule.field,