예제 #1
0
def video_info():
    if request.method == 'POST':
        # specific for 'try it' on /
        # since it is my own api_key used for now...
        if request.form.get('api_key_test') is not None:
            api_key = app.config['api_key_test']
        elif 'api_key' in session:
            api_key = session['api_key']
        else:
            return render_template('explore.html',
                                   message="""
                <h4><strong class="text-danger">You can try Pytheas but to go further you will need to get an api_key from Google services
                <br>Please go to <a href="./config" class="btn btn-primary btn-lg active" role="button" aria-pressed="true">Config</a> and follow guidelines</strong></h4>
                """)

        id_video = request.form.get('unique_id_video')
        id_video = YouTube.cleaning_video(id_video)
        part = ', '.join(request.form.getlist('part'))
        api = YouTube(api_key=api_key)
        video_result = api.get_query('videos', id=id_video, part=part)
        video_result_string = json.dumps(video_result,
                                         sort_keys=True,
                                         indent=2,
                                         separators=(',', ': '))
        return render_template('methods/view_results.html',
                               result=video_result,
                               string=video_result_string)
    return render_template('explore.html')
예제 #2
0
def video(payload=None):
    if request.method == 'POST':
        if not 'api_key' in session:
            return render_template('config.html', message='api key not set')
        query_id = str(uuid4())
        user_id = session['profil']['id']
        query_name = str(request.form.get('name_query'))
        part = ', '.join(request.form.getlist('part'))

        # come from input_csv
        if payload:
            query_name = payload['query']
            part = payload['part']
            list_videos = payload['videos']
            list_videos = [YouTube.cleaning_video(x) for x in list_videos]
        else:
            list_videos = request.form.get('list_videos').splitlines()
            list_videos = [YouTube.cleaning_video(x) for x in list_videos]

        param = {
            'query_id': query_id,
            'query': query_name,
            'part': part,
            'api_key': session['api_key'],
            'kind': 'videosList',
            'videos': list_videos,
        }
        r_query = requests.post("http://restapp:" + app.config['REST_PORT'] +
                                "/" + user_id + "/add_query/" + query_id,
                                json=param)

        def send_request():
            requests.post("http://restapp:" + app.config['REST_PORT'] + "/" +
                          user_id + "/query/" + query_id + "/add_video/videos",
                          json=param)

        Thread(target=send_request).start()
    return render_template('methods/download_process.html')