Esempio n. 1
0
def track_from_upload(name, **kwargs) -> Optional[Track]:
    plugin_description = memcache.get("upload.plugins").get(name)

    if plugin_description is None:
        return Response.INVALID_PLUGIN

    plugin = __load_plugin(name, plugin_description["path"])
    track_record = plugin.handle(**kwargs)  # type: TrackRecord

    if track_record.backend is None or track_record.mrl is None:
        return Response.PLUGIN_ERROR

    if tracks.exists(track_record.title, track_record.artist,
                     track_record.album):
        __cleanup(track_record.mrl)
        return Response.TRACK_EXISTS

    track = None
    with persistance():

        track = tracks.get_or_create(track_record.title, track_record.artist,
                                     track_record.album)

        track.backend = track_record.backend
        track.mrl = track_record.mrl

        # TODO: tag info
        db_session.add(track)

    return track
Esempio n. 2
0
def get_or_create(name: str) -> Artist:

    artist = db_session.query(Artist).filter(Artist.name == name).first()

    if artist is None:
        with persistance():
            artist = Artist(name=name)
            db_session.add(artist)

    return artist
Esempio n. 3
0
def get_or_create(title: str, artist: str) -> Album:

    a = artists.get_or_create(artist)

    album = db_session.query(Album)\
        .filter(Album.title == title)\
        .filter(Album.artist == a) \
        .first()

    if album is None:
        with persistance():
            album = Album(title=title)
            album.artist = a
            db_session.add(album)

    return album
Esempio n. 4
0
def get_or_create(title: str, artist: str, album: str) -> Track:

    a = albums.get_or_create(album, artist)

    t = db_session.query(Track)\
        .filter(Track.title == title)\
        .filter(Track.album == a)\
        .filter(Track.artist == a.artist)\
        .first()

    if t is None:
        with persistance():
            t = Track(title=title)
            t.album = a
            t.artist = t.album.artist
            db_session.add(t)

    if t.status is None:
        with persistance():
            s = Status(t)
            db_session.add(s)

    return t
Esempio n. 5
0
def create(username: str, password_hashed: bytes, password_salt: bytes) -> User:
    with persistance():
        u = User(username=username, password_hash=password_hashed, password_salt=password_salt)
        db_session.add(u)

    return u