#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Watch youtube video
"""

import time
import argparse
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


def watch_video(url):
    """Run selenium scraper"""
    driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub",
                              DesiredCapabilities.CHROME)
    try:
        driver.get(url)
        driver.find_element_by_class_name("ytp-large-play-button").click()
        time.sleep(14400)  # 4h
    except Exception:
        driver.save_screenshot('screenshot.png')
    finally:
        driver.close()


def run():
    """Evaluate options and trigger watch"""
    parser = argparse.ArgumentParser(description='Watch youtube video.')
    parser.add_argument('--url', dest='url', action='store', required=True,
                        help='Video URL')
    args = parser.parse_args()

    watch_video(args.url)


if __name__ == '__main__':
    run()
