Esempio n. 1
0
def next():
    global videoID
    global ARGS
    global total_input
    global score
    global last_words
    input = list()
    urls = list()
    for i in range(ARGS):
        input.append(request.args.get(str(i)))
        if request.args.get(str(i)) == last_words[i]:
            score += 1
    total_input += input
    ARGS = 0
    last_words.clear()
    input.clear()

    session['CURR_LINE_NUM'] += 1
    curr_list = lines_words[session['CURR_LINE_NUM']]
    last_words = curr_list.copy()
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i].strip(",.!?"))
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()

    return render_template('normal.html')
Esempio n. 2
0
def karaoke_next():
    urls = list()
    session['CURR_LINE_NUM'] += 1
    curr_list = lines_words[session['CURR_LINE_NUM']]
    last_words = curr_list.copy()
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i].strip(",.!?"))
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100 / 5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(
                width
            ) + '''%"><img src="''' + urls[
                i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[
                    i].upper() + '''</p></div>'''
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100 / len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(
                width
            ) + '''%"><img src="''' + urls[
                i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[
                    i].upper() + '''</p></div>'''
        html += '''</div>'''
    else:
        width = 100 / 8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(
                width
            ) + '''%"><img src="''' + urls[
                i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[
                    i].upper() + '''</p></div>'''
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(
                width
            ) + '''%"><img src="''' + urls[
                i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[
                    i].upper() + '''</p></div>'''
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()
    return render_template('karaoke.html')
Esempio n. 3
0
def back():
    global videoID
    # global session['CURR_LINE_NUM']
    urls = list()
    session['CURR_LINE_NUM'] -= 1
    curr_list = lines_words[session['CURR_LINE_NUM']]
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i])
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()

    # start = session['vid_data'][str(session['CURR_LINE_NUM'])][0][0]
    # end = session['vid_data'][str(session['CURR_LINE_NUM'])][0][1]
    # download_yt.get_music_clip(videoID, start, end)
    #
    # dynamic_vid = open('templates/video.html', 'w+')
    # html = '''<audio hidden id="hint" src="static/music/''' + videoID + '''.mp3" type="audio/mpeg" controls>
    # Your browser does not support the audio element.
    # </audio>
    # <button class="btn btn-info" onClick="togglePlay()">Hint</button>'''
    # dynamic_vid.write(html)
    # dynamic_vid.close()

    return render_template('normal.html')
Esempio n. 4
0
def parse_data(data):
    db = "database.db"
    # create a database connection
    conn = database.create_connection(db)
    out = list()
    for i in range(len(data)):
        line = data[i][1]
        print(line)
        words = line.split()
        for word in words:
            # word = word.strip(",.!?;:")
            if database.select_img(conn, word) == None and word not in out:
                out.append(word)
    return out
Esempio n. 5
0
def parse_data(data):
    db = "database.db"
    # create a database connection
    conn = database.create_connection(db)
    out = list()
    k = 0
    for i in range(len(data)):
        line = data[i][1]
        words = line.split()
        for word in words:
            k += 1
            if database.select_img(conn, word) == None and word not in out:
                out.append(word)
    return out, k
Esempio n. 6
0
def back():
    global videoID
    urls = list()
    session['CURR_LINE_NUM'] -= 1
    curr_list = lines_words[session['CURR_LINE_NUM']]
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i])
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()

    dynamic_vid = open('templates/video.html', 'w+')
    html = '''<audio controls>
    <source src="static/music/''' + videoID + '''.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
    </audio>'''
    dynamic_vid.write(html)
    dynamic_vid.close()

    return render_template('normal.html')
