# 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
    start = html.find('videosJSON = [')
    end = html.find('}];', start)
    json_str = html[start + 13:end + 2]
    data = json.loads(json_str)

    for vid in data:
        title = vid['title']
        url = url_base + vid['url']
        thumb = vid['rawThumb']
        item_add(ST_PLAY, title, url, poster=thumb)


# 4 handle the first search query (only page 1)
# 5 handle more search results (from page 2) (and the videos of categories)
elif STATE in (ST_SEARCH, ST_SEARCH_RES):
    if STATE == ST_SEARCH:
        URL = URL.replace(' ', '+')
        URL = 'http://fantasti.cc/search/' + URL + '/tube/'

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

    for div in soup.findAll('div', class_='searchVideo'):
        title = div.find('span').string
        url = div.find('a')['href']
        thumb = div.find('img')['src']
        item_add(ST_PLAY, title, 'http://fantasti.cc' + url, poster=thumb)

    # more items...
    try:
        url = 'http://fantasti.cc/' + soup.find('a', text='next >>')['href']

# 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

    start = html.find('videosJSON = [')
    end = html.find('}];', start)
    json_str = html[start + 13:end + 2]
    data = json.loads(json_str)

    for vid in data:
        title = vid['title']
        url = url_base + vid['url']
        thumb = vid['rawThumb']
        item_add(ST_PLAY, title, url, poster=thumb)


# 4 handle the first search query (only page 1)
# 5 handle more search results (from page 2) (and the videos of categories)
elif STATE in (ST_SEARCH, ST_SEARCH_RES):
    if STATE == ST_SEARCH:
        URL = URL.replace(' ', '+')
        URL = 'http://fantasti.cc/search/' + URL + '/tube/'

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

    for div in soup.findAll('div', class_='searchVideo'):
        title = div.find('span').string
        url = div.find('a')['href']
        thumb = div.find('img')['src']
        item_add(ST_PLAY, title, 'http://fantasti.cc' + url, poster=thumb)

    # more items...
    try:
        url = 'http://fantasti.cc/' + soup.find('a', text='next >>')['href']

        item_add(ST_SEARCH_RES, 'More items...', url, action=ACT_MORE)