# Path: resources/lib/modules/workers.py
# class Thread(threading.Thread):
# class Workers:
#     def __init__(self, target, *args):
#     def run(self):
#     def get_result(self):
#     def globaltrace(self, frame, event, arg):
#     def localtrace(self, frame, event, arg):
#     def kill(self):
#     def __init__(self, concurrent=30, queue_size=None, target=None, expect_result=True):
#         def _queue_worker():
#     def put(self, item):
#     def join(self):
#     def terminate(self):
# 
# Path: resources/lib/modules/util.py
# class struct(object):
#     def __init__(self, kdict=None):
#     def __repr__(self):
#     def __getattr__(self, name):
#     def __len__(self):
#     def get(self, key):
# def getMPAAFromCI(ci):
# def getBestBitrateUrl(plugin, streams):
# def merge_dicts(x, *argv):
# def slugify(string):
# def unescape(text):
#     def fixup(m):
# def time_format(time_str=None, input_format=None):
# def get_signed_hashes(a):
# def J(a):
# def K(a):
# def L():
# def M(a):
# def N():
# def O(a):
# def P(a):
# def get_utc_delta():
# def strptime(date_string, format):
# def strptime_workaround(date_string, format='%Y-%m-%dT%H:%M:%S'):
# def get_total_seconds(timedelta):
# def get_total_seconds_float(timedelta):
# def get_total_hours(timedelta):
# def add_url_parameters(url, params):
# def is_number(s):
# G = 3600
# H = "=0xAC10FD"
# 
# Path: resources/lib/modules/cache.py
# def get(function, timeout_hour, *args, **kargs):
# def clear_item(function, *args, **kargs):
# def __get_from_cache(dbcur, table, f, a, timeout_hour):
# def __execute_origin(dbcur, dbcon, function, table, f, a, response, *args, **kargs):
# def delete_file():
# def clear(table=None):


import requests
import datetime
import player
from resources.lib.modules import workers
from resources.lib.modules import util
from resources.lib.modules import cache
        # 'title': episode_title,
        'tvshowtitle': title,
        'sorttitle': program_name,
        'channel_id': response['prgSvcId'],
        'dateadded': datetime.datetime.strftime(date, '%Y-%m-%d %H:%M:%S'),
        'plot': description,
        'tag': tags,
        'duration': now['durationSeconds'],
        'adult': program['isAdult'],
        'cast': cast,
        'director': program['directors'],
        'genre': program['genres'],
        'rating': program['rating'],
        'year': program['releaseYear'],
        'episode': program['episodeNumber'] if program['episodeNumber'] else None,
        'season': program['seasonNumber'] if program['seasonNumber'] else None,
        'art': {
            'icon': logo,
            'thumb': thumb,
            'tvshow.poster': thumb,
            'clearlogo': logo,
            'fanart': fanart
        }
    }


def get_epg(start, end, channel_map):
    start_time = datetime.datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
    end_time = datetime.datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
    url = 'https://apim.oi.net.br/app/oiplay/ummex/v1/epg?starttime={starttime}&endtime={endtime}&liveSubscriberGroup={channelmap}'.format(starttime=start_time, endtime=end_time, channelmap=channel_map)

# Path: resources/lib/modules/workers.py
# class Thread(threading.Thread):
# class Workers:
#     def __init__(self, target, *args):
#     def run(self):
#     def get_result(self):
#     def globaltrace(self, frame, event, arg):
#     def localtrace(self, frame, event, arg):
#     def kill(self):
#     def __init__(self, concurrent=30, queue_size=None, target=None, expect_result=True):
#         def _queue_worker():
#     def put(self, item):
#     def join(self):
#     def terminate(self):
# 
# Path: resources/lib/modules/util.py
# class struct(object):
#     def __init__(self, kdict=None):
#     def __repr__(self):
#     def __getattr__(self, name):
#     def __len__(self):
#     def get(self, key):
# def getMPAAFromCI(ci):
# def getBestBitrateUrl(plugin, streams):
# def merge_dicts(x, *argv):
# def slugify(string):
# def unescape(text):
#     def fixup(m):
# def time_format(time_str=None, input_format=None):
# def get_signed_hashes(a):
# def J(a):
# def K(a):
# def L():
# def M(a):
# def N():
# def O(a):
# def P(a):
# def get_utc_delta():
# def strptime(date_string, format):
# def strptime_workaround(date_string, format='%Y-%m-%dT%H:%M:%S'):
# def get_total_seconds(timedelta):
# def get_total_seconds_float(timedelta):
# def get_total_hours(timedelta):
# def add_url_parameters(url, params):
# def is_number(s):
# G = 3600
# H = "=0xAC10FD"
# 
# Path: resources/lib/modules/cache.py
# def get(function, timeout_hour, *args, **kargs):
# def clear_item(function, *args, **kargs):
# def __get_from_cache(dbcur, table, f, a, timeout_hour):
# def __execute_origin(dbcur, dbcon, function, table, f, a, response, *args, **kargs):
# def delete_file():
# def clear(table=None):


# Path: resources/lib/modules/oiplay/scraper_live.py
import requests
import datetime
import player
from resources.lib.modules import workers
from resources.lib.modules import util
from resources.lib.modules import cache

        # 'title': episode_title,
        'tvshowtitle': title,
        'sorttitle': program_name,
        'channel_id': response['prgSvcId'],
        'dateadded': datetime.datetime.strftime(date, '%Y-%m-%d %H:%M:%S'),
        'plot': description,
        'tag': tags,
        'duration': now['durationSeconds'],
        'adult': program['isAdult'],
        'cast': cast,
        'director': program['directors'],
        'genre': program['genres'],
        'rating': program['rating'],
        'year': program['releaseYear'],
        'episode': program['episodeNumber'] if program['episodeNumber'] else None,
        'season': program['seasonNumber'] if program['seasonNumber'] else None,
        'art': {
            'icon': logo,
            'thumb': thumb,
            'tvshow.poster': thumb,
            'clearlogo': logo,
            'fanart': fanart
        }
    }


def get_epg(start, end, channel_map):
    start_time = datetime.datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
    end_time = datetime.datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
    url = 'https://apim.oi.net.br/app/oiplay/ummex/v1/epg?starttime={starttime}&endtime={endtime}&liveSubscriberGroup={channelmap}'.format(starttime=start_time, endtime=end_time, channelmap=channel_map)

    epg = cache.get(requests.get, 20, url, table='oiplay').json()