Reputation: 1
I saw this piece of perl code, which creates an MP3 object and writes some tags to it. I don't write code in perl but i assume it creates a valid mp3 file with tags.
$mp3 = MP3::Tag->new('1.mp3');
$mp3->title_set('Some_title');
$mp3->artist_set('Some_artist');
$mp3->update_tags();
$mp3->close();
I want to write something similar in python. I've tried mutagen and eyeD3 so far, but i was only able to overwrite tags of an existing mp3 file, with this piece of code, i found somewhere:
from mutagen.easyid3 import EasyID3
# works with valid mp3 files, which already have tags
def manipulate_id3_tags(path, title, artist, genre):
try:
meta = EasyID3(path) # HERE I GET ERROR
# i assume, if no meta tags where found, it will create some
# but it never hits the exception even it is ID3NoHeaderError
except ID3NoHeaderError:
meta = mutagen.File(path, easy=True) # this also can't be a proper function call
meta.add_tags()
meta['title'] = title
meta['artist'] = artist
meta['genre'] = genre
meta.save()
print(meta)
I don't think these modules can create mp3 files from scratch.
I read the wikipedia article about MP3. My idea was to create a .mp3 file in python and write the header to it. Then i filled the rest with junk code.
This is my sample header according to wikipedia article: 11111111 11111011 11010110 00000100
byte_header = b"\xff\xfb\xd6\x04"
mp3 = open(path + "\\my_file.mp3", "wb")
mp3.write(byte_header)
mp3.write(b"\x01" * 800)
mp3.close
I get an error at the above commented line 'C:\Users\Admin\Music\my_file.mp3' doesn't start with an ID3 tag
Even if the error handling would work, i don't think this method will work. Can anybody help me out here. Just want to create a simple mp3 dummy file, which i can write valid and readable tags to it.
Upvotes: 0
Views: 3469
Reputation: 126722
You are incorrect about Perl's MP3::Tag module. Its constructor expects an existing valid MP3 file, whose tags you may read and modify. It will not create an MP3 file from scratch
This site has silent MP3 files with lengths of 1/10 second upwards, and I suggest that you simply download one of those
Upvotes: 3