home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / totem / plugins / bbc / installablecodecs.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  2.5 KB  |  88 lines

  1. #!/usr/bin/python
  2. # coding=UTF-8
  3. #
  4. # Copyright (C) 2008 Tim-Philipp M√ºller <tim.muller@collabora.co.uk>
  5. # Copyright (C) 2008 Canonical Ltd.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
  20. #
  21. # The Totem project hereby grant permission for non-gpl compatible GStreamer
  22. # plugins to be used and distributed together with GStreamer and Totem. This
  23. # permission are above and beyond the permissions granted by the GPL license
  24. # Totem is covered by.
  25. #
  26. # See license_change file for details.
  27.  
  28. import gobject
  29. gobject.threads_init()
  30. import pygst
  31. pygst.require ("0.10")
  32. import gst
  33.  
  34. import os
  35.  
  36. def getInstallableCodecsUbuntu():
  37.   import warnings
  38.   warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
  39.   import apt
  40.  
  41.   codecs = []
  42.  
  43.   try:
  44.     apt_cache = apt.Cache()
  45.   except:
  46.     gst.warning('Failed to read APT cache')
  47.     return []
  48.  
  49.   #import time
  50.   #now = time.time()
  51.   for pkg in apt_cache:
  52.     # check only packages that are releated to gstreamer
  53.     # this is a performance hack that brings this code from 30s
  54.     # to 1s on cold cache
  55.     if (not "gstreamer" in pkg.name or 
  56.         pkg.isInstalled or 
  57.         not pkg.candidateDownloadable):
  58.       continue
  59.     record = pkg.candidateRecord
  60.     if not record:
  61.       continue
  62.     if not record.has_key("Gstreamer-Version"):
  63.       continue
  64.     if record.has_key("Gstreamer-Decoders"):
  65.       codec_list = record["Gstreamer-Decoders"].split(";")
  66.       codecs.extend([item.split(",")[0].strip() for item in codec_list])
  67.   #print time.time() - now
  68.     
  69.   return codecs
  70.  
  71.  
  72. def getInstallableCodecs():
  73.   codecs = []
  74.   if os.access('/var/cache/app-install/gai-codec-map.gdbm', os.R_OK):
  75.     codecs = getInstallableCodecsUbuntu()
  76.   return codecs
  77.  
  78.  
  79. if __name__ == "__main__":
  80.   codecs = getInstallableCodecs()
  81.   if len(codecs) > 0:
  82.     for codec in codecs:
  83.       print "installable: %s" % (codec)
  84.   else:
  85.     print 'No codecs known to be installable'
  86.  
  87.  
  88.