# News Player v1.0 by Wang Zhiyu
# 2023/04/05
# 这个程序依赖于 ChromeDriver.exe nircmd.exe, 放于该目录下即可
# 假如你是下一届的学生而且打开了这个文件, 不要以为这是病毒, 这玩意是2020届的学生写的用来晚上7点钟自动打开CCTV13播放的答辩代码, 如果你们不需要看新闻联播了, 删除此文件即可, 系统不会寄掉。
# 附带: 我知道这个文件的hash值, 并做了线上备份, 如果有人动了这个文件我是知道的哦~
# 另: 如果你想改改代码和功能, 可以看看答辩注释
# 如果改烂了可以访问 https://pastebin.ubuntu.com/p/CdhgQqf7j9/ 源代码

import time
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
import pyttsx3
from selenium.webdriver.common.action_chains import ActionChains
import getpass
welcome_char_image = """
                _        _   _                   _____  _                       
     /\        | |      | \ | |                 |  __ \| |                      
    /  \  _   _| |_ ___ |  \| | _____      _____| |__) | | __ _ _   _  ___ _ __ 
   / /\ \| | | | __/ _ \| . ` |/ _ \ \ /\ / / __|  ___/| |/ _` | | | |/ _ \ '__|
  / ____ \ |_| | || (_) | |\  |  __/\ V  V /\__ \ |    | | (_| | |_| |  __/ |   
 /_/    \_\__,_|\__\___/|_| \_|\___| \_/\_/ |___/_|    |_|\__,_|\__, |\___|_|   
                                                                 __/ |          
                                  Version 1.0                   |___/           
                            Copyleft Wang Zhiyu 2023
                    Based on Python, NirCMD & Chromium Project
                       Open Source Software: GPL-3 License
             DO NOT close this window unless you want to quit the program!
LOG:
"""
bye_char_image = """
                                              __  
                                  _           \ \ 
                                 (_)  ______   | |
                                     |______|  | |
                                  _            | |
                                 (_)           | |
                                              /_/ 
                             AutoNewsPlayer Version 1.0
                              Copyleft Wang Zhiyu 2023
                    Based on Python, NirCMD & Chromium Project
                       Open Source Software: GPL-3 License
                                 Have a good night
"""
os.system("color A")
print(welcome_char_image)
# 设置Chromium浏览器路径(答辩代码)
a = r"C:\Users\\"
b = r"\AppData\Local\Chromium\Application\chrome.exe"
chrome_path = a + getpass.getuser() + b


engine = pyttsx3.init()
os.system("nircmd.exe setsysvolume 40000")
engine.say("AutoNewsPlayer Version One Point Zero")
engine.runAndWait()
engine.say("Initialization Start")
engine.runAndWait()
os.system("color 4F")
engine.say("Starting chromium browser to open the target website")
engine.runAndWait()
# 启动Chromium浏览器并打开CCTV13网站
options = webdriver.ChromeOptions()
# 设置启动参数，模拟人类用户的行为(关闭沙比浏览器受控制横幅)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
options.binary_location = chrome_path
driver = webdriver.Chrome(options=options)
driver.get("http://tv.cctv.com/live/cctv13/")
engine.say("Waiting for Loading Webpage")
engine.runAndWait()
time.sleep(5)  # 等待页面加载完成
engine.say("Click playing button")
engine.runAndWait()
# 自动点击播放按钮
play_button = driver.find_element(By.XPATH,'//*[@id="play_or_pause_play_player"]')
play_button.click()
time.sleep(3)
engine.say("Waiting for loading video")
engine.runAndWait()
time.sleep(1)

# 切换到全屏模式
engine.say("Enable the fullscreen mode")
engine.runAndWait()
fullscreen_button = driver.find_element(By.XPATH,'//*[@id="player_fullscreen_no_player"]')
fullscreen_button.click()

time.sleep(3)  # 等待切换完成
# 调整电脑音量为15%
# 注: 100% 为 65535
engine.say("Turning the computer volume to fifteen persent")
engine.runAndWait()
os.system("nircmd.exe setsysvolume 9830")
# 实例化ActionChains类，并传入驱动程序对象
actions = ActionChains(driver)

# 将指针移动到其他位置 (随便找了个元素)
actions.move_to_element(driver.find_element(By.XPATH,'//*[@id="search"]/div/div[1]/div/span[3]/input[1]')).perform()
engine.say("The playback operation is completely finished and the page will be closed after about thirty minutes")
engine.runAndWait()
# 播放30分钟后关闭浏览器
# time.sleep(5)
time.sleep(1740)
engine.say("Closing browser and turning the computer volume to seventy-five persent")
engine.runAndWait()
driver.quit()
os.system("color A")
# 调整电脑音量为75%
os.system("nircmd.exe setsysvolume 49151")
os.system("cls")
print(bye_char_image)
engine.say("Operation completed")
engine.runAndWait()

engine.say("Good luck with your class! Dear teacher and students.")
os.system("explorer.exe")
engine.runAndWait()