# Path: core/config.py
# PLATFORM_NAME = "kodi-isengard"
# PLUGIN_NAME = "streamondemand-pureita-master"
# def get_platform():
# def is_xbmc():
# def get_library_support():
# def get_system_platform():
# def open_settings():
# def get_setting(name):
# def set_setting(name,value):
# def get_localized_string(code):
# def get_library_path():
# def get_temp_file(filename):
# def get_runtime_path():
# def get_data_path():
# def get_cookie_data():
# def verify_directories_created():
# 
# Path: core/logger.py
# def log_enable(active):
# def encode_log(message=""):
# def get_caller(message=None):
# def info(texto=""):
# def debug(texto=""):
# def error(texto=""):
# 
# Path: core/downloadtools.py
# def limpia_nombre_caracteres_especiales(s):
# def limpia_nombre_sin_acentos(s):
# def limpia_nombre_excepto_1(s):
# def limpia_nombre_excepto_2(s):
# def getfilefromtitle(url,title):
# def downloadtitle(url,title):
# def downloadbest(video_urls,title,continuar=False):
# def downloadfile(url,nombrefichero,headers=[],silent=False,continuar=False):
# def downloadfileGzipped(url,pathfichero):
# def GetTitleFromFile(title):
# def sec_to_hms(seconds):
# def downloadIfNotModifiedSince(url,timestamp):


import os
import sys
import re
import urlparse
import urllib
import urllib2
import locale
import threading
import time
import socket
import xbmc
import xbmcgui
        import subprocess
                import traceback,sys
from core import config
from core import logger
from core import downloadtools
            from servers import filenium
                from pprint import pprint
def download_and_play(url,file_name,download_path):
    # Lanza thread
    logger.info("[download_and_play.py] Active threads "+str(threading.active_count()))
    logger.info("[download_and_play.py] "+repr(threading.enumerate()))
    logger.info("[download_and_play.py] Starting download thread...")
    download_thread = DownloadThread(url,file_name,download_path)
    download_thread.start()
    logger.info("[download_and_play.py] Download thread started")
    logger.info("[download_and_play.py] Active threads "+str(threading.active_count()))
    logger.info("[download_and_play.py] "+repr(threading.enumerate()))

    # Espera
    logger.info("[download_and_play.py] Waiting...")

    while True:
        cancelled=False
        dialog = xbmcgui.DialogProgress()
        dialog.create('Download in corso ... ', 'Chiudi questa finestra per avviare la riproduzione)
        dialog.update(0)

        while not cancelled and download_thread.is_alive():
            dialog.update( download_thread.get_progress() , "Chiudi questa finestra per avviare la riproduzione", "Velocita: "+str(int(download_thread.get_speed()/1024))+" KB/s "+str(download_thread.get_actual_size())+"MB de "+str(download_thread.get_total_size())+"MB" , "Tempo restante: "+str( downloadtools.sec_to_hms(download_thread.get_remaining_time())) )
            xbmc.sleep(1000)

            if dialog.iscanceled():
                cancelled=True
                break

        dialog.close()


# Path: core/config.py
# PLATFORM_NAME = "kodi-isengard"
# PLUGIN_NAME = "streamondemand-pureita-master"
# def get_platform():
# def is_xbmc():
# def get_library_support():
# def get_system_platform():
# def open_settings():
# def get_setting(name):
# def set_setting(name,value):
# def get_localized_string(code):
# def get_library_path():
# def get_temp_file(filename):
# def get_runtime_path():
# def get_data_path():
# def get_cookie_data():
# def verify_directories_created():
# 
# Path: core/logger.py
# def log_enable(active):
# def encode_log(message=""):
# def get_caller(message=None):
# def info(texto=""):
# def debug(texto=""):
# def error(texto=""):
# 
# Path: core/downloadtools.py
# def limpia_nombre_caracteres_especiales(s):
# def limpia_nombre_sin_acentos(s):
# def limpia_nombre_excepto_1(s):
# def limpia_nombre_excepto_2(s):
# def getfilefromtitle(url,title):
# def downloadtitle(url,title):
# def downloadbest(video_urls,title,continuar=False):
# def downloadfile(url,nombrefichero,headers=[],silent=False,continuar=False):
# def downloadfileGzipped(url,pathfichero):
# def GetTitleFromFile(title):
# def sec_to_hms(seconds):
# def downloadIfNotModifiedSince(url,timestamp):


# Path: platformcode/download_and_play.py
import os
import sys
import re
import urlparse
import urllib
import urllib2
import locale
import threading
import time
import socket
import xbmc
import xbmcgui
        import subprocess
                import traceback,sys
from core import config
from core import logger
from core import downloadtools
            from servers import filenium
                from pprint import pprint

def download_and_play(url,file_name,download_path):
    # Lanza thread
    logger.info("[download_and_play.py] Active threads "+str(threading.active_count()))
    logger.info("[download_and_play.py] "+repr(threading.enumerate()))
    logger.info("[download_and_play.py] Starting download thread...")
    download_thread = DownloadThread(url,file_name,download_path)
    download_thread.start()
    logger.info("[download_and_play.py] Download thread started")
    logger.info("[download_and_play.py] Active threads "+str(threading.active_count()))
    logger.info("[download_and_play.py] "+repr(threading.enumerate()))

    # Espera
    logger.info("[download_and_play.py] Waiting...")

    while True:
        cancelled=False
        dialog = xbmcgui.DialogProgress()
        dialog.create('Download in corso ... ', 'Chiudi questa finestra per avviare la riproduzione)
        dialog.update(0)

        while not cancelled and download_thread.is_alive():
            dialog.update( download_thread.get_progress() , "Chiudi questa finestra per avviare la riproduzione", "Velocita: "+str(int(download_thread.get_speed()/1024))+" KB/s "+str(download_thread.get_actual_size())+"MB de "+str(download_thread.get_total_size())+"MB" , "Tempo restante: "+str( downloadtools.sec_to_hms(download_thread.get_remaining_time())) )
            xbmc.sleep(1000)

            if dialog.iscanceled():
                cancelled=True
                break

        dialog.close()


        logger.info("[download_and_play.py] End of waiting")