45
45
>>> print f.channels
46
46
>>> print f.duration
47
47
"""
48
- from __future__ import with_statement
49
- from __future__ import division
50
48
51
49
import gi
52
50
gi .require_version ('Gst' , '1.0' )
55
53
import sys
56
54
import threading
57
55
import os
56
+ import queue
57
+ from urllib .parse import quote
58
58
59
59
from .exceptions import DecodeError
60
60
61
- try :
62
- import queue
63
- except ImportError :
64
- import Queue as queue
65
-
66
- try :
67
- from urllib .parse import quote
68
- except ImportError :
69
- from urllib import quote
70
-
71
-
72
61
QUEUE_SIZE = 10
73
62
BUFFER_SIZE = 10
74
63
SENTINEL = '__GSTDEC_SENTINEL__'
@@ -83,7 +72,7 @@ class GStreamerError(DecodeError):
83
72
class UnknownTypeError (GStreamerError ):
84
73
"""Raised when Gstreamer can't decode the given file type."""
85
74
def __init__ (self , streaminfo ):
86
- super (UnknownTypeError , self ).__init__ (
75
+ super ().__init__ (
87
76
"can't decode stream: " + streaminfo
88
77
)
89
78
self .streaminfo = streaminfo
@@ -99,7 +88,7 @@ class NoStreamError(GStreamerError):
99
88
were found.
100
89
"""
101
90
def __init__ (self ):
102
- super (NoStreamError , self ).__init__ ('no audio streams found' )
91
+ super ().__init__ ('no audio streams found' )
103
92
104
93
105
94
class MetadataMissingError (GStreamerError ):
@@ -114,7 +103,7 @@ class IncompleteGStreamerError(GStreamerError):
114
103
principal plugin packages) are missing.
115
104
"""
116
105
def __init__ (self ):
117
- super (IncompleteGStreamerError , self ).__init__ (
106
+ super ().__init__ (
118
107
'missing GStreamer base plugins'
119
108
)
120
109
@@ -142,7 +131,7 @@ class MainLoopThread(threading.Thread):
142
131
"""A daemon thread encapsulating a Gobject main loop.
143
132
"""
144
133
def __init__ (self ):
145
- super (MainLoopThread , self ).__init__ ()
134
+ super ().__init__ ()
146
135
self .loop = GLib .MainLoop .new (None , False )
147
136
self .daemon = True
148
137
@@ -152,7 +141,7 @@ def run(self):
152
141
153
142
# The decoder.
154
143
155
- class GstAudioFile ( object ) :
144
+ class GstAudioFile :
156
145
"""Reads raw audio data from any audio file that Gstreamer
157
146
knows how to decode.
158
147
@@ -373,17 +362,14 @@ def _message(self, bus, message):
373
362
374
363
# Iteration.
375
364
376
- def next (self ):
365
+ def __next__ (self ):
377
366
# Wait for data from the Gstreamer callbacks.
378
367
val = self .queue .get ()
379
368
if val == SENTINEL :
380
369
# End of stream.
381
370
raise StopIteration
382
371
return val
383
372
384
- # For Python 3 compatibility.
385
- __next__ = next
386
-
387
373
def __iter__ (self ):
388
374
return self
389
375
@@ -418,11 +404,6 @@ def close(self, force=False):
418
404
# Halt the pipeline (closing file).
419
405
self .pipeline .set_state (Gst .State .NULL )
420
406
421
- # Delete the pipeline object. This seems to be necessary on Python
422
- # 2, but not Python 3 for some reason: on 3.5, at least, the
423
- # pipeline gets dereferenced automatically.
424
- del self .pipeline
425
-
426
407
def __del__ (self ):
427
408
self .close ()
428
409
0 commit comments