<commit_before>import { eventFire } from "../dom";
import { Debugger } from "../../../../../communication/Debugger";

const FMOVIES = 'fmovies'
const NINE_ANIME = '9anime'
const MY_CLOUD = 'mycloud'
const VIMEO = 'vimeo'


const PLAYERS_DOMAIN = [FMOVIES, NINE_ANIME, MY_CLOUD, VIMEO]

export interface VideoPlayer {
    play: () => void,
    pause: () => void,
    seekForward: (seconds: number) => void,
    seekBackward: (seconds: number) => void,
    volumeUp: (seconds: number) => number,
    volumeDown: (seconds: number) => number,
    enterFullScreen: () => void,
    exitFullScreen: () => void
}

export interface VideoPlayerWrapper {
    player: HTMLVideoElement,
    container?: HTMLElement[]
    customBehavior?: Partial<VideoPlayer>
}

export const getCurrentPlayerByDomain = (domain: string): VideoPlayer => {
    let videoPlayer: VideoPlayerWrapper = null

    if (PLAYERS_DOMAIN.indexOf(domain) > -1) {
        videoPlayer = getVideoPlayer(domain)
    }

    if (videoPlayer && videoPlayer.player) {
        return loadVideoPlayer(videoPlayer, videoPlayer.customBehavior)
    }

    return null
}

export const getVideoPlayer = (domain: string): VideoPlayerWrapper => {

    let playerWrapper: VideoPlayerWrapper = {
        player: null
    }
    switch (domain) {
        case MY_CLOUD:
        case FMOVIES:
        case NINE_ANIME:
            //only compatible with basic HTML5 player     
            const cover = document.getElementsByClassName('cover')[0]
            if (cover)
                eventFire(cover, 'click');
            playerWrapper.player = document.getElementsByClassName('jw-video jw-reset')[0] as HTMLVideoElement
            playerWrapper.container = [document.getElementById('player')]

            break
        case VIMEO:
            //only compatible with basic HTML5 player     
            playerWrapper.player = document.getElementsByTagName('video')[0] as HTMLVideoElement
            playerWrapper.container = [
                document.getElementsByClassName("player js-player player")[0] as any,
                document.getElementsByClassName("player_area")[0] as any]

            if (playerWrapper.player)
                eventFire(playerWrapper.player, 'click');

            break
    }

    if (playerWrapper.player) {

        Debugger.log('Player loaded from: ' + window.location.href)
        Debugger.log(playerWrapper)
    }

    return playerWrapper
}



export const loadVideoPlayer = (wrapper: VideoPlayerWrapper, customVideoPlayer?: Partial<VideoPlayer>): VideoPlayer => {
    const videoPlayer = {
        play: function () {
            wrapper.player.play()<commit_msg>so easy to add Amazon player :p<commit_after>import { eventFire } from "../dom";
import { Debugger } from "../../../../../communication/Debugger";

const FMOVIES = 'fmovies'
const NINE_ANIME = '9anime'
const MY_CLOUD = 'mycloud'
const VIMEO = 'vimeo'
const AMAZON = 'primevideo'


const PLAYERS_DOMAIN = [FMOVIES, NINE_ANIME, MY_CLOUD, VIMEO, AMAZON]

export interface VideoPlayer {
    play: () => void,
    pause: () => void,
    seekForward: (seconds: number) => void,
    seekBackward: (seconds: number) => void,
    volumeUp: (seconds: number) => number,
    volumeDown: (seconds: number) => number,
    enterFullScreen: () => void,
    exitFullScreen: () => void
}

export interface VideoPlayerWrapper {
    player: HTMLVideoElement,
    container?: HTMLElement[]
    customBehavior?: Partial<VideoPlayer>
}

export const getCurrentPlayerByDomain = (domain: string): VideoPlayer => {
    let videoPlayer: VideoPlayerWrapper = null

    if (PLAYERS_DOMAIN.indexOf(domain) > -1) {
        videoPlayer = getVideoPlayer(domain)
    }

    if (videoPlayer && videoPlayer.player) {
        return loadVideoPlayer(videoPlayer, videoPlayer.customBehavior)
    }

    return null
}

export const getVideoPlayer = (domain: string): VideoPlayerWrapper => {

    let playerWrapper: VideoPlayerWrapper = {
        player: null
    }
    switch (domain) {
        case MY_CLOUD:
        case FMOVIES:
        case NINE_ANIME:
            //only compatible with basic HTML5 player     
            const cover = document.getElementsByClassName('cover')[0]
            if (cover)
                eventFire(cover, 'click');
            playerWrapper.player = document.getElementsByClassName('jw-video jw-reset')[0] as HTMLVideoElement
            playerWrapper.container = [document.getElementById('player')]

            break
        case VIMEO:
            //only compatible with basic HTML5 player     
            playerWrapper.player = document.getElementsByTagName('video')[0] as HTMLVideoElement
            playerWrapper.container = [
                document.getElementsByClassName("player js-player player")[0] as any,
                document.getElementsByClassName("player_area")[0] as any]

            if (playerWrapper.player)
                eventFire(playerWrapper.player, 'click');

            break
        case AMAZON:
            //only compatible with basic HTML5 player     
            playerWrapper.player = document.getElementsByTagName('video')[0] as HTMLVideoElement
            playerWrapper.container = [
                document.getElementsByClassName("webPlayerContainer")[0] as any]

            const playBtn = document.getElementsByClassName('av-play-icon js-deeplinkable')[0]
            if (playBtn)
                eventFire(playBtn, 'click');

            break
    }

    if (playerWrapper.player) {

        Debugger.log('Player loaded from: ' + window.location.href)
        Debugger.log(playerWrapper)
    }

    return playerWrapper
}



export const loadVideoPlayer = (wrapper: VideoPlayerWrapper, customVideoPlayer?: Partial<VideoPlayer>): VideoPlayer => {
    const videoPlayer = {
        play: function () {
            wrapper.player.play()
{'fraction_non_alphanumeric': 0.10763948497854077, 'fraction_numerical': 0.003776824034334764, 'mean_word_length': 2.701397712833545, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6739923', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1592, 'n_words': 380}