0

I am trying to create a Django project on SpotDL. Here's my files:

--urls.py

urlpatterns = [
path('admins/', admin.site.urls),
path('spdl/', views.spdl),

]

--views.py

def spdl(request):
import spotdl
spotify_url = "https://open.spotify.com/track/2Cd9iWfcOpGDHLz6tVA3G4";
subprocess.run(['spotdl', spotify_url] , check=True)

return HttpResponse("downloaded")

It successfully downloads the track on my PC. But, I want to customize it a little bit. I want to set the --bitrate on views.py file during the spotdl call. I tried this line but failed: (got via ChatGPT)

subprocess.run(['spotdl', '--bitrate', '128', spotify_url], check=True)

How can I pass other commands to SpotDL like --bitrate or --cookie-file cookies.txt?

1 Answer 1

0

Here's how you can make calls to the binary and pass command line arguments using the subprocess call, attaching the subprocess document for your reference.

import subprocess
subprocess.call(['./a.out', '--name=yash', '--age=22', '--job=dev'])

I have tested on this c++ code and its working as expected. Similar can be done by calling spot-dl. Please make sure spot-dl is on path and can be accessed by the server.

#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
    string name = argv[1];
    string age = argv[2];
    string job = argv[3];
    cout << "Hello" << name << "! You are " << age << " years old and work as a " << job;
}

Sidenote

  • doing it on scale will be a very bad idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.