def embed_media_url(self, job_id):
        """
        Create cielo24 add media url.

        Arguments:
            job_id (str): cielo24 job id

        Returns:
            cielo24 task id
        """
        media_url = build_url(self.cielo24_api_base_url,
                              self.cielo24_add_media,
                              v=CIELO24_API_VERSION,
                              job_id=job_id,
                              api_token=self.api_key,
                              media_url=self.s3_video_url)
        response = requests.get(media_url)

        if not response.ok:
            raise Cielo24AddMediaError(
                '[ADD MEDIA ERROR] url={} -- status={} -- text={}'.format(
                    scrub_query_params(media_url, ['api_token']),
                    response.status_code, response.text))

        task_id = ast.literal_eval(response.text)['TaskId']
        LOGGER.info(
            '[CIELO24] Media url created for video=%s with job_id=%s and task_id=%s',
            self.video.studio_id, job_id, task_id)
        return task_id
    def create_job(self):
        """
        Create new job for transcription.

        Returns:
            cielo24 job id
        """
        create_job_url = build_url(self.cielo24_api_base_url,
                                   self.cielo24_new_job,
                                   v=CIELO24_API_VERSION,
                                   language=self.video.source_language,
                                   api_token=self.api_key,
                                   job_name=self.video.studio_id)
        response = requests.get(create_job_url)

        if not response.ok:
            raise Cielo24CreateJobError(
                '[CREATE JOB ERROR] url={} -- status={} -- text={}'.format(
                    scrub_query_params(create_job_url, ['api_token']),
                    response.status_code,
                    response.text,
                ))

        job_id = ast.literal_eval(response.text)['JobId']
        LOGGER.info('[CIELO24] New job created for video=%s with job_id=%s',
                    self.video.studio_id, job_id)
        return job_id
    def get_available_languages(self):
        """
        Gets all the 3Play Media supported languages
        """
        available_languages_url = build_url(self.base_url,
                                            self.available_languages_url,
                                            apikey=self.api_key)
        response = requests.get(url=available_languages_url)
        if not response.ok:
            raise ThreePlayMediaLanguagesRetrievalError(
                'Error while retrieving available languages: url={url} -- {response} -- {status}'
                .format(url=scrub_query_params(available_languages_url,
                                               ['apikey']),
                        response=response.text,
                        status=response.status_code))

        # A normal response should be a list containing 3Play Media supported languages and if we're getting a dict,
        # there must be an error: https://support.3playmedia.com/hc/en-us/articles/227729968-Captions-Imports-API
        available_languages = json.loads(response.text)
        if isinstance(available_languages, dict):
            raise ThreePlayMediaLanguagesRetrievalError(
                'Expected 3Play Media Supported languages but got: {response}'.
                format(response=response.text))

        return available_languages
    def perform_transcript(self, job_id, lang_code):
        """
        Request cielo24 to generate transcripts for a video.
        """
        callback_url = '{}?job_id={}&iwp_name={}&lang_code={}&org={}&video_id={}'.format(
            self.callback_base_url, job_id, '{iwp_name}', lang_code, self.org,
            self.video.studio_id)

        perform_transcript_url = build_url(
            self.cielo24_api_base_url,
            self.cielo24_perform_transcription,
            v=CIELO24_API_VERSION,
            job_id=job_id,
            target_language=lang_code,
            callback_url=callback_url,
            api_token=self.api_key,
            priority=self.turnaround,
            transcription_fidelity=self.fidelity,
            options=json.dumps({"return_iwp": ["FINAL"]}))
        response = requests.get(perform_transcript_url)

        if not response.ok:
            raise Cielo24PerformTranscriptError(
                '[PERFORM TRANSCRIPT ERROR] url={} -- status={} -- text={}'.
                format(
                    scrub_query_params(perform_transcript_url, ['api_token']),
                    response.status_code, response.text))

        task_id = ast.literal_eval(response.text)['TaskId']
        LOGGER.info(
            '[CIELO24] Perform transcript request successful for video=%s with job_id=%s and task_id=%s',
            self.video.studio_id, job_id, task_id)
        return job_id
