# 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, report_error, \
    seconds_to_duration, relative_date, url_encode, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH
            _('Tags'), ', '.join(tags),
        )
        item_add(ST_PLAY, title, video['url'], poster=video['thumb'], info=info)

    if len(videos) == 30:
        build_next_page_item(url, ST_VIDEO_LIST)


def build_next_page_item(url, next_state):
    # NOTE: this assume 'page=X' is ALWAYS the last param!! don't forget it!
    # num_pages = int(total / ITEMS_PER_PAGE) + 1
    url, cur_page = url.split('page=')
    next_page = int(cur_page) + 1
    # if next_page <= num_pages:
    url += 'page=' + str(next_page)
    item_add(next_state, _('More items...'), url, action=ACT_MORE)


# the first page, show fixed categories
if STATE == ST_HOME:

    url = 'http://it.pornhub.com/random'
    item_add(ST_PLAY, _('Play a random video'), url, icon='icon/play')

    item_add(ST_SEARCH, _('Search videos'), 'search', action=ACT_SEARCH)

    url = API_BASE + '/categories'
    item_add(ST_CATEGORIES, _('Categories'), url, action=ACT_FOLDER)

    url = API_BASE + '/search?ordering=newest&page=1'

# 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/pornhub/pornhub.py
from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, report_error, \
    seconds_to_duration, relative_date, url_encode, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH

            _('Tags'), ', '.join(tags),
        )
        item_add(ST_PLAY, title, video['url'], poster=video['thumb'], info=info)

    if len(videos) == 30:
        build_next_page_item(url, ST_VIDEO_LIST)


def build_next_page_item(url, next_state):
    # NOTE: this assume 'page=X' is ALWAYS the last param!! don't forget it!
    # num_pages = int(total / ITEMS_PER_PAGE) + 1
    url, cur_page = url.split('page=')
    next_page = int(cur_page) + 1
    # if next_page <= num_pages:
    url += 'page=' + str(next_page)
    item_add(next_state, _('More items...'), url, action=ACT_MORE)


# the first page, show fixed categories
if STATE == ST_HOME:

    url = 'http://it.pornhub.com/random'
    item_add(ST_PLAY, _('Play a random video'), url, icon='icon/play')

    item_add(ST_SEARCH, _('Search videos'), 'search', action=ACT_SEARCH)

    url = API_BASE + '/categories'
    item_add(ST_CATEGORIES, _('Categories'), url, action=ACT_FOLDER)

    url = API_BASE + '/search?ordering=newest&page=1'

    item_add(ST_VIDEO_LIST, _('Recently added'), url, action=ACT_FOLDER)