Exemple #1
0
def seek_to_seconds_get():
    logger('Fetch seek to seconds')
    cur.execute("SELECT Id, Seconds FROM " + SQLITE['seektable'] +
                " WHERE Id=1")
    data = cur.fetchone()
    res = 0
    if data:
        res = data[1]
    return flask.jsonify({'status': 'ok', 'data': res}), 200
Exemple #2
0
def musics_get():
    logger('Fetch last music')
    rep = cur.execute("SELECT * FROM " + SQLITE['musictable'] +
                      " ORDER BY Datetime LIMIT 1")
    music = rep.fetchone()
    d = {
        'id': music[0],
        'datetime': music[1],
        'link': music[2],
        'categoryId': music[3],
        'duration': music[4],
        'durationSeconds': music[5],
        'videoId': music[6],
        'title': music[7]
    }
    return flask.jsonify({'status': 'ok', 'data': d}), 200
Exemple #3
0
def music_info_get(music_id):
    if not flask.request.is_xhr:  # check ajax request
        return app.send_static_file('index.html')
        #return flask.jsonify({'status': 'error', 'message': 'Error'}), 400
    check_youtube_id = youtube_id_regex.findall(str(music_id))
    if len(check_youtube_id) > 0:
        if check_youtube_id[0] != str(music_id):
            return app.send_static_file('index.html')
            #return flask.jsonify({'status': 'error', 'message': 'Error'}), 400
    logger('Check the music')
    url = GOOGLE[
        'endpoint'] + '?part=id,contentDetails,snippet&id=' + music_id + '&key=' + GOOGLE[
            'apikey']
    response = requests.get(url)
    data = response.json()
    item = data.get('items')[0]
    duration = item.get('contentDetails')['duration']
    video_id = item.get('id')
    category_id = item.get('snippet')['categoryId']
    title = item.get('snippet')['title']
    duration_s = duration_seconds(duration)
    # TODO: check category & sensitive content
    good_d = good_duration(duration)
    good_c = good_category(category_id)
    if good_d and good_c:  # if song is okay
        date = datetime.datetime.now()
        link = 'https://www.youtube.com/watch?v=' + video_id
        # push into the db
        cur.execute(
            "INSERT INTO " + SQLITE['musictable'] + """
            (Datetime,Link,CategoryId,Duration,DurationSeconds,VideoId,Title)
            VALUES (?,?,?,?,?,?,?)""",
            (date, link, category_id, duration, duration_s, video_id, title))
        return flask.jsonify({
            'status': 'ok',
            'message': 'Thanks for your contribution :)'
        }), 200
    else:
        return flask.jsonify({
            'status': 'error',
            'message': 'Sorry, video is not valid ..'
        }), 200
def loop():
    rep = cur.execute("SELECT VideoId, DurationSeconds FROM " + SQLITE['musictable'] + " ORDER BY Datetime LIMIT 1 ")
    data = rep.fetchone()
    if data:
        video_id, duration_seconds = data[0], data[1]
        logger(video_id + ' ' + str(duration_seconds))
        # seconds time loop procedure
        t0 = time.time()
        t1 = int(time.time() - t0)
        t_tmp = t1
        while t1 < duration_seconds:
            t1 = int(time.time() - t0)
            if t1 != t_tmp: # update every seconds
                cur.execute("UPDATE " + SQLITE['seektable'] + " SET Seconds = ? WHERE Id = ?", (t1, 1))
                #print t1
                t_tmp = t1
            if t1 >= duration_seconds:
                logger('Delete song')
                cur.execute("DELETE FROM " + SQLITE['musictable'] + " WHERE VideoId = ? ", (video_id,))
                break
Exemple #5
0
def show_musics_get():
    logger('Fetch musics playlist and total number')
    rep = cur.execute("SELECT * FROM " + SQLITE['musictable'] +
                      " ORDER BY Datetime LIMIT 11")
    musics = rep.fetchall()
    res = list()
    for music in musics[1:]:
        d = {
            'id': music[0],
            'datetime': music[1],
            'link': music[2],
            'categoryId': music[3],
            'duration': music[4],
            'durationSeconds': music[5],
            'videoId': music[6],
            'title': music[7]
        }
        res.append(d)
    cur.execute("SELECT Count(*) FROM " + SQLITE['musictable'])
    data2 = cur.fetchone()
    res2 = 0
    if data2:
        res2 = data2[0] - 1
    return flask.jsonify({'status': 'ok', 'data': res, 'data2': res2}), 200
Exemple #6
0
def dashboard():
    logger('Enter the website')
    return app.send_static_file('index.html')