Package elisa :: Package plugins :: Package bad :: Package webtv_plugin :: Module mmslist_media
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.webtv_plugin.mmslist_media

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17  """ 
 18  mmslist Component Class 
 19  """ 
 20   
 21   
 22  __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>' 
 23   
 24  from elisa.base_components.media_provider import MediaProvider 
 25  from elisa.core.media_uri import MediaUri 
 26  from elisa.core import common 
 27   
 28  from elisa.extern.translation import gettexter, N_ 
 29  T_ = gettexter('elisa-base') 
 30   
 31  from elisa.core.bus import bus_message 
 32   
 33  from twisted.internet import defer, threads 
 34   
 35  _IBN = 'mms://a150.l2584248272.c25842.g.lm.akamaistream.net/D/150/25842/v0001/reflector:48272' 
 36   
37 -class MmslistMedia(MediaProvider):
38 """ 39 This media provider simply ships a list of mms-channels 40 """ 41 42 default_config = {'streams' : [_IBN,], 43 _IBN: {'label': 'ibn'} 44 } 45
46 - def initialize(self):
47 uri = "mmslist:///" 48 action_type = bus_message.MediaLocation.ActionType.LOCATION_ADDED 49 msg = bus_message.InternetLocation(action_type, 50 T_(N_("MMS channels")), 51 'mms', 52 uri, 53 media_types=['video',]) 54 common.application.bus.send_message(msg) 55 self._init_streams()
56
57 - def _init_streams(self):
58 self._streams = {} 59 for stream_uri in self.config.get('streams',[]): 60 uri = MediaUri(stream_uri) 61 stream_opts = self.config.get(str(uri), {'label': uri.label}) 62 label = stream_opts['label'] 63 self._streams[label] = uri
64
66 return { 'mmslist': 0 }
67
69 return []
70
71 - def _blocking_get_media_type(self, uri):
72 if self._blocking_is_directory(uri): 73 return {'file_type' : 'directory', 74 'mime_type' : 'mime_type'} 75 76 return {'file_type' : 'video', 'mime_type' : 'mms'}
77
78 - def _blocking_is_directory(self, uri):
79 if uri.path == '/': 80 return True 81 elif uri.path == '': 82 return True 83 84 return False
85
86 - def get_media_type(self, uri):
87 d = threads.deferToThread(self._blocking_get_media_type, 88 uri) 89 return d
90 91
92 - def has_children_with_types(self, uri, media_types):
93 d = threads.deferToThread(self._blocking_has_children_with_types, 94 uri, media_types) 95 return d
96
97 - def _blocking_has_children_with_types(self, uri, media_types):
98 if self._blocking_is_directory(uri): 99 if 'video' in media_types: 100 return True 101 return False
102
103 - def _blocking_get_direct_children(self, uri, list_of_children):
104 105 if self._blocking_is_directory(uri): 106 for key in self._streams.keys(): 107 chi_uri = MediaUri(self._streams[key]) 108 chi_uri.label = key 109 chi_uri.scheme = 'mmslist' 110 dict = {'file_type' : 'video', 111 'mime_type' : 'mms'} 112 list_of_children.append( (chi_uri, dict) ) 113 return list_of_children
114
115 - def get_direct_children(self, uri, l):
116 d = threads.deferToThread(self._blocking_get_direct_children, uri, l) 117 return d
118
119 - def get_real_uri(self, uri):
120 new_uri = MediaUri(str(uri)) 121 new_uri.scheme = 'mms' 122 return new_uri
123