enqueue files to playlist in winamp with python

945 Views Asked by At

I am trying to get python to enqueue music files into Winamp. I have tried the following:

pywinamp

some functions work, but add to playlist doesn't

WACommand

Again some command line switches work, but load file doesn't

Does anyone know some way to get this done? I am not looking for a complete controller for winamp, just a way to push files into the playlist in an already running instance.

I am using winamp 5.63 and windows 7 x64 and python 2.7

3

There are 3 best solutions below

0
On

Not too sure if this is what you are looking for but I hope it may help...

I found a rough way to do it and that is:

Go to into Winamp, go to options->preferences->file types then check the box that says "Enqueue files on double click" then accept the preferences.

Once that is done the following Python code will put 20 (or how ever many you set the while loop to) songs into the playlist from the given directory.

Also if you didn't want the songs to be random you could assign the path variable to be the file path of whatever file you select

import os
import random
import dircache

i = 0
while i < 20: # change 20 to how ever many songs you want to generate
    # set your directory in line bellow
    dir = "C:\" 
    filename = random.choice(dircache.listdir(dir))
    path = os.path.join(dir, filename)
    os.startfile(path)
    i+=1
0
On

pywinamp works with python 2.7 x86 properly, but not with python 2.7 x64. So that.

0
On

I'm using Python 3 on Windows 8 64-bit and using pywinamp.py I can add files to playlist and play the file. Here is my code:

# Run winamp.exe
try:
    with open(os.devnull, 'wb') as devnull:
        devnull = open(os.devnull)
        winamp_path = 'C:\\Program Files\\Winamp\\winamp.exe'
        p = subprocess.Popen([winamp_path], stdout=devnull, stderr=devnull)
except OSError as e:
    # handle the exception
    pass

w = Winamp() # class from pywinamp.py
# Wait for app to start
''' For some reason i couldn't access __mainWindowHWND attribute of Winamp class so i added this line in __init__ method of Winamp class: self.wid = self.__mainWindowHWND. This way i know if winamp is open'''
while not w.wid:
    w = Winamp()
    time.sleep(2)

# Enqueue file in Winamp
w.enqueueFile(filepath.encode('utf-8')) # ctypes needs bytes type
# Get length of winamp playlist and set position on the last track
w.setPlaylistPosition(w.getListLength())
# Play song
w.play()