Created
October 16, 2013 17:55
-
-
Save shantanoo/7012052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
def get_mp3_tag(fname): | |
try: | |
f = open(sys.argv[1], 'rb') | |
except Exception as e: | |
return(e, 1) | |
f.seek(-128, 2) | |
data = f.read(128).decode() | |
f.close() | |
if data.startswith('TAG'): | |
song = data[3:33].replace(chr(0), '') | |
artist = data[33:63].replace(chr(0), '') | |
return ({'Song':song, 'Artist': artist}, 0) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('Invalid parameters passed') | |
print('Usage:') | |
print('%s <mp3 file>' % sys.argv[0]) | |
sys.exit(1) | |
tmp = get_mp3_tag(sys.argv[1]) | |
if not tmp[1]: | |
for x in tmp[0]: | |
print('%s: %s' % (x, tmp[0][x])) | |
else: | |
print(tmp[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment