import urlparse
from lambdascrapers.modules import control
from lambdascrapers import providerSources, providerNames

params = dict(urlparse.parse_qsl(sys.argv[2].replace('?', '')))
mode = params.get('mode')

def ScraperChoice():
    from lambdascrapers import providerSources
    sourceList = providerSources()
    control.idle()
    module_choice = 'All'
    items = ['All', 'Yoda', 'Placenta', 'Incursion']
    select = control.selectDialog([i for i in sourceList])
    if select == -1: return
    module_choice = sourceList[select]
    control.setSetting('module.provider', module_choice)
    control.openSettings('0.1')

def ToggleProviderAll(enable):
    from lambdascrapers import providerNames
    sourceList = providerNames()
    (setting, open_id) = ('true', '0.3') if enable else ('false', '0.2')
    for i in sourceList:
        source_setting = 'provider.' + i
        control.setSetting(source_setting, setting)
    control.openSettings(open_id)

def toggleAll(setting, open_id=None, sourceList=None):
    from lambdascrapers import getAllHosters
    sourceList = getAllHosters() if not sourceList else sourceList
    for i in sourceList:
        source_setting = 'provider.' + i
        control.setSetting(source_setting, setting)
    control.openSettings(open_id)



if mode == "LambdaSettings":
    control.openSettings('0.0', 'script.module.lambdascrapers')

if mode == "ScraperChoice":
    ScraperChoice()

if mode == "ToggleProviderAll":
    ToggleProviderAll(False if params['action'] == "DisableModuleAll" else True)

if mode == "toggleAll":
    open_id = params['open_id'] if 'open_id' in params else '0.0'
    sourcelist = params['sourcelist'] if 'sourcelist' in params else None
    toggleAll(params['setting'], open_id, sourceList=sourcelist)

if mode == "toggleAllDebrid":
    sourcelist = ['300mbfilms','bestmoviez','ddls','ddlvalley','directdl','gomovies','hevcfilm',
    'moviesonline','myvideolink','phazeddl','power','releasebb','RLSB','rlsbb','rlsmovies','rlsscn',
    'scenerls','sceper','seriescr','tvbmoviez','tvrelease','ultrahd','ultrahdindir']
    toggleAll(params['setting'], params['open_id'], sourcelist)

if mode == "Defaults":
    print "##Defaults"
    control.setSetting(id='provider.1movie', value='true')
    control.setSetting(id='provider.2ddl', value='true')
    control.setSetting(id='provider.4kmovieto', value='true')
    control.setSetting(id='provider.123fox', value='false')
    control.setSetting(id='provider.123hbo', value='false')
    control.setSetting(id='provider.123hulu', value='true')
    control.setSetting(id='provider.123movies', value='true')
    control.setSetting(id='provider.123moviesgold', value='true')
    control.setSetting(id='provider.123netflix', value='true')
    control.setSetting(id='provider.321movies', value='false')
    control.setSetting(id='provider.1080P', value='true')
    control.setSetting(id='provider.afdah', value='true')
    control.setSetting(id='provider.allrls', value='true')
    control.setSetting(id='provider.allucen', value='true')
    control.setSetting(id='provider.animeultima', value='true')
    control.setSetting(id='provider.bmoviez', value='true')
    control.setSetting(id='provider.bnwmovies', value='true')
    control.setSetting(id='provider.bob', value='true')
    control.setSetting(id='provider.cafehulu', value='false')
    control.setSetting(id='provider.cartoonhd', value='false')
    control.setSetting(id='provider.cinemamega', value='false')
    control.setSetting(id='provider.cmovie', value='false')
    control.setSetting(id='provider.cmovies', value='true')
    control.setSetting(id='provider.coolmoviezone', value='true')
    control.setSetting(id='provider.cooltv', value='false')
    control.setSetting(id='provider.darewatch', value='true')
    control.setSetting(id='provider.divxcrawler', value='true')
    control.setSetting(id='provider.dizigold', value='true')
    control.setSetting(id='provider.dltube', value='true')
    control.setSetting(id='provider.einthusan', value='true')
    control.setSetting(id='provider.filmfrantic', value='true')
    control.setSetting(id='provider.filmxy', value='true')
    control.setSetting(id='provider.flenix', value='true')
    control.setSetting(id='provider.flix', value='false')
    control.setSetting(id='provider.flixanity', value='true')
    control.setSetting(id='provider.fmovied6', value='false')
    control.setSetting(id='provider.freefmovies', value='true')
    control.setSetting(id='provider.freemovie6', value='true')
    control.setSetting(id='provider.freeputlockers', value='true')
    control.setSetting(id='provider.furk', value='true')
    control.setSetting(id='provider.genvideos', value='true')
    control.setSetting(id='provider.gogoanime', value='true')
    control.setSetting(id='provider.gowatchseries', value='true')
    control.setSetting(id='provider.hd', value='false')
    control.setSetting(id='provider.hdmega', value='false')
    control.setSetting(id='provider.Hdmto', value='true')
    control.setSetting(id='provider.hdpopcorns', value='true')
    control.setSetting(id='provider.hulufilm', value='false')
    control.setSetting(id='provider.huluvip', value='false')
    control.setSetting(id='provider.icefilms', value='true')
    control.setSetting(id='provider.icouchtuner', value='true')
    control.setSetting(id='provider.imdark', value='true')
    control.setSetting(id='provider.kattv', value='true')
    control.setSetting(id='provider.kingmovies', value='false')
    control.setSetting(id='provider.l23movies', value='true')
    control.setSetting(id='provider.library', value='false')
    control.setSetting(id='provider.locker', value='false')
    control.setSetting(id='provider.m4ufree', value='true')
    control.setSetting(id='provider.megahd', value='true')
    control.setSetting(id='provider.megavid', value='false')
    control.setSetting(id='provider.miradetodo', value='true')
    control.setSetting(id='provider.movie4kis', value='false')
    control.setSetting(id='provider.movie4korg', value='false')
    control.setSetting(id='provider.movie4kto', value='false')
    control.setSetting(id='provider.movie4uch', value='false')
    control.setSetting(id='provider.moviesgold', value='false')
    control.setSetting(id='provider.moviesplanet', value='true')
    control.setSetting(id='provider.moviexk', value='false')
    control.setSetting(id='provider.myputlocker', value='true')
    control.setSetting(id='provider.mywatchseries', value='true')
    control.setSetting(id='provider.mzmovies', value='true')
    control.setSetting(id='provider.onlinedizi', value='true')
    control.setSetting(id='provider.openloadmovies', value='false')
    control.setSetting(id='provider.ororo', value='true')
    control.setSetting(id='provider.plocker', value='true')
    control.setSetting(id='provider.primewire', value='true')
    control.setSetting(id='provider.projectfree', value='true')
    control.setSetting(id='provider.pron', value='true')
    control.setSetting(id='provider.putlocker', value='true')
    control.setSetting(id='provider.rajahoki88', value='true')
    control.setSetting(id='provider.rarbg', value='false')
    control.setSetting(id='provider.seehd', value='true')
    control.setSetting(id='provider.series9', value='true')
    control.setSetting(id='provider.seriesfree', value='true')
    control.setSetting(id='provider.seriesonline', value='true')
    control.setSetting(id='provider.sezonlukdizi', value='true')
    control.setSetting(id='provider.showbox', value='false')
    control.setSetting(id='provider.solarmoviez', value='true')
    control.setSetting(id='provider.streamlord', value='true')
    control.setSetting(id='provider.sunmovies', value='false')
    control.setSetting(id='provider.timewatch', value='false')
    control.setSetting(id='provider.tvbox', value='true')
    control.setSetting(id='provider.uhd', value='false')
    control.setSetting(id='provider.videoscraper', value='true')
    control.setSetting(id='provider.vioozfree', value='false')
    control.setSetting(id='provider.vodly', value='true')
    control.setSetting(id='provider.watch32', value='true')
    control.setSetting(id='provider.watch-free', value='false')
    control.setSetting(id='provider.watchit', value='false')
    control.setSetting(id='provider.watchnew', value='false')
    control.setSetting(id='provider.watchonline', value='true')
    control.setSetting(id='provider.watchseries', value='true')
    control.setSetting(id='provider.xmovies', value='true')
    control.setSetting(id='provider.xwatchseries', value='true')
    control.setSetting(id='provider.ymovies', value='true')

