# Path: epymc/extapi/onlinevideo.py
# ACT_DEFAULT = 0
# ACT_NONE = 1
# ACT_FOLDER = 2
# ACT_MORE = 3
# ACT_PLAY = 4
# ACT_SEARCH = 5
# def state_get():
# def language_get():
# def item_add(next_state, label, url, info=None, icon=None, poster=None, action=ACT_DEFAULT):
# def play_url(url):
# def report_error(msg):
# def local_resource(_file_, res):
# def fetch_url(url, headers=None, parser=None):
# def ydl_executable():
# def call_ydl(url):
# def url_encode(params):
# def seconds_to_duration(seconds):
# def relative_date(date):
# def format_date(date):


from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, url_encode, language_get, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH
    return (IMG_BASE + '/' + size + img) if img else None


def movie_item(movie_data):
    title = movie_data['title']
    poster = full_img_url(movie_data['poster_path'])
    url = '/movie/%d?append_to_response=credits,videos' % movie_data['id']
    item_add(ST_MOVIE_INFO, title, url, poster=poster)


def next_page_item(url, data, next_state):
    if data['page'] < data['total_pages']:
        page = data['page']
        if '&page=' in url:
            next_url = url.replace('&page=%d' % (page), '&page=%d' % (page + 1))
        else:
            if not '?' in url: url += '?'
            next_url = url + '&page=%d' % (page + 1)
        text = _('Load more results (page {0} of {1})').format(page, data['total_pages'])
        item_add(next_state, text, next_url, action=ACT_MORE)


################################################################################
# home page
################################################################################
if STATE == ST_HOME:
    item_add(ST_SEARCH, _('Search movies'), 'search', action=ACT_SEARCH)
    item_add(ST_MOVIES_LIST, _('Popular movies'), '/movie/popular', action=ACT_FOLDER)
    item_add(ST_MOVIES_LIST, _('Top rated movies'), '/movie/top_rated', action=ACT_FOLDER)
    item_add(ST_MOVIES_LIST, _('Upcoming movies'), '/movie/upcoming', action=ACT_FOLDER)

# Path: epymc/extapi/onlinevideo.py
# ACT_DEFAULT = 0
# ACT_NONE = 1
# ACT_FOLDER = 2
# ACT_MORE = 3
# ACT_PLAY = 4
# ACT_SEARCH = 5
# def state_get():
# def language_get():
# def item_add(next_state, label, url, info=None, icon=None, poster=None, action=ACT_DEFAULT):
# def play_url(url):
# def report_error(msg):
# def local_resource(_file_, res):
# def fetch_url(url, headers=None, parser=None):
# def ydl_executable():
# def call_ydl(url):
# def url_encode(params):
# def seconds_to_duration(seconds):
# def relative_date(date):
# def format_date(date):


# Path: epymc/plugins/onlinevideo/themoviedb/themoviedb.py
from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, url_encode, language_get, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH

    return (IMG_BASE + '/' + size + img) if img else None


def movie_item(movie_data):
    title = movie_data['title']
    poster = full_img_url(movie_data['poster_path'])
    url = '/movie/%d?append_to_response=credits,videos' % movie_data['id']
    item_add(ST_MOVIE_INFO, title, url, poster=poster)


def next_page_item(url, data, next_state):
    if data['page'] < data['total_pages']:
        page = data['page']
        if '&page=' in url:
            next_url = url.replace('&page=%d' % (page), '&page=%d' % (page + 1))
        else:
            if not '?' in url: url += '?'
            next_url = url + '&page=%d' % (page + 1)
        text = _('Load more results (page {0} of {1})').format(page, data['total_pages'])
        item_add(next_state, text, next_url, action=ACT_MORE)


################################################################################
# home page
################################################################################
if STATE == ST_HOME:
    item_add(ST_SEARCH, _('Search movies'), 'search', action=ACT_SEARCH)
    item_add(ST_MOVIES_LIST, _('Popular movies'), '/movie/popular', action=ACT_FOLDER)
    item_add(ST_MOVIES_LIST, _('Top rated movies'), '/movie/top_rated', action=ACT_FOLDER)
    item_add(ST_MOVIES_LIST, _('Upcoming movies'), '/movie/upcoming', action=ACT_FOLDER)

    item_add(ST_MOVIES_LIST, _('Now playing movies'), '/movie/now_playing', action=ACT_FOLDER)