Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Tracks download not working with direct import #770

Open
suntification opened this issue Nov 10, 2024 · 0 comments
Open

[BUG] Tracks download not working with direct import #770

suntification opened this issue Nov 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@suntification
Copy link

suntification commented Nov 10, 2024

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 suntification added the bug Something isn't working label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant