Beispiel #1
0
    def activate(self):

        if self.veda_id != None and len(settings['veda_api_url']) == 0:
            ErrorObject().print_error(
                message='VEDA API Config Incorrect, run test to debug')
            return None
        """
        test case
        """
        if self.veda_id is None:
            self.mezz_extension = '.mp4'
            self.mezz_title = TEST_VIDEO_FILE
            self.mezz_filepath = os.path.join(TEST_VIDEO_DIR, TEST_VIDEO_FILE)
            self.valid = True
            return None
        """
        Generated Token
        """
        veda_token = generate_apitoken.veda_tokengen()
        if veda_token == None: return None

        data = {
            'edx_id': self.veda_id,
        }
        headers = {
            'Authorization': 'Token ' + veda_token,
            'content-type': 'application/json'
        }
        x = requests.get('/'.join((settings['veda_api_url'], 'videos', '')),
                         params=data,
                         headers=headers)

        vid_dict = json.loads(x.text)
        if len(vid_dict['results']) == 0: return None

        for v in vid_dict['results']:
            """
            Yeah this is horrible, but it's tied to VEDA's model

            """
            self.vid_pk = v['id']
            self.class_id = v['inst_class']
            self.val_id = v['studio_id']
            self.mezz_extension = v['video_orig_extension']
            self.mezz_bitrate = v['video_orig_bitrate']
            self.mezz_title = v['client_title']
            self.mezz_filesize = v['video_orig_filesize']
            '''Do some field cleaning in case of SAR/DAR legacy errors'''
            mezz_resolution = v['video_orig_resolution'].strip().split(' ')[0]
            self.mezz_resolution = mezz_resolution
            '''Clean from unicode (00:00:00.53)'''
            uni_duration = v['video_orig_duration']
            self.mezz_duration = Output._seconds_from_string(uni_duration)
            self.mezz_filepath = '/'.join(
                ('https://s3.amazonaws.com', settings['aws_storage_bucket'],
                 self.veda_id + '.' + self.mezz_extension))

            self.valid = True
Beispiel #2
0
    def test_veda_connection(self):
        if not os.path.exists(self.WS.instance_yaml):
            self.assertTrue(True)
            return None

        veda_token = generate_apitoken.veda_tokengen()
        self.assertFalse(veda_token == None)
        headers = {
            'Authorization': 'Token ' + veda_token, # + veda_token,
            'content-type': 'application/json'
            }
        s = requests.get(self.WS.settings_dict['veda_api_url'] + '/', headers=headers, timeout=20)

        self.assertFalse(s.status_code == 404)
        self.assertFalse(s.status_code > 299)
Beispiel #3
0
    def pull_data(self):
        """
        Retrieve Active and latest encode data from central VEDA node
        """
        # TODO: Change retrieval to a scheduled/delay process
        if self.VideoObject.veda_id is None:
            self._default_encodes()
            return

        veda_token = generate_apitoken.veda_tokengen()
        if veda_token is None:
            logger.error(': {id} {encode} VEDA Token Generate'.format(
                id=self.VideoObject.veda_id, encode=self.profile_name))
            return

        data = {'product_spec': self.profile_name}

        headers = {
            'Authorization': 'Token ' + veda_token,
            'content-type': 'application/json'
        }
        x = requests.get('/'.join((settings['veda_api_url'], 'encodes')),
                         params=data,
                         headers=headers)
        if x.status_code > 250:
            self._default_encodes()
            return

        enc_dict = json.loads(x.text)

        if len(enc_dict['results']) == 0:
            logger.error(
                ': {id} {encode} VEDA API Encode Mismatch: No Data'.format(
                    id=self.VideoObject.veda_id, encode=self.profile_name))
            return

        for e in enc_dict['results']:
            if e['product_spec'] == self.profile_name and e[
                    'profile_active'] is True:
                self.resolution = e['encode_resolution']
                self.rate_factor = e['encode_bitdepth']
                self.filetype = e['encode_filetype']
                self.encode_suffix = e['encode_suffix']
                self.encode_pk = e['id']

                if self.encode_suffix is None:
                    # In the case of an API Error
                    self._default_encodes()
Beispiel #4
0
    def test_veda_connection(self):
        if not os.path.exists(self.WS.instance_yaml):
            self.assertTrue(True)
            return None

        veda_token = generate_apitoken.veda_tokengen()
        self.assertFalse(veda_token == None)
        headers = {
            'Authorization': 'Token ' + veda_token,  # + veda_token,
            'content-type': 'application/json'
        }
        s = requests.get(self.WS.settings_dict['veda_api_url'] + '/',
                         headers=headers,
                         timeout=20)

        self.assertFalse(s.status_code == 404)
        self.assertFalse(s.status_code > 299)
