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

    videos = soup.findAll('a', class_='teaser-video-content')
    for video in videos:
        try:
            url = 'http://www.zapiks.com' + video['href']
            title = video.find('span', class_='teaser-title').string.strip()
            thumb = video.find('div', class_='teaser-thumbnail')['style']
            thumb = thumb.replace("background-image : url('", '').replace("')", '')
            intro = video.find('div', class_='teaser-intro').string
            user = video.find('span', class_='teaser-user').string.strip().replace('from ', '')
            uploaded = video.find('span', class_='teaser-date')['datetime']
            views = list(video.find('span', class_='teaser-counter').strings)[0]
            views = int(views.strip().replace('Views', '').replace(' ', ''))
            try:
                likes = int(video.find('span', class_='teaser-counter-likes').string.strip())
            except:
                likes = 0
            info = '<title>{}</title><br>' \
                   '<small><name>{}</name> {} <name>/ {} {}</name></small><br>' \
                   '<small><success>{} {}</success> <name>/</> ' \

# 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

    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')

    videos = soup.findAll('a', class_='teaser-video-content')
    for video in videos:
        try:
            url = 'http://www.zapiks.com' + video['href']
            title = video.find('span', class_='teaser-title').string.strip()
            thumb = video.find('div', class_='teaser-thumbnail')['style']
            thumb = thumb.replace("background-image : url('", '').replace("')", '')
            intro = video.find('div', class_='teaser-intro').string
            user = video.find('span', class_='teaser-user').string.strip().replace('from ', '')
            uploaded = video.find('span', class_='teaser-date')['datetime']
            views = list(video.find('span', class_='teaser-counter').strings)[0]
            views = int(views.strip().replace('Views', '').replace(' ', ''))
            try:
                likes = int(video.find('span', class_='teaser-counter-likes').string.strip())
            except:
                likes = 0
            info = '<title>{}</title><br>' \
                   '<small><name>{}</name> {} <name>/ {} {}</name></small><br>' \
                   '<small><success>{} {}</success> <name>/</> ' \

                   '<info>{} {}</info></small><br>' \