コード例 #1
0
 def on_get(self, req, resp):
     try:
         key_id = req.params['id']
         if key_id == '':
             raise ImportError
     except ImportError:
         raise falcon.HTTPInvalidParam('Parameter cannot be blank', 'url')
     except:
         raise falcon.HTTPMissingParam(param_name='id (ID of video)')
     with open("yte-logs.json", "r+") as logs_file:
         logs = json.load(logs_file)
         logs_file.close
     if key_id in logs:
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         resp.body = json.dumps(logs[key_id])
         if logs[key_id]['status'] != '200 OK':
             Process(target=self.main, args=(key_id, )).start()
     else:
         check_vid = YouTube('https://www.youtube.com/watch?v=' + key_id)
         if int(check_vid.length) > 600:
             raise falcon.HTTPFailedDependency(
                 description='Video is more than 10 mins long')
         log_create(key_id)
         Process(target=self.main, args=(key_id, )).start()
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         body = {
             'response': 'Process started, GET request again to see status.'
         }
         resp.body = json.dumps(body)
コード例 #2
0
 def test_http_failed_dependency_with_title_and_desc_and_challenges(self):
     try:
         raise falcon.HTTPFailedDependency(title='Test', description='Testdescription')
     except falcon.HTTPFailedDependency as e:
         self.assertEqual('Test', e.title, 'Title should be "Test"')
         self.assertEqual('Testdescription', e.description,
                          'Description should be "Testdescription"')
コード例 #3
0
 def test_http_failed_dependency_no_title_and_desc_and_challenges(self):
     try:
         raise falcon.HTTPFailedDependency()
     except falcon.HTTPFailedDependency as e:
         self.assertEqual(status.HTTP_424, e.title,
                          'The title should be ' + status.HTTP_424 + ', but it is: ' + e.title)
         self.assertEqual(None, e.description, 'The description should be None')
コード例 #4
0
 def on_get(self, req, resp):
     try:
         vid_id = req.params['id']
         start_sec = req.params['s']
         end_sec = req.params['e']
         if id == '' or start_sec == '' or end_sec == '':
             raise ImportError
     except ImportError:
         raise falcon.HTTPInvalidParam('Parameters cannot be blank',
                                       '"id","s","e"')
     except:
         raise falcon.HTTPMissingParam(
             param_name=
             'id (id: video id), s (s: Start, start point of the clip, in seconds), e (e: End, end point of the clip, in seconds)'
         )
     with open("yte-logs.json", "r+") as logs_file:
         logs = json.load(logs_file)
         logs_file.close
     key = vid_id + '_' + start_sec + '_' + end_sec
     if key in logs:
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         resp.body = json.dumps(logs[key])
         if logs[key]['status'] != '200 OK':
             Process(target=self.main,
                     args=(key, vid_id, start_sec, end_sec)).start()
     else:
         check_vid = YouTube('https://www.youtube.com/watch?v=' + vid_id)
         if int(check_vid.length) > 600:
             raise falcon.HTTPFailedDependency(
                 description='Video is more than 10 mins long')
         log_create(key)
         Process(target=self.main,
                 args=(key, vid_id, start_sec, end_sec)).start()
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         body = {
             'response': 'Process started, GET request again to see status.'
         }
         resp.body = json.dumps(body)
コード例 #5
0
 def on_get(self, req, resp):
     try:
         vid_id = req.params['id']
         skip_length = req.params['sl']
         clip_length = req.params['cl']
         if vid_id == '' or skip_length == '' or clip_length == '':
             raise ImportError
     except ImportError:
         raise falcon.HTTPInvalidParam('Parameters cannot be blank',
                                       '"id","sl","cl"')
     except:
         raise falcon.HTTPMissingParam(
             param_name=
             'id (id: video id), sl (sl: Skip Length, how many seconds to pass between clips), cl (cl: Clip Length, length of a single clip)'
         )
     with open("yte-logs.json", "r+") as logs_file:
         logs = json.load(logs_file)
         logs_file.close
     key = vid_id + '_' + skip_length + '_' + clip_length
     if key in logs:
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         resp.body = json.dumps(logs[key])
         if logs[key]['status'] != '200 OK':
             Process(target=self.main,
                     args=(key, vid_id, skip_length, clip_length)).start()
     else:
         check_vid = YouTube('https://www.youtube.com/watch?v=' + vid_id)
         if int(check_vid.length) > 600:
             raise falcon.HTTPFailedDependency(
                 description='Video is more than 10 mins long')
         log_create(key)
         Process(target=self.main,
                 args=(key, vid_id, skip_length, clip_length)).start()
         resp.content_type = 'json'
         resp.status = falcon.HTTP_200
         body = {
             'response': 'Process started, GET request again to see status.'
         }
         resp.body = json.dumps(body)