# 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 re
import json
from epymc.extapi.onlinevideo import api_version, state_get, \
    fetch_url, play_url, item_add, call_ydl, report_error, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH

# this is the first page, show fixed categories
if STATE == ST_HOME:
    # item_add(ST_PLAY,'A Random Video', 'http://fantasti.cc/random.php?v=1')
    item_add(ST_SEARCH, 'Search videos', 'search', action=ACT_SEARCH)

    item_add(ST_VIDEO_LIST, 'Upcoming video', url_base + '/videos/upcoming', action=ACT_FOLDER)

    item_add(ST_CATEGORIES_LIST, 'Categories', url_base + '/category', action=ACT_FOLDER)

    item_add(ST_VIDEO_LIST, 'Popular today', url_base + '/videos/popular/today', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular this week', url_base + '/videos/popular/7days', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular this month', url_base + '/videos/popular/31days', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular all time', url_base + '/videos/popular/all_time', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular made popular', url_base + '/videos/popular/made_popular', action=ACT_FOLDER)

    item_add(ST_COLLECTION_LIST, 'Collections - Popular', url_base + '/videos/collections/popular/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Top Rated', url_base + '/videos/collections/top_rated/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Most Viewed', url_base + '/videos/collections/most_viewed/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Most Discussed', url_base + '/videos/collections/most_discussed/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Top Favorites', url_base + '/videos/collections/top_favorites/31days',
             action=ACT_FOLDER)


# handle a page with a list of videos (popular videos)
elif STATE == ST_VIDEO_LIST:

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


# this is the first page, show fixed categories
if STATE == ST_HOME:
    # item_add(ST_PLAY,'A Random Video', 'http://fantasti.cc/random.php?v=1')
    item_add(ST_SEARCH, 'Search videos', 'search', action=ACT_SEARCH)

    item_add(ST_VIDEO_LIST, 'Upcoming video', url_base + '/videos/upcoming', action=ACT_FOLDER)

    item_add(ST_CATEGORIES_LIST, 'Categories', url_base + '/category', action=ACT_FOLDER)

    item_add(ST_VIDEO_LIST, 'Popular today', url_base + '/videos/popular/today', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular this week', url_base + '/videos/popular/7days', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular this month', url_base + '/videos/popular/31days', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular all time', url_base + '/videos/popular/all_time', action=ACT_FOLDER)
    item_add(ST_VIDEO_LIST, 'Popular made popular', url_base + '/videos/popular/made_popular', action=ACT_FOLDER)

    item_add(ST_COLLECTION_LIST, 'Collections - Popular', url_base + '/videos/collections/popular/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Top Rated', url_base + '/videos/collections/top_rated/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Most Viewed', url_base + '/videos/collections/most_viewed/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Most Discussed', url_base + '/videos/collections/most_discussed/31days',
             action=ACT_FOLDER)
    item_add(ST_COLLECTION_LIST, 'Collections - Top Favorites', url_base + '/videos/collections/top_favorites/31days',
             action=ACT_FOLDER)


# handle a page with a list of videos (popular videos)
elif STATE == ST_VIDEO_LIST:

    soup = fetch_url(URL, parser='bs4')