-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.py
More file actions
32 lines (26 loc) · 846 Bytes
/
utilities.py
File metadata and controls
32 lines (26 loc) · 846 Bytes
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
import wave
import contextlib
import os
import time
import sys
import logging
import eyed3
logging.getLogger().setLevel(logging.INFO)
def get_wav_duration(file_name):
with contextlib.closing(wave.open(file_name,'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
return duration
def get_mp3_duration(file_name):
return eyed3.load(file_name).info.time_secs
def play_wav(file_name):
logging.info("Now playing: {}".format(file_name))
duration = get_wav_duration(file_name)
os.system("gnome-open \"{}\"".format(file_name))
time.sleep(duration)
def play_mp3(file_name):
logging.info("Now playing: {}".format(file_name))
duration = get_mp3_duration(file_name)
os.system("gnome-open \"{}\"".format(file_name))
time.sleep(duration)