# -*- coding: utf-8 -*-
# plugin.video.crunchyreroll
# Copyright (C) 2024 Xtero
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import xbmcaddon
from .utils import ADDON_ID, local_from_id
from .client import CrunchyrollClient


def init_crunchyroll_client():
    addon = xbmcaddon.Addon(id=ADDON_ID)
    email = addon.getSetting("crunchyroll_username")
    password = addon.getSetting("crunchyroll_password")
    prefered_audio = "original"
    if addon.getSettingInt("prefered_audio") != 0:
        prefered_audio = local_from_id(addon.getSettingInt("prefered_audio")-1)
    settings = {
        "prefered_subtitle": local_from_id(addon.getSettingInt("subtitle_language")),
        "prefered_audio": prefered_audio,
        "page_size": addon.getSettingInt("page_size"),
    }
    return CrunchyrollClient(email, password, settings)
