~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/discoverer.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-07-07 13:43:47 UTC
  • mto: (6.1.9 sid) (1.2.12)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20110707134347-cari9kxjiakzej9z
Tags: upstream-0.14.1
ImportĀ upstreamĀ versionĀ 0.14.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
1
# PiTiVi , Non-linear video editor
3
2
#
4
3
#       discoverer.py
18
17
#
19
18
# You should have received a copy of the GNU Lesser General Public
20
19
# License along with this program; if not, write to the
21
 
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
 
# Boston, MA 02111-1307, USA.
 
20
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
21
# Boston, MA 02110-1301, USA.
23
22
 
24
23
"""
25
24
Discover file multimedia information.
26
25
"""
27
26
 
28
27
from gettext import gettext as _
29
 
import os.path
 
28
import os
30
29
import gobject
31
30
gobject.threads_init()
32
31
import gst
33
 
import gst.pbutils
34
 
from gst.pbutils import INSTALL_PLUGINS_SUCCESS, \
35
 
        INSTALL_PLUGINS_PARTIAL_SUCCESS, INSTALL_PLUGINS_USER_ABORT, \
36
 
        INSTALL_PLUGINS_STARTED_OK
 
32
from gst import pbutils
37
33
import tempfile
38
34
import hashlib
39
35
 
49
45
# what encoded format it is
50
46
# We will need that in order to create proper Stream objects.
51
47
 
 
48
 
52
49
class EOSSir(gst.Element):
53
50
    __gstdetails__ = (
54
51
        "EOSSir",
55
52
        "Generic",
56
53
        "pushes EOS after the first buffer",
57
 
        "Alessandro Decina <alessandro.d@gmail.com>"
58
 
        )
 
54
        "Alessandro Decina <alessandro.d@gmail.com>")
59
55
 
60
56
    srctemplate = gst.PadTemplate("src", gst.PAD_SRC,
61
57
            gst.PAD_ALWAYS, gst.Caps("ANY"))
83
79
        return ret
84
80
gobject.type_register(EOSSir)
85
81
 
 
82
 
86
83
class Discoverer(Signallable, Loggable):
87
84
    """
88
85
    Queues requests to discover information about given files.
101
98
    """
102
99
 
103
100
    __signals__ = {
104
 
        "discovery-error" : ["a", "b", "c" ],
105
 
        "discovery-done" : ["uri", "factory"],
106
 
        "ready" : None,
107
 
        "starting" : None,
108
 
        "missing-plugins": ["uri", "detail", "description"]
109
 
        }
 
101
        "discovery-error": ["a", "b", "c"],
 
102
        "discovery-done": ["uri", "factory"],
 
103
        "ready": None,
 
104
        "starting": None,
 
105
        "missing-plugins": ["uri", "detail", "description"]}
110
106
 
111
107
    def __init__(self):
112
108
        Loggable.__init__(self)
195
191
 
196
192
        for message in self.missing_plugin_messages:
197
193
            detail = \
198
 
                    gst.pbutils.missing_plugin_message_get_installer_detail(message)
 
194
                    pbutils.missing_plugin_message_get_installer_detail(message)
199
195
            description = \
200
 
                    gst.pbutils.missing_plugin_message_get_description(message)
 
196
                    pbutils.missing_plugin_message_get_description(message)
201
197
 
202
198
            self.missing_plugin_details.append(detail)
203
199
            self.missing_plugin_descriptions.append(description)
207
203
    def _installMissingPluginsCallback(self, result, factory):
208
204
        rescan = False
209
205
 
210
 
        if result in (INSTALL_PLUGINS_SUCCESS,
211
 
                INSTALL_PLUGINS_PARTIAL_SUCCESS):
 
206
        if result in (pbutils.INSTALL_PLUGINS_SUCCESS,
 
207
                pbutils.INSTALL_PLUGINS_PARTIAL_SUCCESS):
