~sebest/moovida/dailymotion_plugin

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/dailymotion/resource_provider.py

  • Committer: Sebastien Estienne
  • Date: 2008-08-17 12:16:21 UTC
  • Revision ID: sebastien.estienne@gmail.com-20080817121621-a5af39e1ji70rl7k
Video Preview and Dynamic channels

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from elisa.plugins.dailymotion.models import DailymotionVideoModel, \
18
18
                                             DailymotionPlayableModel, \
19
 
                                             DailymotionVideoListModel
 
19
                                             DailymotionVideoListModel, \
 
20
                                             DailymotionChannelModel, \
 
21
                                             DailymotionChannelListModel
20
22
 
21
23
from elisa.core.media_uri import MediaUri
22
24
 
36
38
    api_uri = "http://%s/rss/.*" % API_SERVER
37
39
    api_re = re.compile(api_uri)
38
40
 
 
41
    channel_uri = "http://%s/rss/channels" % API_SERVER
 
42
    channel_re = re.compile(channel_uri)
 
43
 
39
44
    img_uri = "http://(?:ak.)?static.dailymotion.com/dyn/.*"
40
45
    img_re = re.compile(img_uri)
41
46
 
55
60
    def get(self, uri, context_model=None):
56
61
        url = str(uri)
57
62
 
58
 
        if self.api_re.match(url) is not None:
 
63
        if self.channel_re.match(url) is not None:
 
64
            http_client = self._api_client
 
65
            result_model = DailymotionChannelListModel()
 
66
        elif self.api_re.match(url) is not None:
59
67
            http_client = self._api_client
60
68
            result_model = DailymotionVideoListModel()
61
69
        elif self.img_re.match(url) is not None:
114
122
 
115
123
                    model.videos.append(video)                            
116
124
 
 
125
            elif isinstance(model, DailymotionChannelListModel):
 
126
                # Populate a list of channels
 
127
                import StringIO
 
128
                s = StringIO.StringIO(response)
 
129
                for item in parse(s).findall("//item"):
 
130
                    channel = DailymotionChannelModel()
 
131
                    channel.title = unicode(item.find("title").text).capitalize()
 
132
                    channel.description = unicode(item.find("description").text)
 
133
                    for dm_link in item.findall("{%s}link" % DM_NS):
 
134
                        if dm_link.get("rel") == "featured":
 
135
                            channel.featured = MediaUri(dm_link.get("href") + "?includeFeeds=true")
 
136
                    model.channels.append(channel)
 
137
 
117
138
            elif isinstance(model, RawDataModel):
118
139
                # Image raw data
119
140
                model.data = response