Example #1
0
def spotify():
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        return redirect(url_for('frontend.index'))

    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(
            gettext("Only existing release groups can be mapped to Spotify!"),
            'error')
        return redirect(url_for('search.index'))

    page = int(request.args.get('page', default=1))
    if page < 1:
        return redirect(url_for('.spotify'))
    limit = 16
    offset = (page - 1) * limit

    # Removing punctuation from the string
    punctuation_map = dict((ord(char), None) for char in string.punctuation)
    query = unicode(release_group['title']).translate(punctuation_map)
    # Searching...
    response = spotify_api.search(query, 'album', limit, offset).get('albums')
    return render_template('mapping/spotify.html',
                           release_group=release_group,
                           search_results=response.get('items'),
                           page=page,
                           limit=limit,
                           count=response.get('total'))
def spotify_report():
    """Endpoint for reporting incorrect Spotify mappings.

    Shows confirmation page before submitting report to mbspotify.
    """
    release_group_id = request.args.get('release_group_id')
    spotify_id = request.args.get('spotify_id')
    spotify_uri = "spotify:album:" + spotify_id

    # Checking if release group exists
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(gettext("Can't find release group with that ID!"), 'error')
        return redirect(url_for('.spotify_list', release_group_id=release_group_id))

    # Checking if release group is mapped to Spotify
    spotify_mappings = mbspotify.mappings(str(release_group_id))
    if not (spotify_uri in spotify_mappings):
        flash(gettext("This album is not mapped to Spotify yet!"), 'error')
        return redirect(url_for('.spotify_list', release_group_id=release_group_id))

    if request.method == 'POST':
        mbspotify.vote(release_group_id, spotify_uri, current_user.id)
        flash(gettext("Incorrect Spotify mapping has been reported. Thank you!"), 'success')
        return redirect(url_for('.spotify_list', release_group_id=release_group_id))

    else:
        album = spotify_api.get_album(spotify_id)
        if not album or album.get('error'):
            flash(gettext("You need to specify existing album from Spotify!"), 'error')
            return redirect(url_for('.spotify_list', release_group_id=release_group_id))

        return render_template('mapping/report.html', release_group=release_group, spotify_album=album)
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(gettext("Only existing release groups can be mapped to Spotify!"), 'error')
        return redirect(url_for('search.index'))

    spotify_ref = request.args.get('spotify_ref', default=None)
    if not spotify_ref:
        flash(gettext("You need to select an album from Spotify!"), 'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    spotify_id = parse_spotify_id(spotify_ref)
    if not spotify_id:
        flash(gettext("You need to specify a correct link to this album on Spotify!"), 'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    album = spotify_api.get_album(spotify_id)
    if not album or album.get('error'):
        flash(gettext("You need to specify existing album from Spotify!"), 'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    if request.method == 'POST':
        # TODO(roman): Check values that are returned by add_mapping (also take a look at related JS).
        mbspotify.add_mapping(release_group_id, 'spotify:album:%s' % spotify_id, current_user.id)
        flash(gettext("Spotify mapping has been added!"), 'success')
        return redirect(url_for('.spotify_list', release_group_id=release_group_id))

    return render_template('mapping/confirm.html', release_group=release_group, spotify_album=album)
def spotify_list(release_group_id):
    """This view lists all Spotify albums mapped to a specified release group."""
    spotify_mappings = mbspotify.mappings(str(release_group_id))

    # Converting Spotify URIs to IDs
    spotify_ids = []
    for mapping in spotify_mappings:
        spotify_ids.append(mapping[14:])

    if len(spotify_ids) > 0:
        spotify_albums = spotify_api.get_multiple_albums(spotify_ids)
    else:
        spotify_albums = []
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        raise NotFound("Can't find release group with a specified ID.")
    return render_template('mapping/list.html', spotify_albums=spotify_albums,
                           release_group=release_group)
Example #5
0
def spotify_list(release_group_id):
    """This view lists all Spotify albums mapped to a specified release group."""
    spotify_mappings = mbspotify.mappings(str(release_group_id))

    # Converting Spotify URIs to IDs
    spotify_ids = []
    for mapping in spotify_mappings:
        spotify_ids.append(mapping[14:])

    if len(spotify_ids) > 0:
        spotify_albums = spotify_api.get_multiple_albums(spotify_ids)
    else:
        spotify_albums = []
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        raise NotFound("Can't find release group with a specified ID.")
    return render_template('mapping/list.html',
                           spotify_albums=spotify_albums,
                           release_group=release_group)
Example #6
0
def spotify_report():
    """Endpoint for reporting incorrect Spotify mappings.

    Shows confirmation page before submitting report to mbspotify.
    """
    release_group_id = request.args.get('release_group_id')
    spotify_id = request.args.get('spotify_id')
    spotify_uri = "spotify:album:" + spotify_id

    # Checking if release group exists
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(gettext("Can't find release group with that ID!"), 'error')
        return redirect(
            url_for('.spotify_list', release_group_id=release_group_id))

    # Checking if release group is mapped to Spotify
    spotify_mappings = mbspotify.mappings(str(release_group_id))
    if not (spotify_uri in spotify_mappings):
        flash(gettext("This album is not mapped to Spotify yet!"), 'error')
        return redirect(
            url_for('.spotify_list', release_group_id=release_group_id))

    if request.method == 'POST':
        mbspotify.vote(release_group_id, spotify_uri, current_user.id)
        flash(
            gettext("Incorrect Spotify mapping has been reported. Thank you!"),
            'success')
        return redirect(
            url_for('.spotify_list', release_group_id=release_group_id))

    else:
        album = spotify_api.get_album(spotify_id)
        if not album or album.get('error'):
            flash(gettext("You need to specify existing album from Spotify!"),
                  'error')
            return redirect(
                url_for('.spotify_list', release_group_id=release_group_id))

        return render_template('mapping/report.html',
                               release_group=release_group,
                               spotify_album=album)
Example #7
0
def entity(id):
    id = str(id)
    release_group = musicbrainz.get_release_group_by_id(id)
    if not release_group:
        raise NotFound(
            gettext(
                "Sorry, we couldn't find a release group with that MusicBrainz ID."
            ))
    if len(release_group['release-list']) > 0:
        release = musicbrainz.get_release_by_id(
            release_group['release-list'][0]['id'])
    else:
        release = None
    spotify_mappings = mbspotify.mappings(id)
    limit = int(request.args.get('limit', default=10))
    offset = int(request.args.get('offset', default=0))
    if current_user.is_authenticated():
        my_reviews, my_count = Review.list(entity_id=id,
                                           entity_type='release_group',
                                           user_id=current_user.id)
        if my_count != 0:
            my_review = my_reviews[0]
        else:
            my_review = None
    else:
        my_review = None
    reviews, count = Review.list(entity_id=id,
                                 entity_type='release_group',
                                 sort='rating',
                                 limit=limit,
                                 offset=offset)
    return render_template('release_group.html',
                           id=id,
                           release_group=release_group,
                           reviews=reviews,
                           release=release,
                           my_review=my_review,
                           spotify_mappings=spotify_mappings,
                           limit=limit,
                           offset=offset,
                           count=count)
Example #8
0
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(
            gettext("Only existing release groups can be mapped to Spotify!"),
            'error')
        return redirect(url_for('search.index'))

    spotify_ref = request.args.get('spotify_ref', default=None)
    if not spotify_ref:
        flash(gettext("You need to select an album from Spotify!"), 'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    spotify_id = parse_spotify_id(spotify_ref)
    if not spotify_id:
        flash(
            gettext(
                "You need to specify a correct link to this album on Spotify!"
            ), 'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    album = spotify_api.get_album(spotify_id)
    if not album or album.get('error'):
        flash(gettext("You need to specify existing album from Spotify!"),
              'error')
        return redirect(url_for('.spotify', release_group_id=release_group_id))

    if request.method == 'POST':
        # TODO(roman): Check values that are returned by add_mapping (also take a look at related JS).
        mbspotify.add_mapping(release_group_id,
                              'spotify:album:%s' % spotify_id, current_user.id)
        flash(gettext("Spotify mapping has been added!"), 'success')
        return redirect(
            url_for('.spotify_list', release_group_id=release_group_id))

    return render_template('mapping/confirm.html',
                           release_group=release_group,
                           spotify_album=album)
def spotify():
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        return redirect(url_for('frontend.index'))

    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash(gettext("Only existing release groups can be mapped to Spotify!"), 'error')
        return redirect(url_for('search.index'))

    page = int(request.args.get('page', default=1))
    if page < 1:
        return redirect(url_for('.spotify'))
    limit = 16
    offset = (page - 1) * limit

    # Removing punctuation from the string
    punctuation_map = dict((ord(char), None) for char in string.punctuation)
    query = unicode(release_group['title']).translate(punctuation_map)
    # Searching...
    response = spotify_api.search(query, 'album', limit, offset).get('albums')
    return render_template('mapping/spotify.html', release_group=release_group, search_results=response.get('items'),
                           page=page, limit=limit, count=response.get('total'))
def entity(id):
    id = str(id)
    release_group = musicbrainz.get_release_group_by_id(id)
    if not release_group:
        raise NotFound(gettext("Sorry, we couldn't find a release group with that MusicBrainz ID."))
    if len(release_group['release-list']) > 0:
        release = musicbrainz.get_release_by_id(release_group['release-list'][0]['id'])
    else:
        release = None
    spotify_mappings = mbspotify.mappings(id)
    limit = int(request.args.get('limit', default=10))
    offset = int(request.args.get('offset', default=0))
    if current_user.is_authenticated():
        my_reviews, my_count = Review.list(entity_id=id, entity_type='release_group', user_id=current_user.id)
        if my_count != 0:
            my_review = my_reviews[0]
        else:
            my_review = None
    else:
        my_review = None
    reviews, count = Review.list(entity_id=id, entity_type='release_group', sort='rating', limit=limit, offset=offset)
    return render_template('release_group.html', id=id, release_group=release_group, reviews=reviews,
                           release=release, my_review=my_review, spotify_mappings=spotify_mappings,
                           limit=limit, offset=offset, count=count)