<commit_before>#!/usr/bin/python
import sys
import time
import os
import sqlite3
import stat

def start(file):
    cmd = 'mplayer "' + file + '" < fifo > /dev/null 2>&1 &'
    os.system(cmd)
    os.system('echo -n . > fifo')

def pause():
        os.system('echo -n "p" > fifo')

def startup_checks():

    # Check if pipe exists. If not, create it.
    try:
        fifo_exists = stat.S_ISFIFO(os.stat('fifo').st_mode)
    except OSError as e:
        fifo_exists = False 
    print fifo_exists
    if fifo_exists == False:
        try:
            os.mkfifo('fifo')
        except OSError:
            os.remove('fifo')
            os.mkfifo('fifo')
    
    if os.path.isfile('omxremote.db') == False:
        
if __name__ == '__main__':
    startup_checks()
    #conn = sqlite3.connect("omxremote.db")
    #cursor = conn.cursor()
    #create table
    #cursor.execute("""CREATE TABLE library
    #                    (key, file, size)
    #                """)

    #cursor.execute("INSERT INTO library VALUES ('1', 'home/brian/Music/The Wallflowers - Cinderella.mp3', '383420')")
    #conn.commit()
    #sql = "SELECT file FROM library WHERE key=1"
    #for row in cursor.execute(sql):
    #    print row
    #    file = row[0]
    #print file
    if sys.argv[1] == 'start':
        start("/home/brian/Music/The Wallflowers - Cinderella.mp3")
    if sys.argv[1] == 'pause':
        pause()
    if sys.argv[1] == 'stop':
        os.system('echo -n "q" > fifo')


<commit_msg>adds sqlite db check and recursive file entry into library<commit_after>#!/usr/bin/python
import sys
import time
import os
import sqlite3
import stat

def start(file):
    cmd = 'mplayer "' + file + '" < fifo > /dev/null 2>&1 &'
    os.system(cmd)
    os.system('echo -n . > fifo')

def pause():
        os.system('echo -n "p" > fifo')

def startup_checks():

    # Check if pipe exists. If not, create it.
    try:
        fifo_exists = stat.S_ISFIFO(os.stat('fifo').st_mode)
    except OSError as e:
        fifo_exists = False 
    if fifo_exists == False:
        try:
            os.mkfifo('fifo')
        except OSError:
            os.remove('fifo')
            os.mkfifo('fifo')
    
    # Check if sqlite db file exists. If not... initialize it.
    if os.path.isfile('omxremote.db') == False:
        conn = sqlite3.connect("omxremote.db")
        cursor = conn.cursor()
        sql = "CREATE TABLE library (key INTEGER PRIMARY KEY AUTOINCREMENT, name, path UNIQUE, type, size)"
        cursor.execute(sql)
        conn.commit()
    else:
        conn = sqlite3.connect("omxremote.db")
        cursor = conn.cursor()
        sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='library'"
        cursor.execute(sql)
        cursor.fetchall()
        if cursor.rowcount == 0:
            cursor.execute("CREATE TABLE library (key INTEGER PRIMARY KEY AUTOINCREMENT, name, path UNIQUE, type, size)")
            conn.commit()

def add_path_to_library(path, recurse = 1):
    file_exts = ['.mp3', '.avi', '.mp4', '.mkv', '.flac']
    conn = sqlite3.connect("omxremote.db")
    cursor = conn.cursor()
    dirs = os.walk(path)
    if recurse == 1:
        for directory in dirs:
            for filename in directory[2]:
                if os.path.splitext(filename)[1] in file_exts:
                    #print directory[0].strip() + "/" + filename.strip()
                    path = directory[0].strip() + "/" + filename.strip()
                    name = os.path.splitext(filename)[0]
                    ext = os.path.splitext(filename)[1]
                    size = os.path.getsize(path)
                    try:
                        cursor.execute("INSERT INTO library (name, path, type, size) VALUES ( ?, ?, ?, ?)", (name, path, ext, size))
                    except sqlite3.IntegrityError:
                            continue
    conn.commit()


if __name__ == '__main__':
    startup_checks()

    if sys.argv[1] == 'start':
        start("/home/brian/Music/The Wallflowers - Cinderella.mp3")
    if sys.argv[1] == 'pause':
        pause()
    if sys.argv[1] == 'stop':
        os.system('echo -n "q" > fifo')
    if sys.argv[1] == 'next':
        os.system('echo -n "" > fifo')
    #add_path_to_library("/home/brian/usb")



{'fraction_non_alphanumeric': 0.14427390791027156, 'fraction_numerical': 0.009681227863046045, 'mean_word_length': 2.0807272727272728, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4955197', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1378, 'n_words': 342}