if mode == "Reaper":
    print "##Reaper"
    control.setSetting(id='provider.1movie', value='false')
    control.setSetting(id='provider.2ddl', value='true')
    control.setSetting(id='provider.4kmovieto', value='false')
    control.setSetting(id='provider.123fox', value='false')
    control.setSetting(id='provider.123hbo', value='false')
    control.setSetting(id='provider.123hulu', value='true')
    control.setSetting(id='provider.123movies', value='false')
    control.setSetting(id='provider.123moviesgold', value='false')
    control.setSetting(id='provider.123netflix', value='false')
    control.setSetting(id='provider.321movies', value='false')
    control.setSetting(id='provider.1080P', value='false')
    control.setSetting(id='provider.afdah', value='false')
    control.setSetting(id='provider.allrls', value='false')
    control.setSetting(id='provider.allucen', value='false')
    control.setSetting(id='provider.animeultima', value='false')
    control.setSetting(id='provider.bmoviez', value='true')
    control.setSetting(id='provider.bnwmovies', value='false')
    control.setSetting(id='provider.bob', value='true')
    control.setSetting(id='provider.cafehulu', value='false')
    control.setSetting(id='provider.cartoonhd', value='false')
    control.setSetting(id='provider.cinemamega', value='false')
    control.setSetting(id='provider.cmovie', value='false')
    control.setSetting(id='provider.cmovies', value='false')
    control.setSetting(id='provider.coolmoviezone', value='false')
    control.setSetting(id='provider.cooltv', value='false')
    control.setSetting(id='provider.darewatch', value='false')
    control.setSetting(id='provider.divxcrawler', value='true')
    control.setSetting(id='provider.dizigold', value='false')
    control.setSetting(id='provider.dltube', value='false')
    control.setSetting(id='provider.einthusan', value='false')
    control.setSetting(id='provider.filmfrantic', value='false')
    control.setSetting(id='provider.filmxy', value='false')
    control.setSetting(id='provider.flenix', value='false')
    control.setSetting(id='provider.flix', value='false')
    control.setSetting(id='provider.flixanity', value='true')
    control.setSetting(id='provider.fmovied6', value='false')
    control.setSetting(id='provider.freefmovies', value='true')
    control.setSetting(id='provider.freemovie6', value='false')
    control.setSetting(id='provider.freeputlockers', value='true')
    control.setSetting(id='provider.furk', value='false')
    control.setSetting(id='provider.genvideos', value='false')
    control.setSetting(id='provider.gogoanime', value='false')
    control.setSetting(id='provider.gowatchseries', value='true')
    control.setSetting(id='provider.hd', value='false')
    control.setSetting(id='provider.hdmega', value='false')
    control.setSetting(id='provider.Hdmto', value='false')
    control.setSetting(id='provider.hdpopcorns', value='false')
    control.setSetting(id='provider.hulufilm', value='false')
    control.setSetting(id='provider.huluvip', value='false')
    control.setSetting(id='provider.icefilms', value='false')
    control.setSetting(id='provider.icouchtuner', value='false')
    control.setSetting(id='provider.imdark', value='false')
    control.setSetting(id='provider.kattv', value='false')
    control.setSetting(id='provider.kingmovies', value='false')
    control.setSetting(id='provider.l23movies', value='false')
    control.setSetting(id='provider.library', value='false')
    control.setSetting(id='provider.locker', value='false')
    control.setSetting(id='provider.m4ufree', value='false')
    control.setSetting(id='provider.megahd', value='false')
    control.setSetting(id='provider.megavid', value='false')
    control.setSetting(id='provider.miradetodo', value='false')
    control.setSetting(id='provider.movie4kis', value='false')
    control.setSetting(id='provider.movie4korg', value='false')
    control.setSetting(id='provider.movie4kto', value='false')
    control.setSetting(id='provider.movie4uch', value='false')
    control.setSetting(id='provider.moviesgold', value='false')
    control.setSetting(id='provider.moviesplanet', value='false')
    control.setSetting(id='provider.moviexk', value='false')
    control.setSetting(id='provider.myputlocker', value='false')
    control.setSetting(id='provider.mywatchseries', value='false')
    control.setSetting(id='provider.mzmovies', value='false')
    control.setSetting(id='provider.onlinedizi', value='false')
    control.setSetting(id='provider.openloadmovies', value='false')
    control.setSetting(id='provider.ororo', value='false')
    control.setSetting(id='provider.plocker', value='false')
    control.setSetting(id='provider.primewire', value='false')
    control.setSetting(id='provider.projectfree', value='false')
    control.setSetting(id='provider.pron', value='false')
    control.setSetting(id='provider.putlocker', value='false')
    control.setSetting(id='provider.rajahoki88', value='false')
    control.setSetting(id='provider.rarbg', value='false')
    control.setSetting(id='provider.seehd', value='false')
    control.setSetting(id='provider.series9', value='true')
    control.setSetting(id='provider.seriesfree', value='false')
    control.setSetting(id='provider.seriesonline', value='true')
    control.setSetting(id='provider.sezonlukdizi', value='false')
    control.setSetting(id='provider.showbox', value='false')
    control.setSetting(id='provider.solarmoviez', value='true')
    control.setSetting(id='provider.streamlord', value='false')
    control.setSetting(id='provider.sunmovies', value='false')
    control.setSetting(id='provider.timewatch', value='false')
    control.setSetting(id='provider.tvbox', value='false')
    control.setSetting(id='provider.uhd', value='false')
    control.setSetting(id='provider.videoscraper', value='false')
    control.setSetting(id='provider.vioozfree', value='false')
    control.setSetting(id='provider.vodly', value='false')
    control.setSetting(id='provider.watch32', value='false')
    control.setSetting(id='provider.watch-free', value='false')
    control.setSetting(id='provider.watchit', value='false')
    control.setSetting(id='provider.watchnew', value='false')
    control.setSetting(id='provider.watchonline', value='true')
    control.setSetting(id='provider.watchseries', value='false')
    control.setSetting(id='provider.xmovies', value='true')
    control.setSetting(id='provider.xwatchseries', value='false')
    control.setSetting(id='provider.ymovies', value='false')
