Exemple #1
0
def artists():
    """A list of all artists in the database."""
    return render_template(
        'list.html',
        title='Καλλιτέχνες',
        objects=Artist.all(),
        detail_url='main.artist',
        admin=session.get('logged_in'),
    )
Exemple #2
0
def index():
    """Index all data into elasticsearch."""
    elastic.create_index()

    def index_all(items, name):
        with click.progressbar(items, label=f"Indexing {name}") as bar:
            for item in bar:
                elastic.index(item)

    index_all(Song.all(frommetadata=False), 'songs')
    index_all(Artist.all(), 'artists')
    index_all(Scale.all(), 'scales')
Exemple #3
0
def artist(slug):
    """A list of all songs from given artist."""
    artist = Artist.get_or_404(slug)

    if artist.num == 1:
        return redirect(url_for('main.song', slug=artist.songs[0].slug))

    return render_template(
        'index.html',
        title=artist.name,
        songs=artist.songs,
        admin=session.get('logged_in'),
        artist=True,
    )
Exemple #4
0
def song(slug, semitones=None, root=None):
    """A song optionally transposed by given semitones."""
    logging.info(f"Got request for song {slug}")

    playlist: Playlist = get_selected_playlist()
    if playlist and not root:
        try:
            root = playlist.roots[slug]
        except KeyError:
            pass

    logging.debug("Got selected playlist")

    if session.get('logged_in') and request.args.get('random') != 'true':
        Session.get().add_song(slug)

    logging.debug("Added song to session")

    song = Song.get_or_404(slug, semitones=semitones, root=root, unicode=True)
    artist = Artist.get(song.artist_slug)

    logging.debug("Read song data from disk")

    related_songs = get_related(slug)
    if related_songs is not None:
        related_title = 'Σχετικά'
    else:
        related_songs = [song for song in artist.songs if song.slug != slug]
        related_title = ('Άλλα παραδοσιακά' if song.artist == 'Παραδοσιακό'
                         else f'Άλλα του {artist.genitive}')

    logging.debug("Rendering\n")

    return render_template(
        'song.html',
        song=song,
        artist=artist,
        songs=related_songs,
        related_title=related_title,
        semitones=semitones,
        root=root,
        admin=session.get('logged_in'),
    )
Exemple #5
0
def search():
    query = request.args.get('q')
    if not query:
        return redirect(url_for('main.index'))

    songs = list(Song.search(query))

    if len(songs) > 1:
        return render_template(
            'index.html',
            title=query,
            songs=songs,
            admin=session.get('logged_in'),
        )

    if len(songs) == 1:
        return redirect(url_for('main.song', slug=songs[0].slug))

    artists = list(Artist.search(query))

    if len(artists) > 1:
        return render_template(
            'list.html',
            title=query,
            objects=artists,
            detail_url='main.artist',
            admin=session.get('logged_in'),
        )

    if len(artists) == 1:
        return redirect(url_for('main.artist', slug=artists[0].slug))

    if any(scale.name == query for scale in Scale.all()):
        scale = Scale.get(query)
        return redirect(url_for('main.scale', slug=scale.slug))

    abort(404)