#!/usr/bin/env python
from __future__ import print_function
import pygame as pg
import termcolor
import time, sys
from threading import Thread

class Output(Thread):

    def __init__(self):
        Thread.__init__(self)
        self.running = True

    def run(self):
        time.sleep(0.9)
        while self.running:
            for color in ['green', 'blue', 'red', 'cyan', 'yellow', 'magenta']:
                sys.stdout.write(termcolor.colored('on s\'en bat les couilles\n', color))
                sys.stdout.flush()
                time.sleep(0.5)


def play_music(music_file, volume=0.8):
    freq = 44100
    bitsize = -16
    channels = 2
    buffer = 2048
    pg.mixer.init(freq, bitsize, channels, buffer)
    pg.mixer.music.set_volume(volume)
    clock = pg.time.Clock()
    try:
        pg.mixer.music.load(music_file)
    except pg.error:
        return
    pg.mixer.music.play()
    while pg.mixer.music.get_busy():
        clock.tick(30)

music_file = 'osblc.mp3'
volume = 0.8

if __name__ == '__main__':

    try:
        import pkg_resources
        path = pkg_resources.resource_stream('osblc_lib', music_file)
        thread = Output()
        thread.start()
        play_music(path, volume)
        thread.running = False

    except (KeyboardInterrupt, SystemExit):
        thread.running = False
