def update_db():
    with sql.connect(db_name) as conn:
        for query in queries:
            for page in range(1, 4):
                print(query, page)
                search_page = download_search_page(query, page)
                video_list = parse_search_page(search_page)

                for video in video_list:
                    video_page = download_video_page(video['link'])
                    video_json_data = parse_video_page(video_page)

                    if 'watch-time-text' not in video_json_data:
                        continue

                    p = compute_prediction(video_json_data)

                    video_id = video_json_data.get('og:video:url', '')
                    watch_title = video_json_data['watch-title'].replace(
                        "'", "")
                    data_front = {
                        "title": watch_title,
                        "score": float(p),
                        "video_id": video_id
                    }
                    data_front['update_time'] = time.time_ns()

                    print(video_id, json.dumps(data_front))
                    c = conn.cursor()
                    c.execute(
                        "INSERT INTO videos VALUES ('{title}', '{video_id}', {score}, {update_time})"
                        .format(**data_front))
                    conn.commit()
    return True
Esempio n. 2
0
def predict():
    out = []

    #     if PredForm(request.form).validate_on_submit():
    #         yt_video_pred = request.form.yt_video_id

    yt_video_pred = request.args.get('vid_id')

    #     yt_video_id = request.args.get("yt_video_id", default='')

    ydl = youtube_dl.YoutubeDL({"ignoreerrors": True})
    #     video_json_data = ydl.extract_info("https://www.youtube.com/watch?v={}".format(yt_video_id), download=False)
    video_json_data = ydl.extract_info(
        "https://www.youtube.com/watch?v={}".format(yt_video_pred),
        download=False)

    if video_json_data is None:
        return "not found"

    p = ml_utils.compute_prediction(video_json_data)

    out.append(video_json_data['title'])
    out.append(video_json_data['webpage_url'])
    out.append(p)
    #     output = {"title": video_json_data['title'], "score": p}

    #     return json.dumps(output)
    #     out = json.dumps(output)

    return render_template('predict.html', out=out)
def update_db():
    with sql.connect(db_name) as conn:
        for keyword in keywords:
            for page in range(1, 4):
                search_page = get_data.download_search_page(keyword, page)
                videos_list = get_data.parse_search_page(search_page)

                for video in videos_list:
                    video_page = get_data.download_video_page(video['link'])
                    video_json_data = get_data.parse_video_page(video_page)

                    if 'watch-time-text' not in video_json_data:  # if the video parsed does not have a title, discard
                        continue

                    p = compute_prediction(video_json_data)

                    video_id = video_json_data.get('og:video:url', '')
                    video_title = video_json_data['watch-title'].replace(
                        "'", "''")
                    data_front = {
                        "title": video_title,
                        "score": float(p),
                        "video_id": video_id
                    }

                    print(video_id, json.dumps(data_front))
                    cursor = conn.cursor()
                    cursor.execute(
                        "INSERT INTO videos VALUES ('{title}', '{video_id}', {score})"
                        .format(**data_front))
                    conn.commit()

    return True
Esempio n. 4
0
def predict_api():
    yt_video_id = request.args.get("yt_video_id", default='')
    
    ydl = youtube_dl.YoutubeDL({"ignoreerrors": True})
    video_json_data = ydl.extract_info("https://www.youtube.com/watch?v={}".format(yt_video_id), download=False)

    if video_json_data is None:
        return "not found"

    p = ml_utils.compute_prediction(video_json_data)
    output = {"title": video_json_data['title'], "score": p}

    return json.dumps(output)
Esempio n. 5
0
def predict_api():
    yt_video_id = request.args.get("yt_video_id", default='')
    video_page = get_data.download_video_page(
        "/watch?v={}".format(yt_video_id))
    video_json_data = get_data.parse_video_page(video_page)

    if 'watch-time-text' not in video_json_data:
        return "not found"

    p = ml_utils.compute_prediction(video_json_data)
    output = {"title": video_json_data['watch-title'], "score": p}

    return json.dumps(output)
Esempio n. 6
0
def predict_api(id_video):

    ydl = youtube_dlc.YoutubeDL({"ignoreerrors": True})
    video_json_data = ydl.extract_info(
        "https://www.youtube.com/watch?v={}".format(id_video), download=False)

    if video_json_data is None:
        return "not found"

    p = ml_utils.compute_prediction(video_json_data)
    output = {
        "title": video_json_data['title'],
        "score": p,
        "link": "https://www.youtube.com/watch?v={}".format(id_video)
    }

    return output