def test_main(self): v = fsnative(u"foo") self.assertTrue(is_fsnative(v)) v2 = glib2fsnative(fsnative2glib(v)) self.assertTrue(is_fsnative(v2)) self.assertEqual(v, v2) v3 = bytes2fsnative(fsnative2bytes(v)) self.assertTrue(is_fsnative(v3)) self.assertEqual(v, v3)
def test_parse_onesong(self): h, name = mkstemp() os.close(h) with open(name, "wb") as f: target = self.prefix target += fsnative2glib(os.path.join(DATA_DIR, "silence-44-s.ogg")) f.write(target) list = self.Parse(name) os.unlink(name) self.failUnlessEqual(len(list), 1) self.failUnlessEqual(list[0]("title"), "Silence") list.delete()
def copy(self, parent_widget, song): if self.__load_db() is None: return False track = gpod.itdb_track_new() # All values should be utf-8 encoded strings # Filepaths should be encoded with the fs encoding # Either combine tags with comma, or only take the first value if self['all_tags']: tag = song.comma else: tag = lambda key: (song.list(key) or ('',))[0] title = tag('title') if self['title_version'] and song('version'): title = " - ".join([title, song('version')]) track.title = encode(title) album = tag('album') if self['album_part'] and song('discsubtitle'): album = " - ".join([album, song('discsubtitle')]) track.album = encode(album) # String keys for key in ['artist', 'genre', 'grouping', 'composer', 'albumartist']: if hasattr(track, key): # albumartist since libgpod-0.4.2 setattr(track, key, encode(tag(key))) # Sort keys (since libgpod-0.5.0) for key in ['artist', 'album', 'albumartist']: if hasattr(track, 'sort_' + key): setattr(track, 'sort_' + key, encode(tag(key + 'sort'))) # Numeric keys for key in ['bitrate', 'playcount', 'year']: try: setattr(track, key, int(song('~#' + key))) except ValueError: continue # Numeric keys where the names differ for key, value in { 'cd_nr': song('~#disc'), 'cds': song('~#discs'), 'rating': min(100, song('~#rating') * 100), 'time_added': self.__mactime(time.time()), 'time_modified': self.__mactime(mtime(song('~filename'))), 'track_nr': song('~#track'), 'tracklen': song('~#length') * 1000, 'tracks': song('~#tracks'), 'size': filesize(song('~filename')), 'soundcheck': self.__soundcheck(song), }.items(): try: setattr(track, key, int(value)) except ValueError: continue track.filetype = encode(song('~format')) track.comment = encode(fsdecode(song('~filename'))) # Associate a cover with the track if self['covers']: cover = app.cover_manager.get_cover(song) if cover: # libgpod will copy the file later when the iTunesDB # is saved, so we have to keep a reference around in # case the cover is a temporary file. self.__covers.append(cover) gpod.itdb_track_set_thumbnails( track, fsnative2glib(cover.name)) # Add the track to the master playlist gpod.itdb_track_add(self.__itdb, track, -1) master = gpod.itdb_playlist_mpl(self.__itdb) gpod.itdb_playlist_add_track(master, track, -1) # Copy the actual file if gpod.itdb_cp_track_to_ipod(track, song['~filename'], None) == 1: return IPodSong(track) else: return False
def copy(self, parent_widget, song): if self.__load_db() is None: return False track = gpod.itdb_track_new() # All values should be utf-8 encoded strings # Filepaths should be encoded with the fs encoding # Either combine tags with comma, or only take the first value if self['all_tags']: tag = song.comma else: tag = lambda key: (song.list(key) or ('', ))[0] title = tag('title') if self['title_version'] and song('version'): title = " - ".join([title, song('version')]) track.title = encode(title) album = tag('album') if self['album_part'] and song('discsubtitle'): album = " - ".join([album, song('discsubtitle')]) track.album = encode(album) # String keys for key in ['artist', 'genre', 'grouping', 'composer', 'albumartist']: if hasattr(track, key): # albumartist since libgpod-0.4.2 setattr(track, key, encode(tag(key))) # Sort keys (since libgpod-0.5.0) for key in ['artist', 'album', 'albumartist']: if hasattr(track, 'sort_' + key): setattr(track, 'sort_' + key, encode(tag(key + 'sort'))) # Numeric keys for key in ['bitrate', 'playcount', 'year']: try: setattr(track, key, int(song('~#' + key))) except ValueError: continue # Numeric keys where the names differ for key, value in { 'cd_nr': song('~#disc'), 'cds': song('~#discs'), 'rating': min(100, song('~#rating') * 100), 'time_added': self.__mactime(time.time()), 'time_modified': self.__mactime(mtime(song('~filename'))), 'track_nr': song('~#track'), 'tracklen': song('~#length') * 1000, 'tracks': song('~#tracks'), 'size': filesize(song('~filename')), 'soundcheck': self.__soundcheck(song), }.items(): try: setattr(track, key, int(value)) except ValueError: continue track.filetype = encode(song('~format')) track.comment = encode(fsdecode(song('~filename'))) # Associate a cover with the track if self['covers']: cover = app.cover_manager.get_cover(song) if cover: # libgpod will copy the file later when the iTunesDB # is saved, so we have to keep a reference around in # case the cover is a temporary file. self.__covers.append(cover) gpod.itdb_track_set_thumbnails(track, fsnative2glib(cover.name)) # Add the track to the master playlist gpod.itdb_track_add(self.__itdb, track, -1) master = gpod.itdb_playlist_mpl(self.__itdb) gpod.itdb_playlist_add_track(master, track, -1) # Copy the actual file if gpod.itdb_cp_track_to_ipod(track, song['~filename'], None) == 1: return IPodSong(track) else: return False
def copy(self, parent_widget, song): if self.__load_db() is None: return False track = gpod.itdb_track_new() # All values should be utf-8 encoded strings # Filepaths should be encoded with the fs encoding # Either combine tags with comma, or only take the first value if self["all_tags"]: tag = song.comma else: tag = lambda key: (song.list(key) or ("",))[0] title = tag("title") if self["title_version"] and song("version"): title = " - ".join([title, song("version")]) track.title = encode(title) album = tag("album") if self["album_part"] and song("discsubtitle"): album = " - ".join([album, song("discsubtitle")]) track.album = encode(album) # String keys for key in ["artist", "genre", "grouping", "composer", "albumartist"]: if hasattr(track, key): # albumartist since libgpod-0.4.2 setattr(track, key, encode(tag(key))) # Sort keys (since libgpod-0.5.0) for key in ["artist", "album", "albumartist"]: if hasattr(track, "sort_" + key): setattr(track, "sort_" + key, encode(tag(key + "sort"))) # Numeric keys for key in ["bitrate", "playcount", "year"]: try: setattr(track, key, int(song("~#" + key))) except ValueError: continue # Numeric keys where the names differ for key, value in { "cd_nr": song("~#disc"), "cds": song("~#discs"), "rating": min(100, song("~#rating") * 100), "time_added": self.__mactime(time.time()), "time_modified": self.__mactime(mtime(song("~filename"))), "track_nr": song("~#track"), "tracklen": song("~#length") * 1000, "tracks": song("~#tracks"), "size": filesize(song("~filename")), "soundcheck": self.__soundcheck(song), }.items(): try: setattr(track, key, int(value)) except ValueError: continue track.filetype = encode(song("~format")) track.comment = encode(fsdecode(song("~filename"))) # Associate a cover with the track if self["covers"]: cover = app.cover_manager.get_cover(song) if cover: # libgpod will copy the file later when the iTunesDB # is saved, so we have to keep a reference around in # case the cover is a temporary file. self.__covers.append(cover) gpod.itdb_track_set_thumbnails(track, fsnative2glib(cover.name)) # Add the track to the master playlist gpod.itdb_track_add(self.__itdb, track, -1) master = gpod.itdb_playlist_mpl(self.__itdb) gpod.itdb_playlist_add_track(master, track, -1) # Copy the actual file if gpod.itdb_cp_track_to_ipod(track, song["~filename"], None) == 1: return IPodSong(track) else: return False