Ejemplo n.º 1
0
def import_file(filename):
    print 'Processing %s' % filename
    #TODO: Use a transaction here to roll back on exception
    try:
        md = get_metadata(filename)

        if not md:
            return

        genre = md.genre  and get_or_create_genre(md.genre)   or None
        artist = md.artist and get_or_create_artist(md.artist) or None
        album = md.album  and get_or_create_album(md.album)   or None

        song   = Song()
        song.path = filename
        song.genre = genre
        song.artist = artist
        song.album = album
        album.artist = artist

        if md.title:
            song.title = md.title

        if md.year:
            song.year = md.year

        if md.trackno:
            song.track = md.trackno

        if md.duration:
            song.length = md.duration

        song.modified = os.path.getmtime(filename)
        song.size = os.path.getsize(filename)
        song.playcount = 0
        song.user_rating = 2.5
        song.time_added = datetime.now()
        song.blacklisted = False

        session.save(song)
        session.flush()
    except:
        pass
Ejemplo n.º 2
0
    def open(self, filename):
        song = media.load(filename)

        if not is_audio_file('', song):
            raise MediaError('File "%s" is not an audio or audio only file' % filename)

        playing = False
        if self._player and self._player.playing:
            playing = True

        self.stop()

        self._lock()
        try:
            self._player = None
        finally:
            self._unlock()

        self._filename = filename
        self._song = song
        self._metadata = get_metadata('', song)

        if playing:
            self.play()
Ejemplo n.º 3
0
 def metadata(self, refresh=False):
     if not self._metadata or refresh:
         self._metadata = get_metadata(self.filename)
     return self._metadata