Ejemplo n.º 1
0
class Artist(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name
Ejemplo n.º 2
0
class Album(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    year = db.Column(db.DATETIME)
    duration = db.Column(db.Integer) # in seconds
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
    artist = db.relationship('Artist', backref=db.backref('albums', lazy='dynamic'))

    def __init__(self, name, year=None, duration=None):
        self.name = name
        self.year = year
        self.duration = duration

    def __repr__(self):
        return self.name
Ejemplo n.º 3
0
class Track(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    pub_year = db.Column(db.String(50))
    duration = db.Column(db.Integer)  # in seconds
    type = db.Column(db.String(50))
    bitrate = db.Column(db.Integer)  # in kbps
    file_url = db.Column(db.String(1000))
    genre = db.Column(db.String(50))
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
    album_id = db.Column(db.Integer, db.ForeignKey('album.id'))
    # cover = image_attachment('Cover')

    artist = db.relationship('Artist',
                             backref=db.backref('tracks', lazy='dynamic'))
    album = db.relationship('Album',
                            backref=db.backref('tracks', lazy='dynamic'))

    __mapper_args__ = {'polymorphic_identity': 'track', 'polymorphic_on': type}

    def __init__(self,
                 name=None,
                 year=None,
                 duration=None,
                 artist=None,
                 bitrate=None,
                 url=None,
                 album=None,
                 genre=None):
        self.name = name
        self.pub_year = year
        self.duration = duration
        self.artist = artist
        self.bitrate = bitrate
        self.file_url = url
        self.genre = genre

    def __repr__(self):
        return self.name
Ejemplo n.º 4
0
class LocalTrack(Track):
    path = db.Column(db.String(1000))

    __mapper_args__ = {
        'polymorphic_identity': 'local_track',
    }

    def __init__(self,
                 name=None,
                 year=None,
                 duration=None,
                 artist=None,
                 path=None,
                 bitrate=None,
                 url=None,
                 album=None,
                 genre=None):
        super(LocalTrack, self).__init__(name, year, duration, artist, album,
                                         bitrate, url, genre)
        self.path = path

    def __init__(self, path):
        audio = EasyID3(path)
        f = MP3(path)
        try:
            self.name = audio['title'][0]
        except KeyError:
            self.name = os.path.basename(os.path.splitext(audio.filename)[0])
        try:
            self.pub_year = audio['date'][0]
        except KeyError:
            pass
        try:
            self.artist = Tools.get_or_create(db.session,
                                              Artist,
                                              name=audio['artist'][0])
        except KeyError:
            pass
        try:
            self.path = path
        except KeyError:
            pass
        try:
            self.bitrate = f.info.bitrate / 1000
        except KeyError:
            pass
        try:
            self.album = Tools.get_or_create(db.session,
                                             Album,
                                             name=audio['album'][0])
            self.album.artist = self.artist
        except KeyError:
            pass
        try:
            self.genre = audio['genre'][0]
        except KeyError:
            pass
        # try:
        #     with store_context(store):
        #         self.cover.from_blob(image_binary)
        # except:
        #     pass
        self.duration = f.info.length
        self.file_url = url_for(
            'static', filename=path[string.rindex(path, 'library/'):])
Ejemplo n.º 5
0
class Cover(db.Model, Image):

    user_id = db.Column(db.Integer,
                        db.ForeignKey('Track.id'),
                        primary_key=True)
    user = db.relationship('Track')