예제 #1
0
 def fetch_video_details(self, video_id):
     video_result = self._retrieve_video_details(video_id,
                                                 'snippet,contentDetails')
     # LATER: add debug logging for youtube response
     if video_result == False:
         return Result(False, meta_info=None, message=video_result.message)
     elif len(video_result) == 0:
         return Result(
             False,
             meta_info=None,
             message=
             _('Invalid YouTube URL. This video does not exist or is private and can not be embedded.'
               ))
     video_details = video_result[0]
     iso8601_duration = video_details['contentDetails']['duration']
     duration = aniso8601.parse_duration(iso8601_duration)
     snippet = video_details['snippet']
     best_thumbnail = self._find_biggest_thumbnail(snippet['thumbnails'])
     meta_info = {
         'unique_id': video_details['id'],
         'duration': timedelta_to_seconds(duration),
         'display_name': snippet['title'],
         'description': snippet['description'],
         'thumbnail': {
             'width': best_thumbnail['width'],
             'height': best_thumbnail['height'],
             'url': best_thumbnail['url'],
         },
         'type': VIDEO,
     }
     return Result(True, meta_info=meta_info, message=None)
예제 #2
0
 def _retrieve_video_details(self, video_id, parts):
     search = self.youtube.videos().list(
         id=video_id,
         part=parts,
     )
     try:
         search_response = search.execute()
     except apiclient.errors.HttpError as api_error:
         response_content = api_error.content
         # LATER: log raw error content
         error_details = json.loads(response_content)['error']['errors'][0]
         reason = error_details['reason']
         youtube_reason = reason
         if 'message' in error_details:
             youtube_reason += ' / ' + error_details['message']
         message = _('unknown YouTube error: %(reason)s') % dict(
             reason=youtube_reason)
         if reason == 'keyInvalid':
             message = _(
                 'Invalid API key. Please check your Google API key in settings.'
             )
         elif reason == 'accessNotConfigured':
             # Access Not Configured. The API (YouTube Data API) is not
             # enabled for your project. Please use the Google Developers
             # Console to update your configuration.
             message = error_details['message']
         return Result(False, message=message)
     videos = search_response.get('items', [])
     return videos
예제 #3
0
 def is_db_scheme_current_for_all_plugins(self):
     for migrator in self.migrators():
         if migrator.db_needs_upgrade():
             return Result(
                 False,
                 message='Database should be updated for plugin %r.' %
                 migrator.plugin_name)
     return True