1 contributor
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# piece of code modified from file metainfo.py from:
# CherryMusic - a standalone music server (http://github.com/devsnd/cherrymusic/) # Copyright (c) 2012 - 2016 Tom Wallroth & Tilman Boerner
# Thanks to them for their very nice music server
#
import sys
from tinytag import TinyTag
class Metainfo():
def __init__(self, artist='', album='', title='', track='', length=0):
self.artist = artist
self.album = album
self.title = title
self.track = track
self.length = length
def dict(self):
return {
'artist': self.artist,
'album': self.album,
'title': self.title,
'track': self.track,
'length': self.length
}
def getSongInfo(filepath):
try:
tag = TinyTag.get(filepath)
except LookupError:
return Metainfo()
# make sure everthing returned (except length) is a string
for attribute in ['artist','album','title','track']:
if getattr(tag, attribute) is None:
setattr(tag, attribute, '')
# print(filepath)
# print(tag.artist)
# print(tag.album)
# print(tag.title)
# print(str(tag.track))
# print(tag.duration)
return Metainfo(tag.artist, tag.album, tag.title, str(tag.track), tag.duration)
if __name__ == "__main__":
for filepath in sys.argv[1:]:
getSongInfo(filepath)