Playlist creation Mobile App in Python !
This is a simple program i have made for my mobile phone (Nokia N70).
To cut a long story short, i have a a 1GB memory card more than half of them are mp3's, and i wanted a simple program to organize them (Playlist for each folder). At the same time, i wanted to play with something new and non-usual ( ! J2ME), i wanted to write it in python :) , and it turned out to be very easy.
Note that the code is not displayed properly here. Python code blocks depend on indentation.
import os
import sys
# Test folder
searchDirectory="/media/sda6/Songs/fdsfsd"
if not os.path.isdir ( searchDirectory ) :
print searchDirectory + " is not a directory."
sys.exit ( 0 )
m3uFilename = os.path.split ( searchDirectory )[1] + '.m3u'
# Get all files.
dirList=os.listdir(searchDirectory)
fileList = []
# Get mp3 or m4a files only.
for fname in dirList:
if fname.lower().endswith ( '.mp3' ) or fname.lower().endswith ( '.m4a' ) :
fileList.append ( fname )
# Begin : Generate the m3u file.
m3uFile = open( searchDirectory + os.path.normcase('/') + m3uFilename ,'w')
filesAdded = 0
for aFile in fileList:
print 'Adding ' + aFile
m3uFile.write ( aFile + '\n' )
filesAdded = filesAdded + 1
print 'Files Added : ' + str ( filesAdded )
m3uFile.close()
# End : Generate the m3u file.
import fileselector
searchDirectory = fileselector.fileselect()
import os
import sys
# Begin : Mobile Specific Code.
import fileselector
searchDirectory = fileselector.fileselect()
# End : Mobile Specific Code.
if not os.path.isdir ( searchDirectory ) :
print searchDirectory + " is not a directory."
sys.exit ( 0 )
m3uFilename = os.path.split ( searchDirectory )[1] + '.m3u'
# Get all files.
dirList=os.listdir(searchDirectory)
fileList = []
# Get mp3 or m4a files only.
for fname in dirList:
if fname.lower().endswith ( '.mp3' ) or fname.lower().endswith ( '.m4a' ) :
fileList.append ( fname )
# Begin : Generate the m3u file.
m3uFile = open( searchDirectory + os.path.normcase('/') + m3uFilename ,'w')
filesAdded = 0
for aFile in fileList:
print 'Adding ' + aFile
m3uFile.write ( aFile + '\n' )
filesAdded = filesAdded + 1
print 'Files Added : ' + str ( filesAdded )
m3uFile.close()
# End : Generate the m3u file.
Enjoy it :)
1 comment:
mmmm.. python!! Sheref fe thawbehe l jaded :D
Post a Comment