<commit_before>import threading
import time
import pygame
import subprocess 
import socket

#Properties
WAIT_UNTIL_DATA = False
USING_PYGAME = False
USING_OMXPLAYER = True
ENABLE_DISCOVERY = True

#Globals
START_PLAYER = None
GETDATATHREAD = None
MY_NAME = "PI Speakers"
player = None
sock = None

def replyToDiscovery(sock):
  print "some connection"
  a = sock.recv(100);
  print "got something here = ", a
  if a == "hello":
    print "Discovery Successful!!"
    sock.write("Hi my name is " + MY_NAME)

def EnableDiscovery():
  sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  sock.bind(('',9081))
  sock.listen(1)
  while(True):
    connection, address = sock.accept()
    t1 = threading.Thread(target=replyToDiscovery, args = (connection,))
    t1.start()

def startDiscovery():
  t1 = threading.Thread(target=EnableDiscovery)
  t1.start()  

def aplayer(): 
  file = "temp.mp3"
  #pygame.time.Clock().tick(100)
  pygame.mixer.music.stop()
  pygame.mixer.music.set_volume(1.0)
  pygame.mixer.music.load(file)
  pygame.mixer.music.play()
  print "Playing .."

def omxplayer():
  global player
  if player != None:
    try:
      player.stdin.write("q")
    except:
      pass
    player.kill()
    player = None
  player = subprocess.Popen(["omxplayer", "temp.mp3"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  print "Playing .."

def init():
  print "Initializing Jukebox-pi..."
  global START_PLAYER
  if USING_PYGAME == True:
    pygame.init()
    pygame.mixer.init()
    START_PLAYER = aplayer
    print "Setting PYGAME as default player"
  elif USING_OMXPLAYER == True:
    START_PLAYER = omxplayer    
    print "Setting OMXPLAYER as default player"

def initsockets():
  global sock
  sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  sock.bind(('',8087))
  sock.listen(1)

def getData(connection):
  global f
  if f != None:
    f.close()
  f = open("temp.mp3","wb")
  f.write(connection.recv(38000))
  START_PLAYER()
  data = connection.recv(512)
  while len(data):
    f.write(data)
    data = connection.recv(512)

def startdatathread(connection):
  global GETDATATHREAD
  GETDATATHREAD = threading.Thread(target=someFunc)
  GETDATATHREAD.start()

init()
initsockets()

if ENABLE_DISCOVERY == True:
  startDiscovery()

f = None
print "Jukebox-pi is good to go!"
while True:  
  connection, address = sock.accept()
  getData(connection)
<commit_msg>some change<commit_after>import threading
import time
import pygame
import subprocess 
import socket

#Properties
WAIT_UNTIL_DATA = False
USING_PYGAME = False
USING_OMXPLAYER = True
ENABLE_DISCOVERY = True

#Globals
START_PLAYER = None
GETDATATHREAD = None
MY_NAME = "PI Speakers"
player = None
sock = None

def replyToDiscovery(sock3):
  print "some connection"
  a = sock3.recv(100);
  print "got something here = ", a
  if a == "hello":
    print "Discovery Successful!!"
    sock3.write("Hi my name is " + MY_NAME)

def EnableDiscovery():
  sock2 = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  sock2.bind(('',9081))
  sock2.listen(1)
  while(True):
    connection, address = sock2.accept()
    t1 = threading.Thread(target=replyToDiscovery, args = (connection,))
    t1.start()

def startDiscovery():
  t1 = threading.Thread(target=EnableDiscovery)
  t1.start()  

def aplayer(): 
  file = "temp.mp3"
  #pygame.time.Clock().tick(100)
  pygame.mixer.music.stop()
  pygame.mixer.music.set_volume(1.0)
  pygame.mixer.music.load(file)
  pygame.mixer.music.play()
  print "Playing .."

def omxplayer():
  global player
  if player != None:
    try:
      player.stdin.write("q")
    except:
      pass
    player.kill()
    player = None
  player = subprocess.Popen(["omxplayer", "temp.mp3"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  print "Playing .."

def init():
  print "Initializing Jukebox-pi..."
  global START_PLAYER
  if USING_PYGAME == True:
    pygame.init()
    pygame.mixer.init()
    START_PLAYER = aplayer
    print "Setting PYGAME as default player"
  elif USING_OMXPLAYER == True:
    START_PLAYER = omxplayer    
    print "Setting OMXPLAYER as default player"

def initsockets():
  global sock
  sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  sock.bind(('',8087))
  sock.listen(1)

def getData(connection):
  global f
  if f != None:
    f.close()
  f = open("temp.mp3","wb")
  f.write(connection.recv(38000))
  START_PLAYER()
  data = connection.recv(512)
  while len(data):
    f.write(data)
    data = connection.recv(512)

def startdatathread(connection):
  global GETDATATHREAD
  GETDATATHREAD = threading.Thread(target=someFunc)
  GETDATATHREAD.start()

init()
initsockets()

if ENABLE_DISCOVERY == True:
  startDiscovery()

f = None
print "Jukebox-pi is good to go!"
while True:  
  connection, address = sock.accept()
  getData(connection)

{'fraction_non_alphanumeric': 0.1256479369686917, 'fraction_numerical': 0.016379846568525813, 'mean_word_length': 3.942622950819672, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '278822', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1744, 'n_words': 385}