Beispiel #5
0
    def pull_data(self):

        encode_dict = {}
        veda_token = generate_apitoken.veda_tokengen()

        if veda_token == None:
            ErrorObject().print_error(
                message="VEDA Token Generate"
                )
            return None

        data = {
            'product_spec' : self.profile_name
            }

        headers = {
            'Authorization': 'Token ' + veda_token,
            'content-type': 'application/json'
            }
        x = requests.get(
            '/'.join((settings['veda_api_url'], 'encodes')), 
            params=data, 
            headers=headers
            )
        enc_dict = json.loads(x.text)   

        if len(enc_dict['results']) == 0:
            ErrorObject().print_error(
                message="VEDA API Encode Mismatch: No Data"
                )
            return None

        for e in enc_dict['results']:
            if e['product_spec'] == self.profile_name and e['profile_active'] is True:
                self.resolution = e['encode_resolution']
                self.rate_factor = e['encode_bitdepth']
                self.filetype = e['encode_filetype']
                self.encode_suffix = e['encode_suffix']
                self.encode_pk = e['id']
        
        if self.encode_suffix == None:
            ErrorObject().print_error(
                message="VEDA API Encode Data Fail: No Suffix"
                )
            return None
Beispiel #6
0
    def run_veda(self):
        if len(settings) == 0:
            return None

        self.veda_token = generate_apitoken.veda_tokengen()
        if self.veda_token is None:
            logger.error('VEDA API connection: Invalid Setup/Method')
            return None

        self.veda_headers = {
            'Authorization': 'Token ' + self.veda_token,
            'content-type': 'application/json'
        }

        self.veda_video_dict = self.determine_veda_pk()

        # Status Update Only
        if self.veda_video_status is not None:
            return self.send_veda_status()
    def run_veda(self):
        if len(settings) == 0:
            return None

        self.veda_token = generate_apitoken.veda_tokengen()
        if self.veda_token == None:
            ErrorObject().print_error(
                message='VEDA API Conn Fail:\nInvalid Setup/Method')
            return None

        self.veda_headers = {
            'Authorization': 'Token ' + self.veda_token,  # + veda_token,
            'content-type': 'application/json'
        }

        self.veda_video_dict = self.determine_veda_pk()
        """
        Status Update Only
        """
        if self.veda_video_status is not None:
            return self.send_veda_status()
Beispiel #8
0
    def pull_data(self):

        encode_dict = {}
        veda_token = generate_apitoken.veda_tokengen()

        if veda_token == None:
            ErrorObject().print_error(message="VEDA Token Generate")
            return None

        data = {'product_spec': self.profile_name}

        headers = {
            'Authorization': 'Token ' + veda_token,
            'content-type': 'application/json'
        }
        x = requests.get('/'.join((settings['veda_api_url'], 'encodes')),
                         params=data,
                         headers=headers)
        enc_dict = json.loads(x.text)

        if len(enc_dict['results']) == 0:
            ErrorObject().print_error(
                message="VEDA API Encode Mismatch: No Data")
            return None

        for e in enc_dict['results']:
            if e['product_spec'] == self.profile_name and e[
                    'profile_active'] is True:
                self.resolution = e['encode_resolution']
                self.rate_factor = e['encode_bitdepth']
                self.filetype = e['encode_filetype']
                self.encode_suffix = e['encode_suffix']
                self.encode_pk = e['id']

        if self.encode_suffix == None:
            ErrorObject().print_error(
                message="VEDA API Encode Data Fail: No Suffix")
            return None
Beispiel #9
0
    def run_veda(self):
        if len(settings) == 0:
            return None

        self.veda_token = generate_apitoken.veda_tokengen()
        if self.veda_token == None:
            ErrorObject().print_error(
                message = 'VEDA API Conn Fail:\nInvalid Setup/Method'
                )
            return None

        self.veda_headers = {
            'Authorization': 'Token ' + self.veda_token, # + veda_token,
            'content-type': 'application/json'
            }

        self.veda_video_dict = self.determine_veda_pk()

        """
        Status Update Only
        """
        if self.veda_video_status is not None:
            return self.send_veda_status()