Exemplo n.º 5
0
def get_translation_services(api_key):
    """
    GET available 3Play Media Translation services

    Arguments:
        api_key(unicode): api key which is required to make an authentic call to 3Play Media

    Returns:
        Available 3Play Media Translation services.
    """
    get_translation_services_url = build_url(
        THREE_PLAY_TRANSLATION_SERVICES_URL, apikey=api_key)
    response = requests.get(get_translation_services_url)
    if not response.ok:
        raise TranscriptTranslationError(
            u'[3PlayMedia Callback] Error fetching the translation services -- url={url}, {status}, {response}'
            .format(
                url=scrub_query_params(get_translation_services_url,
                                       ['apikey']),
                status=response.status_code,
                response=response.text,
            ))

    # Response should be a list containing services, details:
    # http://support.3playmedia.com/hc/en-us/articles/227729988-Translations-API-Methods
    available_services = json.loads(response.text)
    if not isinstance(available_services, list):
        raise TranscriptTranslationError(
            u'[3PlayMedia Callback] Expected list but got: -- {response}.'.
            format(response=response.text, ))

    return available_services
Exemplo n.º 6
0
def get_translations_metadata(api_key, file_id, edx_video_id):
    """
    Get translations metadata from 3Play Media for a given file id.

    Arguments:
        api_key(unicode): api key
        file_id(unicode): file identifier or process identifier
        edx_video_id(unicode): video studio identifier

    Returns:
        A List containing the translations metadata for a file id or None
        in case of a faulty response.
        Example:
        [
            {
                "id": 1234,
                "translation_service_id": 12,
                "source_language_name": "English",
                "source_language_iso_639_1_code": "en",
                "target_language_name": "French (Canada)",
                "target_language_iso_639_1_code": "fr",
                "state": "complete"
            },
            {
                "id": 1345,
                "translation_service_id": 32,
                "source_language_name": "English",
                "source_language_iso_639_1_code": "en",
                "target_language_name": "German",
                "target_language_iso_639_1_code": "de",
                "state": "in_progress"
            }
        ]
    """
    translations_metadata_url = build_url(
        THREE_PLAY_TRANSLATIONS_METADATA_URL.format(file_id=file_id, ),
        apikey=api_key)
    translations_metadata_response = requests.get(translations_metadata_url)
    if not translations_metadata_response.ok:
        LOGGER.error(
            u'[3PlayMedia Task] Translations metadata request failed, url=%s -- video=%s -- process_id=%s -- status=%s',
            scrub_query_params(translations_metadata_url, ['apikey']),
            edx_video_id,
            file_id,
            translations_metadata_response.status_code,
        )
        return

    translations = json.loads(translations_metadata_response.text)
    if not isinstance(translations, list):
        LOGGER.error(
            u'[3PlayMedia Task] unable to get translations metadata for video=%s -- process_id=%s -- response=%s',
            edx_video_id,
            file_id,
            translations_metadata_response.text,
        )
        return

    return translations
Exemplo n.º 7
0
 def test_scrub_query_params(self, url, params_to_scrub, expected_url):
     """
     Tests that utils.scrub_query_params works as expected.
     """
     self.assertEqual(
         utils.scrub_query_params(url, params_to_scrub),
         expected_url
     )
Exemplo n.º 8
0
 def test_scrub_query_params(self, url, params_to_scrub,
                             expected_scrubbed_value):
     """
     Tests that utils.scrub_query_params works as expected.
     """
     scrubed_url = utils.scrub_query_params(url, params_to_scrub)
     if expected_scrubbed_value:
         self.assertIn(expected_scrubbed_value, scrubed_url)
Exemplo n.º 9
0
def fetch_srt_data(url, **request_params):
    """
    Fetch srt data from transcript provider.
    """
    # return TRANSCRIPT_SRT_DATA
    fetch_srt_data_url = build_url(url, **request_params)
    response = requests.get(fetch_srt_data_url)

    if not response.ok:
        raise TranscriptFetchError(
            '[TRANSCRIPT FETCH ERROR] url={} -- status={} -- text={}'.format(
                scrub_query_params(fetch_srt_data_url,
                                   ['apikey', 'api_token']),
                response.status_code, response.text))

    return response.text