import
os
def
isMp3Format(mp3filePath):
f
=
open
(mp3filePath,
"r"
);
fileStr
=
f.read();
f.close();
head3Str
=
fileStr[:
3
];
if
head3Str
=
=
"ID3"
:
return
True
;
last32Str
=
fileStr[
-
32
:];
if
last32Str[:
3
]
=
=
"TAG"
:
return
True
;
ascii
=
ord
(fileStr[:
1
]);
if
ascii
=
=
255
:
return
True
;
return
False
;
def
isMp3FolderTraverse(folderPath):
mp3List
=
[];
notMp3List
=
[];
isAllMpFormat
=
True
;
for
dirpath, dirnames, filenames
in
os.walk(folderPath):
for
filename
in
filenames:
path
=
dirpath
+
os.sep
+
filename;
isMp3
=
isMp3Format(path);
if
isMp3
=
=
False
and
str
.endswith(path,
".mp3"
)
=
=
True
:
notMp3List.append(path);
isAllMpFormat
=
False
;
else
:
mp3List.append(path);
return
isAllMpFormat, mp3List, notMp3List;
if
__name__
=
=
'__main__'
:
isMp3Format(
"s_com_click1.mp3"
);
isAllMp3, mp3List, notMp3List
=
isMp3FolderTraverse(
"sound"
);
print
isAllMp3;
print
mp3List;
print
notMp3List;