forked from albertz/music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_replaygain.py
44 lines (38 loc) · 1.49 KB
/
test_replaygain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import better_exchook
better_exchook.install()
class Song:
def __init__(self, fn):
self.url = fn
self.f = open(fn)
def readPacket(self, bufSize):
s = self.f.read(bufSize)
return s
def seekRaw(self, offset, whence):
r = self.f.seek(offset, whence)
return self.f.tell()
import sys, os
if len(sys.argv) == 2:
filename = sys.argv[1]
else:
files = [
"~/Music/Classic/Glenn Gould Plays Bach/Two- & Three-Part Inventions - Gould/19 Bach - Invention 13 in a (BWV 784).mp3",
"~/Music/Rock/Tool/Lateralus/09 Lateralus.flac",
"~/Music/Cults - Cults 7/Cults - Cults 7- - 03 The Curse.flac",
"~/Music/Special/zorba/(01) - Theme From Zorba The Greek.ogg",
"~/Music/Classic/Glenn Gould Plays Bach/French Suites, BWV812-7 - Gould/Bach, French Suite 5 in G, BWV816 - 5 Bourree.mp3",
"~/Music/Electronic/Von Paul Kalkbrenner - Aaron.mp3",
"~/Music/Electronic/One Day_Reckoning Song (Wankelmut Remix) - Asaf Avidan & the Mojos.mp3",
"~/Music/Electronic/Swing & Electro Swing/Parov Stelar/2008 - Daylight (Japan Only)/03 - Charlestone Butterfly.flac", # this one has replaygain metadata
]
files = map(os.path.expanduser, files)
filename = files[7]
print(os.path.basename(filename))
assert os.path.isfile(filename)
import ffmpeg
metadata = ffmpeg.getMetadata(Song(filename))
from pprint import pprint
pprint(metadata)
duration, replaygain = ffmpeg.calcReplayGain(Song(filename))
print("duration: %f" % duration)
print("replaygain: %f" % replaygain)
print("gain factor: %f" % (10. ** (replaygain / 20)))