mich hatte vor kurzer zeit mal interessiert, wie lang ich eigentlich schon so Musik gehört habe und hab mir auf die Schnelle ein kleines Script gebastelt, das das erledigt.
Code: Alles auswählen
from xml.etree import ElementTree
import shutil
import os
TEMP_FILE_NAME = 'itunes_temp.xml'
def get_total_play_time(xml_path):
total_time = 0
e = ElementTree.parse(xml_path)
for song in e.findall('dict/dict/dict'):
infos = song.getchildren()
song_time = 0
song_count = 0
for pos,info in enumerate(infos):
if info.tag == 'key':
if info.text == 'Total Time':
try:
song_time = int(infos[pos+1].text)
except ValueError:
continue
elif info.text == 'Play Count':
try:
song_count = int(infos[pos+1].text)
except ValueError:
continue
total_time += song_count * song_time
return total_time
if __name__ == '__main__':
shutil.copyfile('iTunes Music Library.xml', TEMP_FILE_NAME)
time = get_total_play_time(TEMP_FILE_NAME)
print time / (1000.0 * 60 *60), 'h'
os.remove(TEMP_FILE_NAME)
MfG