212
208
            gst.update_registry()
213
209
            rescan = True
214
 
        elif result == INSTALL_PLUGINS_USER_ABORT \
 
210
        elif result == pbutils.INSTALL_PLUGINS_USER_ABORT \
215
211
                and factory.getOutputStreams():
216
212
            self._emitDone(factory)
217
213
        else:
245
241
 
246
242
        if not self.current_streams and not missing_plugins:
247
243
            # woot, nothing decodable
248
 
            self.error = _('Can not decode file.')
 
244
            self.error = _('Cannot decode file.')
249
245
            self.error_detail = _("The given file does not contain audio, "
250
246
                    "video or picture streams.")
251
247
            self._emitError()
266
262
            # assume it's got infinite duration)
267
263
            is_image = have_image and len(self.current_streams) == 1
268
264
            if self.current_duration == gst.CLOCK_TIME_NONE and not is_image:
269
 
                self.error =_("Could not establish the duration of the file.")
 
265
                self.error = _("Could not establish the duration of the file.")
270
266
                self.error_detail = _("This clip seems to be in a format "
271
267
                        "which cannot be accessed in a random fashion.")
272
268
                self._emitError()
282
278
                self.missing_plugin_details,
283
279
                self.missing_plugin_descriptions,
284
280
                callback)
285
 
        if res is None or res != INSTALL_PLUGINS_STARTED_OK:
 
281
        if res is None or res != pbutils.INSTALL_PLUGINS_STARTED_OK:
286
282
            # no missing-plugins handlers
287
283
            if factory.getOutputStreams():
288
284
                self._emitDone(factory)
291
287
 
292
288
            return True
293
289
 
294
 
 
295
290
        # plugins are being installed, processing will continue when
296
291
        # self._installMissingPluginsCallback is called by the application
297
292
        return False
364
359
        if not source:
365
360
            self.warning("This is not a media file: %s", self.current_uri)
366
361
            self.error = _("No available source handler.")
367
 
            self.error_detail = _("You do not have a GStreamer source element to handle protocol '%s'") % gst.uri_get_protocol(self.current_uri)
 
362
            self.error_detail = _('You do not have a GStreamer source element to handle the "%s" protocol') % gst.uri_get_protocol(self.current_uri)
368
363
 
369
364
            return None
370
365
 
405
400
        self.current_uri = self.queue[0]
406
401
        self.info("Analyzing %s", self.current_uri)
407
402
 
 
403
        # check if file exists and is readable
 
404
        if gst.uri_get_protocol(self.current_uri) == "file":
 
405
            filename = gst.uri_get_location(self.current_uri)
 
406
            error = None
 
407
            if not os.access(filename, os.F_OK):
 
408
                error = _("File does not exist")
 
409
            elif not os.access(filename, os.R_OK):
 
410
                error = _("File not readable by current user")
 
411
            if error:
 
412
                self.info("Error: %s", self.error)
 
413
                self.error = error
 
414
                self._finishAnalysis("File does not exist or is not readable by the current user")
 
415
                return False
 
416
 
408
417
        # setup graph and start analyzing
409
418
        self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri)
410
419
 
468
477
            self._finishAnalysis("redirect")
469
478
            return
470
479
 
471
 
        if gst.pbutils.is_missing_plugin_message(message):
 
480
        if pbutils.is_missing_plugin_message(message):
472
481
            self._busMessageMissingPlugins(message)
473
482
 
474
483
    def _busMessageMissingPlugins(self, message):
717
726
    def _addStreamFromPad(self, pad):
718
727
        self._maybeQueryDuration(pad)
719
728
        self.debug("adding stream from pad %s caps %s", pad, pad.props.caps)
720
 
        stream  = get_stream_for_pad(pad)
 
729
        stream = get_stream_for_pad(pad)
721
730
        self.current_streams.append(stream)
722
731
 
723
732
        return stream