This function is identical to the exif_parser() function, with the exception of the signature that's used to check file headers. The MP3 format has only one file signature, 0x494433, unlike the JPEG format. When we call the check_header() function, we supply the file, known signature, and the number of bytes to read from the header. If the signatures match, we call and return the results of the get_tags() function, as follows:
037 def id3_parser(filename):
038 """
039 The id3_parser function confirms the file type and sends it to
040 be processed.
041 :param filename: name of the file potentially containing exif
042 metadata.
043 :return: A dictionary from get_tags, containing the embedded
044 EXIF metadata.
045 """
Although it might be boring to see the same type of logic in each plugin, this greatly simplifies the logic of our framework. In scenarios with larger frameworks, creating things in the same uniform manner helps those maintaining the code sane. Copying and pasting a pre-existing plugin and working from there is often a good way to ensure that things are developed in the same manner. See the following code:
047 # MP3 signatures
048 signatures = ['494433']
049 if processors.utility.check_header(
050 filename, signatures, 3) == True:
051 return get_tags(filename)
052 else:
053 print(('File signature doesn't match known '
054 'MP3 signatures.'))
055 raise TypeError(('File signature doesn't match '
056 'MP3 object.'))