Пример #1
0
def _make_write_request(write_token, method, **params):
    file_content = params.pop('file_content', None)
    data = {
        'method': method,
        'params': params,
    }
    data['params']['token'] = write_token

    if file_content is None:
        response = requests.post(MEDIA_WRITE_URL,
                                 data={'json': json.dumps(data)})
    else:
        response = requests.post(MEDIA_WRITE_URL,
                                 data={'JSONRPC': json.dumps(data)},
                                 files={'file': file_content})

    if not hasattr(response, 'json'):
        raise SyncingError("Invalid response data: %s" % response.content)

    response_data = response.json()
    if response_data.get('error') is not None:
        error = response_data['error']
        try:
            code = error['code']
            msg = error['message']
        except StandardError:
            raise SyncingError("Unknown error")
        else:
            raise SyncingError("%s: %s" % (code, msg))
Пример #2
0
 def create_delete_error(language, message):
     return SyncHistory.objects.create_for_error(
         SyncingError(message),
         account=self.account,
         video_url=self.video_url,
         action=SyncHistory.ACTION_DELETE_SUBTITLES,
         language=language)
Пример #3
0
def _check_error(result):
    """Checks if we had an error result."""
    if _has_child(result, 'error'):
        error = _find_child(result, 'error')
        code = _node_text(_find_child(error, 'code'))
        message = _node_text(_find_child(error, 'message'))
        raise SyncingError("%s: %s" % (code, message))
Пример #4
0
 def create_update_error(version, message):
     return SyncHistory.objects.create_for_error(
         SyncingError(message),
         account=self.account,
         video_url=self.video_url,
         action=SyncHistory.ACTION_UPDATE_SUBTITLES,
         language=version.subtitle_language,
         version=version)
Пример #5
0
def delete_subtitles_cms(account_id, client_id, client_secret, bc_video_id,
                         subtitle_language):
    try:
        brightcove._make_subtitle_cms_request(account_id, client_id,
                                              client_secret, bc_video_id,
                                              subtitle_language.language_code)
    except brightcove.BrightcoveAPIError, e:
        raise SyncingError(unicode(e))
Пример #6
0
 def test_upload_subtitles_error(self):
     now = self.now
     exc = SyncingError('Site exploded')
     self.mock_update_subtitles.side_effect = exc
     language = self.video.subtitle_language('en')
     version = language.get_tip()
     self.run_update_subtitles(language, version)
     self.assertEquals(self.mock_update_subtitles.call_count, 1)
     self.mock_update_subtitles.assert_called_with(self.video_url, language,
                                                   version)
     self.check_sync_history(language, [('U', 'E', now, version, exc.msg)])
     self.check_no_synced_version(language)
Пример #7
0
 def test_delete_subtitles_error(self):
     now = self.now
     exc = SyncingError('Site exploded')
     self.mock_delete_subtitles.side_effect = exc
     language = self.video.subtitle_language('en')
     version = language.get_tip()
     SyncedSubtitleVersion.objects.set_synced_version(
         self.account, self.video_url, language, version)
     self.run_delete_subtitles(language)
     self.assertEquals(self.mock_delete_subtitles.call_count, 1)
     self.mock_delete_subtitles.assert_called_with(self.video_url, language)
     self.check_sync_history(language, [('D', 'E', now, None, exc.msg)])
     self.check_synced_version(language, version)
Пример #8
0
 def update_subtitles(video_url, language, version):
     now_values[language.id] = self.now
     if language.language_code == 'es':
         raise SyncingError('Error')
Пример #9
0
 def get_name(cls, language_code):
     try:
         return getattr(cls, language_code.upper())
     except AttributeError:
         raise SyncingError("No kaltura language for %s" % language_code)