import os
from twisted.web.client import downloadPage
from enigma import ePicLoad, eServiceReference, eTimer, getDesktop
from Components.ActionMap import ActionMap
from Components.AVSwitch import AVSwitch
from Components.config import config, ConfigDirectory, ConfigSelection, \
ConfigSet, ConfigSubDict, ConfigSubsection, ConfigText, ConfigYesNo, \
getConfigListEntry
from Components.ConfigList import ConfigListScreen
from Components.Label import Label
from Components.Pixmap import Pixmap
from Components.ScrollLabel import ScrollLabel
from Components.Sources.List import List
from Components.Sources.StaticText import StaticText
from Components.Task import job_manager
from Plugins.Plugin import PluginDescriptor
from Screens.ChoiceBox import ChoiceBox
from Screens.InfoBar import InfoBar, MoviePlayer
from Screens.MessageBox import MessageBox
from Screens.Screen import Screen
from Tools.BoundFunction import boundFunction
from Tools.Directories import resolveFilename, SCOPE_HDD, SCOPE_PLUGINS
from Tools.LoadPixmap import LoadPixmap
from . import _
config.plugins.YouTube = ConfigSubsection()
config.plugins.YouTube.saveHistory = ConfigYesNo(default=True)
config.plugins.YouTube.searchResult = ConfigSelection(
[('4', '4'),
('8', '8'),
('16', '16'),
('24', '24'),
('50', '50')
], '24')
config.plugins.YouTube.searchRegion = ConfigSelection(
[('', _('All')),
('AU', _('Australia')),
('BR', _('Brazil')),
('CA', _('Canada')),
('CZ', _('Czech Republic')),
('FR', _('France')),
('DE', _('Germany')),
('GB', _('Great Britain')),
('GR', _('Greece')),
('NL', _('Holland')),
('HK', _('Hong Kong')),
('IN', _('India')),
('IE', _('Ireland')),
('IL', _('Israel')),
('IT', _('Italy')),
('JP', _('Japan')),
('LV', _('Latvia')),
('MX', _('Mexico')),
('NZ', _('New Zealand')),
('PL', _('Poland')),
('RU', _('Russia')),
('KR', _('South Korea')),
('ES', _('Spain')),
('SE', _('Sweden')),
('TW', _('Taiwan')),
('TH', _('Thailand')),
('TR', _('Turkey')),
('US', _('United States'))
], '')
config.plugins.YouTube.searchLanguage = ConfigSelection(
[('', _('All')),
('au', _('Australia')),
('br', _('Brazil')),
('ca', _('Canada')),
('cz', _('Czech Republic')),
('fr', _('France')),
('de', _('Germany')),
('gb', _('Great Britain')),
('el', _('Greece')),
('nl', _('Holland')),
('hk', _('Hong Kong')),
('in', _('India')),
('ie', _('Ireland')),
('il', _('Israel')),
('it', _('Italy')),
('jp', _('Japan')),
('lv', _('Latvia')),
('mx', _('Mexico')),
('nz', _('New Zealand')),
('pl', _('Poland')),
('ru', _('Russia')),
('kr', _('South Korea')),
('es', _('Spain')),
('se', _('Sweden')),
('tw', _('Taiwan')),
('th', _('Thailand')),
('tr', _('Turkey')),
('us', _('United States'))
], '')
config.plugins.YouTube.searchOrder = ConfigSelection(
[('relevance', _('Relevance')),
('date', _('Created date')),
('rating', _('Rating')),
('title', _('Title')),
('viewCount', _('View count'))
], 'relevance')
config.plugins.YouTube.safeSearch = ConfigSelection(default='moderate', choices=[
('moderate', _('Moderate')), ('none', _('No')), ('strict', _('Yes'))])
config.plugins.YouTube.maxResolution = ConfigSelection(default='22', choices=[
('38', '4096x3072'), ('37', '1920x1080'), ('22', '1280x720'), ('35', '854x480'),
('18', '640x360'), ('5', '400x240'), ('17', '176x144')])
config.plugins.YouTube.onMovieEof = ConfigSelection(default='quit', choices=[
('quit', _('Return to list')), ('ask', _('Ask user')),
('playnext', _('Play next')), ('repeat', _('Repeat')),
('playprev', _('Play previous'))])
config.plugins.YouTube.onMovieStop = ConfigSelection(default='ask', choices=[
('ask', _('Ask user')), ('quit', _('Return to list'))])
config.plugins.YouTube.login = ConfigYesNo(default=False)
config.plugins.YouTube.downloadDir = ConfigDirectory(default=resolveFilename(SCOPE_HDD))
config.plugins.YouTube.mergeFiles = ConfigYesNo(default=False)
# Dublicate entry list in createSearchList
config.plugins.YouTube.searchHistoryDict = ConfigSubDict()
config.plugins.YouTube.searchHistoryDict['Searchvideo'] = ConfigSet(choices=[])
config.plugins.YouTube.searchHistoryDict['Searchchannel'] = ConfigSet(choices=[])
config.plugins.YouTube.searchHistoryDict['Searchplaylist'] = ConfigSet(choices=[])
config.plugins.YouTube.searchHistoryDict['Searchbroadcasts'] = ConfigSet(choices=[])
config.plugins.YouTube.refreshToken = ConfigText()
API_KEY = 'AIzaSyCyIlbb0FIwoieEZ9RTShMVkRMisu-ZX0k'
YOUTUBE_API_CLIENT_ID = '411447027255-vbgs05u1o3m8mpjs2vcd04afrg60drba.apps.googleusercontent.com'
YOUTUBE_API_CLIENT_SECRET = 'fYE-8T3qf4DrLPLv3NTgvjna'