# 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):


import os
import traceback
from bs4 import BeautifulSoup
from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, relative_date, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH

base = 'http://www.zapiks.com/'

STATE, URL = state_get()

# this is the first page, show fixed categories
if STATE == ST_HOME:
    b = base
    u = '/popular_1.php'
    d = os.path.dirname(__file__)
    item_add(ST_VIDEO_LIST, 'Brand New Videos', b + 'p_1', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Surf', b + 'surf_' + u, poster=os.path.join(d, 'surf.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Snowboard', b + 'snowboard_' + u, poster=os.path.join(d, 'snowboard.png'),
             action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Mountain Bike', b + 'mountainbike_' + u, poster=os.path.join(d, 'vtt.png'),
             action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Bmx', b + 'bmx_' + u, poster=os.path.join(d, 'bmx.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Skate', b + 'skate_' + u, poster=os.path.join(d, 'skate.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Ski', b + 'ski_' + u, poster=os.path.join(d, 'ski.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Kite', b + 'kite_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Wakeboard', b + 'wake_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Other', b + 'other_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)


# the page for each category
elif STATE == ST_VIDEO_LIST:
    # soup = fetch_url(URL, parser='bs4') # this line work, but:
    # the zapiks page have an erroneous auto closing div tag
    # so wee need this hack to let bs4 correctly parse the html
    html = fetch_url(URL)

# 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/zapiks/zapiks.py
import os
import traceback
from bs4 import BeautifulSoup
from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, relative_date, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH


base = 'http://www.zapiks.com/'

STATE, URL = state_get()

# this is the first page, show fixed categories
if STATE == ST_HOME:
    b = base
    u = '/popular_1.php'
    d = os.path.dirname(__file__)
    item_add(ST_VIDEO_LIST, 'Brand New Videos', b + 'p_1', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Surf', b + 'surf_' + u, poster=os.path.join(d, 'surf.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Snowboard', b + 'snowboard_' + u, poster=os.path.join(d, 'snowboard.png'),
             action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Mountain Bike', b + 'mountainbike_' + u, poster=os.path.join(d, 'vtt.png'),
             action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Bmx', b + 'bmx_' + u, poster=os.path.join(d, 'bmx.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Skate', b + 'skate_' + u, poster=os.path.join(d, 'skate.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Ski', b + 'ski_' + u, poster=os.path.join(d, 'ski.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Kite', b + 'kite_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Wakeboard', b + 'wake_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Other', b + 'other_' + u, poster=os.path.join(d, 'zapiks.png'), action=ACT_FOLDER)


# the page for each category
elif STATE == ST_VIDEO_LIST:
    # soup = fetch_url(URL, parser='bs4') # this line work, but:
    # the zapiks page have an erroneous auto closing div tag
    # so wee need this hack to let bs4 correctly parse the html
    html = fetch_url(URL)

    soup = BeautifulSoup(html.replace('/>', '>'), 'lxml')