hydrus/include/HydrusAudioHandling.py

84 lines
1.9 KiB
Python
Raw Normal View History

2013-08-07 22:25:18 +00:00
import hsaudiotag
import hsaudiotag.auto
import hsaudiotag.flac
import hsaudiotag.mpeg
import hsaudiotag.ogg
2013-05-29 20:19:54 +00:00
import HydrusConstants as HC
import os
import threading
import time
import traceback
2016-11-16 20:21:43 +00:00
#if HC.PLATFORM_WINDOWS: import mp3play
2013-12-18 22:49:24 +00:00
2013-05-29 20:19:54 +00:00
parsed_noises = {}
2013-08-07 22:25:18 +00:00
def GetFLACDuration( path ):
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
hsaudio_object = hsaudiotag.flac.FLAC( path )
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
if not hsaudio_object.valid: raise Exception( 'FLAC file was not valid!' )
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
length_in_seconds = hsaudio_object.duration
2013-07-17 20:56:13 +00:00
length_in_ms = int( length_in_seconds * 1000 )
return length_in_ms
2013-08-07 22:25:18 +00:00
def GetMP3Duration( path ):
2013-07-10 20:25:57 +00:00
2013-08-07 22:25:18 +00:00
hsaudio_object = hsaudiotag.mpeg.Mpeg( path )
2013-07-10 20:25:57 +00:00
2013-08-07 22:25:18 +00:00
if not hsaudio_object.valid: raise Exception( 'MP3 file was not valid!' )
2013-07-10 20:25:57 +00:00
2013-08-07 22:25:18 +00:00
length_in_seconds = hsaudio_object.duration
2013-07-10 20:25:57 +00:00
length_in_ms = int( length_in_seconds * 1000 )
2013-07-17 20:56:13 +00:00
return length_in_ms
2013-08-07 22:25:18 +00:00
def GetOGGVorbisDuration( path ):
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
hsaudio_object = hsaudiotag.ogg.Vorbis( path )
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
if not hsaudio_object.valid: raise Exception( 'Ogg Vorbis file was not valid!' )
2013-07-17 20:56:13 +00:00
2013-08-07 22:25:18 +00:00
length_in_seconds = hsaudio_object.duration
2013-07-17 20:56:13 +00:00
length_in_ms = int( length_in_seconds * 1000 )
2013-07-10 20:25:57 +00:00
return length_in_ms
2013-08-14 20:21:49 +00:00
def GetWMADuration( path ):
hsaudio_object = hsaudiotag.wma.WMADecoder( path )
if not hsaudio_object.valid: raise Exception( 'WMA file was not valid!' )
length_in_seconds = hsaudio_object.duration
length_in_ms = int( length_in_seconds * 1000 )
return length_in_ms
2016-11-16 20:21:43 +00:00
'''
2013-05-29 20:19:54 +00:00
def PlayNoise( name ):
2013-12-18 22:49:24 +00:00
if HC.PLATFORM_OSX: return
2013-05-29 20:19:54 +00:00
if name not in parsed_noises:
if name == 'success': filename = 'success.mp3'
elif name == 'error': filename = 'error.mp3'
2015-11-04 22:30:28 +00:00
path = os.path.join( HC.STATIC_DIR, filename )
2013-05-29 20:19:54 +00:00
noise = mp3play.load( path )
parsed_noises[ name ] = noise
noise = parsed_noises[ name ]
noise.play()
2016-11-16 20:21:43 +00:00
'''