Ejemplo n.º 1
0
def download_playlist():
    influxdb.count('spotify.download_playlist_requests')

    playlist_id = request.form.get('playlist_id')
    if playlist_id is None:
        return render_template(
            'show_message.html', message='Invalid request'), 400
    format = request.form.get('format', SUPPORTED_FORMATS[0])
    provider = request.form.get('provider', SUPPORTED_PROVIDERS[0])

    if format not in SUPPORTED_FORMATS:
        current_app.logger.warning(
            'User tried to download a playlist in unsupported format.\n' +
            'Playlist: {}\n'.format(playlist_id) +
            'Format: {}\n'.format(format)
        )
        return render_template(
            'show_message.html', message='Unsupported format'), 400

    if provider not in SUPPORTED_PROVIDERS:
        current_app.logger.warning(
            'User tried to download a playlist with unsupported provider.\n' +
            'Playlist: {}\n'.format(playlist_id) +
            'Format: {}\n'.format(format) +
            'Provider: {}\n'.format(provider)
        )
        return render_template(
            'show_message.html', message='Unsupported provider'), 400

    playlist = models.get_playlist(playlist_id)
    if not playlists.has_playlist('spotify', playlist_id, format):
        playlists.download_playlist.delay(
            playlist, 'spotify', format=format, provider=provider)
        return render_template('show_message.html',
                               message='Your playlist is getting downloaded')

    playlist_checksum = playlists.checksum(playlist['tracks'])
    playlist_data = playlists.get_playlist('spotify', playlist_id, format)

    if playlist_data['checksum'] != playlist_checksum:
        playlists.download_playlist.delay(
            playlist, 'spotify', format=format, provider=provider)
        return render_template('show_message.html',
                               message='Your playlist is getting downloaded')

    influxdb.count('spotify.downloaded_playlists')
    return send_file(
        playlist_data['path'],
        as_attachment=True,
        attachment_filename='{}.zip'.format(playlist['name']),
        mimetype='application/zip'
    )
Ejemplo n.º 2
0
def download_playlist():
    influxdb.count('deezer.download_playlist_requests')

    playlist_id = request.form.get('playlist_id')
    if playlist_id is None:
        return render_template(
            'show_message.html', message='Invalid request'), 400
    format = request.form.get('format', SUPPORTED_FORMATS[0])
    provider = request.form.get('provider', SUPPORTED_PROVIDERS[0])

    if format not in SUPPORTED_FORMATS:
        current_app.logger.warning(
            'User tried to download a playlist in unsupported format.\n' +
            'Playlist: {}\n'.format(playlist_id) +
            'Format: {}\n'.format(format)
        )
        return render_template(
            'show_message.html', message='Unsupported format'), 400

    if provider not in SUPPORTED_PROVIDERS:
        current_app.logger.warning(
            'User tried to download a playlist with unsupported provider.\n' +
            'Playlist: {}\n'.format(playlist_id) +
            'Format: {}\n'.format(format) +
            'Provider: {}\n'.format(provider)
        )
        return render_template(
            'show_message.html', message='Unsupported provider'), 400

    playlist = models.get_playlist(playlist_id)
    if not playlists.has_playlist('deezer', playlist_id, format):
        playlists.download_playlist.delay(
            playlist, 'deezer', format=format, provider=provider)
        return render_template('show_message.html',
                               message='Your playlist is getting downloaded')

    playlist_checksum = playlists.checksum(playlist['tracks'])
    playlist_data = playlists.get_playlist('deezer', playlist_id, format)

    if playlist_data['checksum'] != playlist_checksum:
        playlists.download_playlist.delay(
            playlist, 'deezer', format=format, provider=provider)
        return render_template('show_message.html',
                               message='Your playlist is getting downloaded')

    influxdb.count('deezer.downloaded_playlists')
    return send_file(
        playlist_data['path'],
        as_attachment=True,
        attachment_filename='{}.zip'.format(playlist['name']),
        mimetype='application/zip'
    )
Ejemplo n.º 3
0
 def test_get_playlist_if_playlist_is_being_downloaded(self):
     playlists.cache.set('spotify_some playlist_mp3', 'downloading')
     playlist = playlists.get_playlist('spotify', 'some playlist', 'mp3')
     self.assertIsNone(playlist)
Ejemplo n.º 4
0
 def test_get_playlist(self, cache_get):
     playlists.get_playlist('spotify', 'some playlist', 'mp3')
     cache_get.assert_called_with('spotify_some playlist_mp3')
Ejemplo n.º 5
0
 def test_get_playlist_if_playlist_is_being_downloaded(self):
     playlists.cache.set('spotify_some playlist_mp3', 'downloading')
     playlist = playlists.get_playlist('spotify', 'some playlist', 'mp3')
     self.assertIsNone(playlist)
Ejemplo n.º 6
0
 def test_get_playlist(self, cache_get):
     playlists.get_playlist('spotify', 'some playlist', 'mp3')
     cache_get.assert_called_with('spotify_some playlist_mp3')