streamrip icon indicating copy to clipboard operation
streamrip copied to clipboard

[BUG] Tracks download not working with direct import

Open suntification opened this issue 1 year ago • 1 comments

Describe the bug

I’ve been working with Streamrip and running it through direct imports in a project. While downloading albums works smoothly, I'm hitting issues when trying to download individual tracks using PendingTrack. The track resolution process seems to go through, but the actual download either fails or returns unexpected results.

Here’s a quick rundown of what I’m seeing:

The rip() method for individual tracks either errors out or results in NoneType returns.
Albums process just fine, so I’m wondering if there's something specific about handling tracks this way.

Does Streamrip support track downloads through direct imports? Or are there any known quirks or changes I should be aware of when using it this way?

Any pointers would be amazing. Thanks for your help!

Command Used

import logging
import asyncio
from flask import Flask, request, jsonify
from streamrip.client import DeezerClient
from streamrip.config import Config
from streamrip.media import Track, PendingTrack
from streamrip.db import Database, Downloads, Failed
import os


logging.basicConfig(filename='app.log', level=logging.INFO, 
                    format='%(asctime)s - %(levelname)s - %(message)s')

app = Flask(__name__)


def initialize_client(arl):
    config = Config.defaults()
    config.session.deezer.arl = arl
    client = DeezerClient(config)
    return client

@app.route('/download', methods=['GET', 'POST'])
async def download():
    if request.method == 'GET':
        link_address = request.args.get('url')
    elif request.method == 'POST':
        link_address = request.json.get('url')

    if not link_address:
        logging.warning('URL was not provided')
        return jsonify({'error': 'URL is required'}), 400

    arl = ''
    download_folder = '/path/to/download/folder'

    try:
        downloads_path = '.config/streamrip/downloads.db'
        failed_downloads_path = '.config/streamrip/failed_downloads.db'
        downloads_db = Downloads(downloads_path)
        failed_db = Failed(failed_downloads_path)
        db = Database(downloads_db, failed_db)

        client = initialize_client(arl)
        await client.login()
        if not client.logged_in:
            logging.error('Failed to log in to Deezer')
            return jsonify({'error': 'Failed to log in to Deezer'}), 500
        
        track_id = link_address.split('/')[-1] 

        pending_track = PendingTrack(track_id, client, client.config, download_folder, db, None)
        resolved_track = await pending_track.resolve()
        
        if resolved_track is None:
            logging.error('Track could not be resolved')
            return jsonify({'error': 'Track could not be resolved'}), 500
        
        logging.info(f'Metadata: {resolved_track.meta}')
        
        await resolved_track.rip()
        logging.info('Track downloaded successfully')
        return jsonify({'message': 'Track downloaded successfully'})
    
    except Exception as e:
        logging.exception('An exception occurred')
        return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=int(os.environ.get('PORT', 7123)))

Debug Traceback

"'NoneType' object has no attribute 'downloaded'"

Config File

config = Config.defaults()

Operating System

Ubuntu 24

streamrip version

2.0.5

Screenshots and recordings

No response

Additional context

No response

suntification avatar Nov 10 '24 23:11 suntification

Utilize PendingSingle() instead. That worked from me.

CodePunk- avatar May 29 '25 19:05 CodePunk-