Archive for August 23rd, 2008

..::mp3 ഫയല്‍ സേര്‍ച്ച്::..

ഒരുപാടു mp3 ഫയലുകള്‍ ഉള്ളപ്പോള്‍ അതില്‍ നിന്നും വിവരങ്ങള്‍ അറിയാന്‍ പാടാണ്
ആരാണ് പാടിയത് എത്ര ഫയല്‍ സൈസ് ഉണ്ട് അങ്ങനെ .. അതും ഒരു പാടു ഫോള്‍ഡര്‍ ഉണ്ടേ
പറയുകയും വേണ്ട .. അങ്ങനെ എനിക്ക് ഒരു ആവശ്യം വന്നപ്പോള്‍ ഞാന്‍ python വെച്ചു
എഴുതിയ ഒരു സ്ക്രിപ്റ്റ് ആണ് ഇതു .. subfolder സേര്‍ച്ച് ഉണ്ട് അപ്പൊ എളുപ്പം ആണ്
കാര്യങ്ങള്‍ ..

usage :

python myMp3IDReader.py

first option ഫോള്‍ഡര്‍ ആണോ ഫയല്‍ ആണോ എന്ന് ചോദിക്കും

1 for file and 2 for folder

പിന്നെ ഫയല്‍ നെയിം or ഫോള്‍ഡര്‍ നെയിം കൊടുക്കണം
അത്ര തന്നെ ….

ഫുള്‍ സോഴ്സ് ഇവിടെ കിട്ടും

my_python
my_python.py
Hosted by eSnips

import os
import sys
import string
import math

def searchFileInfoHere(getFName,getoptHr):
        if
getoptHr==1:

                myHeadLine=‘<html
xmlns=”http://www.w3.org/1999/xhtml” lang=”en”>

<head>
        <title>MP3
Info</title>

        </style>
</head>
<body>
<table style=”border-collapse: collapse; width:
100%;”>

+\n

                fileHandle = open ( “d:/temp/temp.html”, ‘w’ )

                fileHandle.write(myHeadLine)
                fileHandle.close()

                topPrasrer=‘<tr><td style=”border: 2px solid
rgb(0, 0, 0);”>Filename</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Artist</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Album</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Annotation</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Comment</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>FileSize</td>

<td style=”border: 2px solid rgb(0, 0,
0);”></td></tr>’
+\n

                fileHandle =  open ( “d:/temp/temp.html”,‘a’ )

                fileHandle.write(topPrasrer)
                fileHandle.close()

                findInfoandPrintIt(getFName)
        else:

                myHeadLine=‘<html
xmlns=”http://www.w3.org/1999/xhtml” lang=”en”>

<head>
        <title>MP3
Info</title>

        </style>
</head>
<body>
<table style=”border-collapse: collapse; width:
100%;”>

+\n

                fileHandle = open ( “d:/temp/temp.html”, ‘w’ )

                fileHandle.write(myHeadLine)
                fileHandle.close()

                topPrasrer=‘<tr><td style=”border: 2px solid
rgb(0, 0, 0);”>Filename</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Artist</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Album</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Annotation</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>Comment</td>

<td style=”border: 2px solid rgb(0, 0,
0);”>FileSize</td>

<td style=”border: 2px solid rgb(0, 0,
0);”></td></tr>’
+\n

                fileHandle =  open ( “d:/temp/temp.html”,‘a’ )

                fileHandle.write(topPrasrer)
                fileHandle.close()

                for dirpath,dirname,filename in os.walk(getFName):

                        for file in filename:

                         
      mainRootpath=os.path.join(dirpath,file)

                         
      findInfoandPrintIt(mainRootpath,getoptHr)

def findInfoandPrintIt(getFName,getoptHr):
        getTagFileInfo = open(getFName, ‘r’)

        getTagFileInfo.seek(-128, 2)
        getTagFileInfo.read(3)

        title = string.strip(getTagFileInfo.read(30))
        artist = string.strip(getTagFileInfo.read(30))

        album = string.strip(getTagFileInfo.read(30))
        anno = string.strip(getTagFileInfo.read(4))

        comment = string.strip(getTagFileInfo.read(28))
        getTagFileInfo.close()

        fileNameHr=str(os.path.basename(getFName))

        getFileSize=os.path.getsize(getFName)
        getFileSize=float (round(getFileSize/1048576*100000)/100000)

        getFileSize=str(getFileSize)+” MB”
        mainParser=‘<tr><td style=\”border: 2px solid rgb(0, 0, 0);\”>’+fileNameHr+‘</td>’+\n+‘<td style=\”border: 2px solid
rgb(0, 0, 0);\”>’
+str(artist)+‘</td>’+\n+‘<td style=\”border: 2px solid
rgb(0, 0, 0);\”>’
+album+‘</td>’+\n+‘<td style=\”border: 2px solid rgb(0, 0, 0);\”>’+anno+‘</td>’+\n+‘<td style=\”border: 2px solid rgb(0, 0, 0);\”>’+comment+‘</td>’+\n+‘<td style=\”border: 2px solid
rgb(0, 0, 0);\”>’
+getFileSize+‘</td></tr>’

        fileHandle =  open
( “d:/temp/temp.html”,‘a’ )
        fileHandle.write(mainParser)

        fileHandle.close()
mySearchOption=int (raw_input(“You want search ID Tag in a File or List
MP3 Files in a folder ???\nFor File Enter 1
For Folder 2\n
))

if mySearchOption==1:
        myFilename=raw_input(“Enter File Name Here…eg:
C:\\temp\\temp.mp3\n
)

        searchFileInfoHere(myFilename,1)
elif mySearchOption==2:
        myFolderName=raw_input(“Enter The Root Folder Name Here\n)

        searchFileInfoHere(myFolderName,2)
else:
        print

“Unknown Option used … exiting now !!!\n
        raw_input(“Press any key to exit
!!!\n
)
        sys.exit(1)