Example #1
0
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        raise BadRequest("Didn't provide `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)
Example #2
0
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        raise BadRequest("Didn't provide `release_group_id`!")
    try:
        release_group = mb_release_group.get_release_group_by_id(
            release_group_id)
    except mb_exceptions.NoDataFoundException:
        flash.error(
            gettext("Only existing release groups can be mapped to Spotify!"))
        return redirect(url_for('search.index'))

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

    try:
        spotify_id = parse_spotify_id(spotify_ref)
    except UnsupportedSpotifyReferenceTypeException:
        flash.error(
            gettext(
                "You need to specify a correct link to this album on Spotify!")
        )
        return redirect(
            url_for('.spotify_add', release_group_id=release_group_id))
    except Exception:
        raise BadRequest("Could not parse Spotify ID!")

    try:
        album = spotify_api.get_album(spotify_id)
    except ExternalServiceException:
        flash.error(
            gettext("You need to specify existing album from Spotify!"))
        return redirect(
            url_for('.spotify_add', 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).
        res, error = mbspotify.add_mapping(release_group_id,
                                           'spotify:album:%s' % spotify_id,
                                           current_user.id)
        if res:
            flash.success(gettext("Spotify mapping has been added!"))
        else:
            flash.error(gettext("Could not add Spotify mapping!"))
            current_app.logger.error(
                "Failed to create new Spotify mapping! Error: {}".format(
                    error))
        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)
Example #3
0
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        raise BadRequest("Didn't provide `release_group_id`!")
    release_group = musicbrainz.get_release_group_by_id(release_group_id)
    if not release_group:
        flash.error(
            gettext("Only existing release groups can be mapped to Spotify!"))
        return redirect(url_for('search.index'))

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

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

    try:
        album = spotify_api.get_album(spotify_id)
    except ExternalServiceException:
        flash.error(
            gettext("You need to specify existing album from Spotify!"))
        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.success(gettext("Spotify mapping has been added!"))
        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)
Example #4
0
def spotify_confirm():
    """Confirmation page for adding new Spotify mapping."""
    release_group_id = request.args.get('release_group_id')
    if not release_group_id:
        raise BadRequest("Didn't provide `release_group_id`!")
    try:
        release_group = mb_release_group.get_release_group_by_id(release_group_id)
    except mb_exceptions.NoDataFoundException:
        flash.error(gettext("Only existing release groups can be mapped to Spotify!"))
        return redirect(url_for('search.index'))

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

    try:
        spotify_id = parse_spotify_id(spotify_ref)
    except UnsupportedSpotifyReferenceTypeException:
        flash.error(gettext("You need to specify a correct link to this album on Spotify!"))
        return redirect(url_for('.spotify_add', release_group_id=release_group_id))
    except Exception:
        raise BadRequest("Could not parse Spotify ID!")

    try:
        album = spotify_api.get_album(spotify_id)
    except ExternalServiceException:
        flash.error(gettext("You need to specify existing album from Spotify!"))
        return redirect(url_for('.spotify_add', 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).
        res, error = mbspotify.add_mapping(release_group_id, 'spotify:album:%s' % spotify_id, current_user.id)
        if res:
            flash.success(gettext("Spotify mapping has been added!"))
        else:
            flash.error(gettext("Could not add Spotify mapping!"))
            current_app.logger.error("Failed to create new Spotify mapping! Error: {}".format(error))
        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)