Beispiel #10
0
    def activate(self):
        """
        test case
        """
        if self.veda_id is not None and len(settings['veda_api_url']) == 0:
            logger.error('VEDA API Config Incorrect')
            return

        if self.veda_id is None and self.mezz_filepath is None:
            self.mezz_extension = '.mp4'
            self.mezz_title = TEST_VIDEO_FILE
            self.mezz_filepath = os.path.join(TEST_VIDEO_DIR, TEST_VIDEO_FILE)
            self.valid = True
            return

        if self.veda_id:
            """
            Generated Token
            """
            veda_token = generate_apitoken.veda_tokengen()
            if veda_token is None:
                return None

            data = {
                'edx_id': self.veda_id,
            }
            headers = {
                'Authorization': 'Token ' + veda_token,
                'content-type': 'application/json'
            }
            x = requests.get('/'.join(
                (settings['veda_api_url'], 'videos', '')),
                             params=data,
                             headers=headers)

            vid_dict = json.loads(x.text)
            if len(vid_dict['results']) == 0:
                return None

            for v in vid_dict['results']:
                """
                Yeah this is horrible, but it's tied to VEDA's model

                """
                self.vid_pk = v['id']
                self.class_id = v['inst_class']
                self.course_url = v['course_ids']
                self.val_id = v['studio_id']
                self.mezz_extension = v['video_orig_extension']
                self.mezz_bitrate = v['video_orig_bitrate']
                self.mezz_title = v['client_title']
                self.mezz_filesize = v['video_orig_filesize']
                # Do some field cleaning in case of SAR/DAR legacy errors
                mezz_resolution = v['video_orig_resolution'].strip().split(
                    ' ')[0]
                self.mezz_resolution = mezz_resolution
                '''Clean from unicode (00:00:00.53)'''
                uni_duration = v['video_orig_duration']
                self.mezz_duration = Output.seconds_from_string(uni_duration)
                self.mezz_filepath = '/'.join(
                    ('https://s3.amazonaws.com',
                     settings['veda_s3_hotstore_bucket'],
                     self.veda_id + '.' + self.mezz_extension))
                self.valid = True
        else:
            VV = ValidateVideo(filepath=self.mezz_filepath, VideoObject=self)
            video_dict = VV.get_video_attributes()
            self.mezz_extension = str(os.path.splitext(
                self.mezz_filepath)[1]).replace('.', '')
            self.mezz_bitrate = 0
            self.mezz_title = self.mezz_filepath.split('/')[-1]
            self.mezz_filesize = video_dict['filesize']
            self.mezz_resolution = video_dict['resolution']
            self.mezz_duration = video_dict['duration']
            self.mezz_filepath = self.mezz_filepath
            self.mezz_bitrate = 'Unparsed'
            self.valid = True
Beispiel #11
0
    def activate(self):

        if self.veda_id != None and len(settings['veda_api_url']) == 0:
            ErrorObject().print_error(
                message = 'VEDA API Config Incorrect, run test to debug'
                )
            return None
        """
        test case
        """
        if self.veda_id is None:
            self.mezz_extension = '.mp4'
            self.mezz_title = TEST_VIDEO_FILE
            self.mezz_filepath = os.path.join(TEST_VIDEO_DIR, TEST_VIDEO_FILE)
            self.valid = True
            return None

        """
        Generated Token
        """
        veda_token = generate_apitoken.veda_tokengen()
        if veda_token == None: return None

        data = {
            'edx_id' : self.veda_id,
            }
        headers = {
            'Authorization': 'Token ' + veda_token,
            'content-type': 'application/json'
            }
        x = requests.get(
            '/'.join((settings['veda_api_url'], 'videos', '')),
            params=data, 
            headers=headers
            )

        vid_dict = json.loads(x.text)   
        if len(vid_dict['results']) == 0: return None

        for v in vid_dict['results']:
            """
            Yeah this is horrible, but it's tied to VEDA's model

            """
            self.vid_pk = v['id']
            self.class_id = v['inst_class']
            self.val_id = v['studio_id']
            self.mezz_extension = v['video_orig_extension']
            self.mezz_bitrate = v['video_orig_bitrate']
            self.mezz_title = v['client_title']
            self.mezz_filesize = v['video_orig_filesize']
            '''Do some field cleaning in case of SAR/DAR legacy errors'''
            mezz_resolution = v['video_orig_resolution'].strip().split(' ')[0]
            self.mezz_resolution = mezz_resolution
            '''Clean from unicode (00:00:00.53)'''
            uni_duration = v['video_orig_duration']
            self.mezz_duration = Output._seconds_from_string(uni_duration)
            self.mezz_filepath = '/'.join((
                'https://s3.amazonaws.com', 
                settings['aws_storage_bucket'],
                self.veda_id + '.' + self.mezz_extension
                ))

            self.valid = True