petit script pour vérifier l...
|
1 |
#!/usr/bin/env python3 |
2 |
# -*- coding: utf-8 -*- |
|
3 |
# |
|
4 |
# piece of code modified from file metainfo.py from: |
|
5 |
# CherryMusic - a standalone music server (http://github.com/devsnd/cherrymusic/) # Copyright (c) 2012 - 2016 Tom Wallroth & Tilman Boerner |
|
6 |
# Thanks to them for their very nice music server |
|
7 |
# |
|
8 |
import sys |
|
9 |
from tinytag import TinyTag |
|
10 | ||
11 |
class Metainfo(): |
|
12 |
def __init__(self, artist='', album='', title='', track='', length=0): |
|
13 |
self.artist = artist |
|
14 |
self.album = album |
|
15 |
self.title = title |
|
16 |
self.track = track |
|
17 |
self.length = length |
|
18 | ||
19 |
def dict(self): |
|
20 |
return { |
|
21 |
'artist': self.artist, |
|
22 |
'album': self.album, |
|
23 |
'title': self.title, |
|
24 |
'track': self.track, |
|
25 |
'length': self.length |
|
26 |
} |
|
27 | ||
28 |
def getSongInfo(filepath): |
|
29 |
try: |
|
30 |
tag = TinyTag.get(filepath) |
|
31 |
except LookupError: |
|
32 |
return Metainfo() |
|
33 |
# make sure everthing returned (except length) is a string |
|
34 |
for attribute in ['artist','album','title','track']: |
|
35 |
if getattr(tag, attribute) is None: |
|
36 |
setattr(tag, attribute, '') |
|
37 |
# print(filepath) |
|
38 |
# print(tag.artist) |
|
39 |
# print(tag.album) |
|
40 |
# print(tag.title) |
|
41 |
# print(str(tag.track)) |
|
42 |
# print(tag.duration) |
|
43 |
return Metainfo(tag.artist, tag.album, tag.title, str(tag.track), tag.duration) |
|
44 | ||
45 |
if __name__ == "__main__": |
|
46 |
for filepath in sys.argv[1:]: |
|
47 |
getSongInfo(filepath) |
|
48 |
|