# 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
        except:
            pass


# 2. show a list of channels in a given categories
elif STATE == ST_CHN_CHANNELS:
    soup = fetch_url(URL, parser='bs4')
    for cha in soup.findAll('div', class_='yt-gb-shelf-hero'):
        try:
            title_span = cha.find('span', class_='qualified-channel-title-text')
            href = title_span.a['href']
            title = title_span.a.string
            thumb = cha.find('span', class_='yt-thumb-clip').img['src']
            thumb = os.path.dirname(os.path.dirname(thumb)) + '/'
            subscribers = cha.find('span', class_='yt-subscription-button-subscriber-count-branded-horizontal')['title']

            description = cha.find('p', class_='description').string.strip()
            info = '<title>%s</title><br><success>%s</success><br>%s' % (
                title, subscribers, description)

            item_add(ST_CHN_VIDEOS, title, ytb_base + href + '/videos?flow=list&sort=dd',
                     poster=thumb, info=info)
        except:
            pass


# 3. show a list of videos in a given channel
elif STATE == ST_CHN_VIDEOS:
    soup = fetch_url(URL, parser='bs4')
    for div in soup.findAll('div', class_='yt-lockup-video'):

# 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

        except:
            pass


# 2. show a list of channels in a given categories
elif STATE == ST_CHN_CHANNELS:
    soup = fetch_url(URL, parser='bs4')
    for cha in soup.findAll('div', class_='yt-gb-shelf-hero'):
        try:
            title_span = cha.find('span', class_='qualified-channel-title-text')
            href = title_span.a['href']
            title = title_span.a.string
            thumb = cha.find('span', class_='yt-thumb-clip').img['src']
            thumb = os.path.dirname(os.path.dirname(thumb)) + '/'
            subscribers = cha.find('span', class_='yt-subscription-button-subscriber-count-branded-horizontal')['title']

            description = cha.find('p', class_='description').string.strip()
            info = '<title>%s</title><br><success>%s</success><br>%s' % (
                title, subscribers, description)

            item_add(ST_CHN_VIDEOS, title, ytb_base + href + '/videos?flow=list&sort=dd',
                     poster=thumb, info=info)
        except:
            pass


# 3. show a list of videos in a given channel
elif STATE == ST_CHN_VIDEOS:
    soup = fetch_url(URL, parser='bs4')
    for div in soup.findAll('div', class_='yt-lockup-video'):

        id = div['data-context-item-id']