~saviq/elisa/subtitle_chardet

« back to all changes in this revision

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

  • Committer: Florian Boucault
  • Author(s): Paul van Tilburg
  • Date: 2010-04-02 21:49:04 UTC
  • mfrom: (1614.1.1 moovida-youtube-fix)
  • Revision ID: florian@boucault.net-20100402214904-udn8f161wdhk6jjd
Fixed YouTube video URL retrieval.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    api_uri = 'http://%s/feeds/api/.*' % API_SERVER
63
63
    api_re = re.compile(api_uri)
64
64
    # Queries to the video server
65
 
    video_uri = 'http://%s/watch\?.*' % VIDEO_SERVER
 
65
    video_uri = 'http://%s/watch(\?|#!).*' % VIDEO_SERVER
66
66
    video_re = re.compile(video_uri)
67
67
    # Queries to the image server
68
68
    img_uri = 'http://%s/vi/.*\.jpg' % IMG_SERVER
70
70
 
71
71
    supported_uri = api_uri + '|' + video_uri + '|' + img_uri
72
72
 
73
 
    _real_uri_re = re.compile(r"'SWF_ARGS': (\{.*\}),")
 
73
    _video_info_uri = 'http://%s/get_video_info?video_id=' % VIDEO_SERVER
 
74
    _video_id_re = re.compile('watch(\?|#!)v=(.*)')
74
75
 
75
76
    def initialize(self):
76
77
        super(YoutubeResourceProvider, self).initialize()
104
105
            complete list of available feeds, see
105
106
            http://code.google.com/apis/youtube/developers_guide_protocol.html#Standard_feeds
106
107
 
107
 
          - http://www.youtube.com/watch?.* : query to the Youtube server for
 
108
          - http://www.youtube.com/watch?.* or
 
109
            http://www.youtube.com/watch#!.*: query to the Youtube server for
108
110
            a given video, returns the playable URL of the SWF video file
109
111
            (L{elisa.plugins.base.models.media.PlayableModel}).
110
112
 
126
128
            result_model = YoutubeVideoListModel()
127
129
        elif self.video_re.match(url) is not None:
128
130
            http_client = self._video_client
 
131
            # Change the URI to one that gets the necessary video info
 
132
            # using get_video_info.
 
133
            video_id = self._video_id_re.search(url).groups()[1]
 
134
            if video_id is not None:
 
135
              uri = MediaUri(self._video_info_uri + video_id)
 
136
              self.debug("Using video info URL instead: %s" % uri)
 
137
            else:
 
138
              self.debug("Couldn't determine the video ID, getting info will fail!")
129
139
            result_model = PlayableModel()
130
140
        elif self.img_re.match(url) is not None:
131
141
            http_client = self._img_client
176
186
 
177
187
            elif isinstance(model, PlayableModel):
178
188
                # Retrieve the real URI of the SWF video file for a video
179
 
                swfargs = self._real_uri_re.search(response).groups()[0]
180
 
                replaces = {'null': 'None', 'true': 'True', 'false': 'False'}
181
 
                for key, value in replaces.iteritems():
182
 
                    swfargs = swfargs.replace(key, value)
183
 
                swfargs = eval(swfargs)
 
189
                video_id = re.compile('video_id=([^&]+)').search(response).groups()[0]
 
190
                token = re.compile('token=([^&]+)').search(response).groups()[0]
184
191
                playable_uri = 'http://%s/get_video?video_id=%s&t=%s' % \
185
 
                               (VIDEO_SERVER, swfargs['video_id'], swfargs['t'])
 
192
                               (VIDEO_SERVER, video_id, token)
186
193
                playable_uri += '&fmt=18' # H264 encoded video, better quality
187
194
                model.uri = MediaUri(playable_uri)
188
195
                if context_model and isinstance(context_model, YoutubeVideoModel):