Exemplo n.º 1
0
   def __setitem__(self, key, value):
      data.Data.__setitem__(self, key, value)
      if self['type'] not in musicio.setkeys or key in musicio.setkeys[self['type']]:
         musicio.writesong(self['path'], item)
   
   def update(self, items):
      """Updates the song metadata with the dict items."""
      data.Data.setitems(self, items)
      filechanges = dict(((k,v) for k, v in items.items() if self['type'] not in musicio.setkeys or k in musicio.setkeys[self['type']]))
      musicio.writesong(self['path'], filechanges)

   def __str__(self):
      return "%s - %s - %s" % (self.get('title', ''),
                               self.get('artist', ''),
                               self.get('album', ''))
      
   @classmethod
   def fromfile(cls, filepath):
      """Returns a Song object created from the song at the given location."""
      songdict = musicio.readsong(filepath)
      if not songdict:
         return None
      else:
         return Song(songdict, new=True)

def fromfile(filepath):
   return Song.fromfile(filepath)

data.datasetup(Song)
songs = Song.items
Exemplo n.º 2
0
        data.Data.__init__(self, d, *args, **kwargs)

    def __str__(self):
        return self["title"]

    @classmethod
    def getid(cls, title, name, create=False):
        """Returns the id of the named album by the given artist. If create is true,
         added the album if it does not exist."""
        rows = db.sql(
            """SELECT al.id
FROM %s AS al
JOIN Artists ar ON ar.id = al.artistid
WHERE al.title = :title AND ar.name = :name"""
            % (cls.table),
            {"title": title, "name": name},
        )
        if len(rows) > 0:
            return rows[0]["id"]
        elif create:
            artistid = artist.Artist.getid(name, create=True)
            a = Album({"artistid": artistid, "title": title}, new=True)
            return a.id
        else:
            # Not found
            return None


data.datasetup(Album)
albums = Album.items