# 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
from epymc.extapi.onlinevideo import api_version, state_get, fetch_url, \
    play_url, item_add, call_ydl, local_resource, seconds_to_duration, \
    relative_date, url_encode, \
    ACT_NONE, ACT_FOLDER, ACT_MORE, ACT_PLAY, ACT_SEARCH
    # more items...
    try:
        url = ytb_base + soup.find('div', class_='search-pager').contents[-2]['href']
        item_add(ST_SEARCH, _('More items...'), url, icon='icon/next', action=ACT_MORE)
    except:
        pass


# 1. show the list of channels categories
elif STATE == ST_CHN_CATEGORIES:
    soup = fetch_url(URL, parser='bs4')
    for cat in soup.findAll('div', class_='yt-gb-shelf'):
        try:
            title = cat.find('span', class_='category-title').string
            href = cat.find('a', class_='category-title-link')['href']
            thumb = cat.find('img', role='contentinfo')['src']
            thumb = os.path.dirname(os.path.dirname(thumb)) + '/'

            channels_count = cat.find('span', class_='channel-count').string
            info = '<title>%s</title><br>%s %s' % (
                title, channels_count,
                ngettext('channel', 'channels', channels_count))

            item_add(ST_CHN_CHANNELS, title, ytb_base + href, poster=thumb, info=info)
        except:
            pass


# 2. show a list of channels in a given categories
elif STATE == ST_CHN_CHANNELS:

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

    # more items...
    try:
        url = ytb_base + soup.find('div', class_='search-pager').contents[-2]['href']
        item_add(ST_SEARCH, _('More items...'), url, icon='icon/next', action=ACT_MORE)
    except:
        pass


# 1. show the list of channels categories
elif STATE == ST_CHN_CATEGORIES:
    soup = fetch_url(URL, parser='bs4')
    for cat in soup.findAll('div', class_='yt-gb-shelf'):
        try:
            title = cat.find('span', class_='category-title').string
            href = cat.find('a', class_='category-title-link')['href']
            thumb = cat.find('img', role='contentinfo')['src']
            thumb = os.path.dirname(os.path.dirname(thumb)) + '/'

            channels_count = cat.find('span', class_='channel-count').string
            info = '<title>%s</title><br>%s %s' % (
                title, channels_count,
                ngettext('channel', 'channels', channels_count))

            item_add(ST_CHN_CHANNELS, title, ytb_base + href, poster=thumb, info=info)
        except:
            pass


# 2. show a list of channels in a given categories
elif STATE == ST_CHN_CHANNELS:

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