1

Is it possible to play all the .mp3's within a folder in windows media player?

I am using Python 3.2, and so far I have code that returns the absolute location of a random album in my music folder. I would like to take that string and somehow open WMP and play the music within that folder

Any suggestions?

For reference, here is my code:

import random
import os

path = ["Q:\\#User\\Music\\", "Q:\\#user\\What CDs\\"]
print("You shall play " + random.sample(list(filter(lambda f: len([i for i in f if i in "."]) == 0, sum(map(lambda d: list(map(lambda e: d + "\\" + e,os.listdir(d))),list(filter(lambda c: len([i for i in c if i in "."]) == 0, sum(map(lambda a: list(map(lambda b: a + b ,os.listdir(a))), path), [])))), []) )), 1)[0])


input()

And yes, ideally that wouldn't all be in one line. I was learning how to use map and lambda and thought I'd challenge myself. I'd now like to take this one step further, and play the random album.

Thanks!

Rakosman
  • 183
  • 1
  • 2
  • 10

1 Answers1

1

Hmmmm, interesting idea.

I would probably create a .m3u file on the fly and then pass it to WMP as a command line argument (which, according to WMP Command Line is certainly doable).

A .m3u file is simply a text file. Here is an example .m3u for the Tool album Undertow:

#EXTM3U
#EXTINF:295,Tool - Intolerance
01 - Intolerance.mp3
#EXTINF:296,Tool - Prison Sex
02 - Prison Sex.mp3
#EXTINF:307,Tool - Sober
03 - Sober.mp3
#EXTINF:434,Tool - Bottom
04 - Bottom.mp3
#EXTINF:330,Tool - Crawl Away
05 - Crawl Away.mp3
#EXTINF:332,Tool - Swamp Song
06 - Swamp Song.mp3
#EXTINF:322,Tool - Undertow
07 - Undertow.mp3
#EXTINF:363,Tool - 4°
08 - 4°.mp3
#EXTINF:466,Tool - Flood
09 - Flood.mp3
#EXTINF:947,Tool - Disgustipated
69 - Disgustipated.mp3

Good luck!

PS - You can invoke the command line argument by importing the os module and using os.system("YOUR DOS COMMAND")

Oh, and the format used in an m3u file:

#EXTINF:<song-time-in-seconds>, <Artist> - <Song>
<Track_Num> - <File name>

If it wasn't clear.

chucksmash
  • 5,777
  • 1
  • 32
  • 41
  • You can also delete the .m3u file immediately after WMP opens. WMP reads everything from the file when it first opens. – chucksmash Feb 05 '12 at 00:54