Beispiel #1
0
    def download(self, path):
        print self.id, self.title
        debug('id = ' + self.id)
        debug('url = ' + self.url)

        if not hasattr(self, 'fileUrl'):
            print 'File URL unavailable.'
            return
            
        debug('fileUrl = ' + self.fileUrl)
        
        tmpname = path + self.id + '.tmp'
        realname = path + self.id + '.' + self.title + '.' + self.fileFormat

        # This is where the downloading actually happens.
        try:
            urlretrieve(self.fileUrl, tmpname, download_progress)
        except:
            if access(tmpname, F_OK):
                remove(tmpname)
            raise

        # Update ID3 info.
        print 'Updating ID3 info...'
        tag = Tag()
        tag.link(tmpname)
        tag.setVersion(ID3_V2_4)
        tag.setTextEncoding(UTF_8_ENCODING)
        tag.setTitle(self.title)
        if self.cover is not None:
            tag.addImage(3, self.cover)
        if self.album is not None: 
            tag.setAlbum(self.album.title)
            if self.album.artist is not None:
                tag.setArtist(self.album.artist.title)
        tag.removeComments()
        tag.update(ID3_V2_4)

        # Save with real name.
        rename(tmpname, realname)

        print 'Done.'