Esempio n. 7
0
def normal():
    global videoID
    global lines_words
    global last_words
    global ARGS
    global num_words
    global title
    ARGS = 0
    session['CURR_LINE_NUM'] = 0
    videoIDs = ['E1ZVSFfCk9g', 'CnAmeh0-E-U', 'SlPhMPnQ58k']
    videoID = random.choice(videoIDs)
    if videoID == 'E1ZVSFfCk9g':
        title = "Time"
    elif videoID == 'CnAmeh0-E-U':
        title = "Sucker"
    else:
        title = "Memories"

    # if not path.exists("srt/"+videoID+".srt"):
    #     url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '.csv'
    #     wget.download(url, out="csv/"+videoID+".csv", bar=None)
    #     eng_index = parse_lang.parse_lang("csv/"+videoID + ".csv")
    #     url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '/' + eng_index + '.srt'
    #     filename = wget.download(url, out="srt/"+videoID+".srt", bar=None)

    session['vid_data'] = parse_srt.parse_srt("srt/"+videoID+".srt")
    words, num_words = img_download.parse_data(session['vid_data'])

    urls = list()
    lines_words = img_download.parse_lines_words(session['vid_data'])
    curr_list = lines_words[session['CURR_LINE_NUM']]
    last_words = curr_list.copy()
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i].strip(",.!?"))
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input name="''' + str(i) + '''"type="text" class=dynamic_image></div>'''
            ARGS += 1
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()

    return render_template('normal.html')
Esempio n. 8
0
def karaoke():
    global lines_words
    global videoID

    session['CURR_LINE_NUM'] = 0
    session['SEARCH'] = request.form.get('search')
    search_response = youtube_api.search(query=session['SEARCH'])
    for search_result in search_response.get("items", []):
            if search_result["id"]["kind"] == "youtube#video":
                videoID = search_result['id']['videoId']
    #get .srt file
    # if not path.exists("srt/"+videoID+".srt"):
    #     url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '.csv'
    #     wget.download(url, out="csv/"+videoID+".csv", bar=None)
    #     eng_index = parse_lang.parse_lang("csv/"+videoID + ".csv")
    #     url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '/' + eng_index + '.srt'
    #     filename = wget.download(url, out="srt/"+videoID+".srt", bar=None)
    if path.exists("srt/"+videoID+".srt"):
        session['vid_data'] = parse_srt.parse_srt("srt/"+videoID+".srt")
    else:
        return redirect("/")

    urls = list()

    lines_words = img_download.parse_lines_words(session['vid_data'])

    curr_list = lines_words[session['CURR_LINE_NUM']]
    last_words = curr_list.copy()
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i].strip(",.!?"))
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><p class=dynamic_image>''' + curr_list[i].upper() + '''</p></div>'''
        html += '''</div>'''

    dynamic_image.write(html)
    dynamic_image.close()

    return render_template('karaoke.html')
Esempio n. 9
0
def search():
    global lines_words
    global videoID
    #find videoID from youtube
    # try:
    urls = list()
    session['SEARCH'] = request.form.get('search')
    search_response = youtube_api.search(query=session['SEARCH'])
    for search_result in search_response.get("items", []):
            if search_result["id"]["kind"] == "youtube#video":
                videoID = search_result['id']['videoId']
    #get .srt file
    if not path.exists("srt/"+videoID+".srt"):
        url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '.csv'
        wget.download(url, out="csv/"+videoID+".csv", bar=None)
        eng_index = parse_lang.parse_lang("csv/"+videoID + ".csv")
        url = 'http://www.nitrxgen.net/youtube_cc/' + videoID + '/' + eng_index + '.srt'
        filename = wget.download(url, out="srt/"+videoID+".srt", bar=None)

    session['vid_data'] = parse_srt.parse_srt("srt/"+videoID+".srt")
    words = img_download.parse_data(session['vid_data'])
    # for i in words:
    #     img_download.downloadimages(i)

    lines_words = img_download.parse_lines_words(session['vid_data'])
    curr_list = lines_words[session['CURR_LINE_NUM']]
    conn = database.create_connection("database.db")
    for i in range(len(curr_list)):
        rows = database.select_img(conn, curr_list[i])
        if rows != None:
            urls.append(rows[0])

    dynamic_image = open('templates/images.html', 'w+')
    if len(urls) <= 4:
        width = 100/5
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
    elif len(urls) <= 8:
        width = 100/len(urls)
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
    else:
        width = 100/8
        html = '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''
        html += '''<div class="row justify-content-center" style="margin:20px;">'''
        for i in range(8, len(urls)):
            html += '''<div class=dynamic_image style="width: ''' + str(width) + '''%"><img src="''' + urls[i] + '''" class="dynamic_image"><br><input type="text" class=dynamic_image></div>'''
        html += '''</div>'''


    dynamic_image.write(html)
    dynamic_image.close()
    start = session['vid_data'][session['CURR_LINE_NUM']][0][0]
    end = session['vid_data'][session['CURR_LINE_NUM']][0][1]
    download_yt.get_music_clip(videoID, start, end)

    dynamic_vid = open('templates/video.html', 'w+')
    html = '''<audio controls>
    <source src="static/music/''' + videoID + '''.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
    </audio>'''
    dynamic_vid.write(html)
    dynamic_vid.close()

    return render_template('normal.html')