import time, os

from unicodedata import name
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
import pandas as pd
import gspread
import urllib3
import requests
from bs4 import BeautifulSoup
import re
import schedule
import os.path
import datetime
import winsound

options = webdriver.ChromeOptions()
options.add_argument("--log-level=3")
options.add_argument("user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome Beta\\User Data\\")
options.add_argument("--start-maximized")  # use --start-maximized instead
options.binary_location = "C:\\Program Files\\Google\\Chrome Beta\\Application\\chrome.exe"

print("Videos ready to upload...")


channelurl = "https://studio.youtube.com/channel/UCWDa0d_pcE80B9dzwonCPnw"
channelurl2 = "https://studio.youtube.com/channel/UC8VpgVZZhWWKzgIcbqnXOXA" #Medicine Uses in Hindi
channelurl3 = "https://studio.youtube.com/channel/UCKZHbwMF89-gfhOJG77fZfA" #Medical Product Review

sa = gspread.service_account(filename="C:/Users/user/Documents/sheetsapi.json")
sh = sa.open("only74kotc")
sheet = sh.worksheet("Sheet4 above 70")
http = urllib3.PoolManager()



headers = {
    'Accept-Encoding': 'gzip, deflate, sdch',
    'Accept-Language': 'en-US,en;q=0.8',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
}

def TUIN():
    bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
    bot.get(channelurl)
    bot.implicitly_wait(20)
    try:
        if WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/div[1]/h1'), "Something went wrong")):
            bot.get("https://studio.youtube.com")
            bot.implicitly_wait(20)
            done_button = bot.find_element(By.XPATH, '//*[@id="img"]')
            done_button.click()#
            switch = WebDriverWait(bot, 10).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item'), "Switch"))
            done_button2 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item')
            done_button2.click()#

            xpaths = [
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[1]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[2]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[3]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[4]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[5]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[6]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[7]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[8]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[9]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[10]/tp-yt-paper-icon-item',
            ]
            for xpath in xpaths:
                try:
                    switch = WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, xpath), "Tablet Use in Hindi"))
                    if switch:
                        print("Found element with XPath:", xpath)
                        break
                except:
                    continue
            done_button = bot.find_element(By.XPATH, xpath)
            done_button.click()#
            time.sleep(5)
            bot.quit()
        else:
            WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="entity-name"]'), "Tablet Use in Hindi"))
            print("same channel found")
    except:
        bot.quit()

def MUIN():
    bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
    bot.get(channelurl2)
    bot.implicitly_wait(20)
    try:
        if WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/div[1]/h1'), "Something went wrong")):
            bot.get("https://studio.youtube.com")
            bot.implicitly_wait(20)
            done_button = bot.find_element(By.XPATH, '//*[@id="img"]')
            done_button.click()#
            switch = WebDriverWait(bot, 10).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item'), "Switch"))
            done_button2 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item')
            done_button2.click()#

            xpaths = [
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[1]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[2]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[3]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[4]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[5]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[6]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[7]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[8]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[9]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[10]/tp-yt-paper-icon-item',
            ]
            for xpath in xpaths:
                try:
                    switch = WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, xpath), "Medicine Uses in Hindi"))
                    if switch:
                        print("Found element with XPath:", xpath)
                        break
                except:
                    continue
            done_button = bot.find_element(By.XPATH, xpath)
            done_button.click()#
            time.sleep(5)
            bot.quit()
        else:
            WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="entity-name"]'), "Medicine Uses in Hindi"))
            print("same channel found")
    except:
        bot.quit()


def MPR():
    bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
    bot.get(channelurl3)
    bot.implicitly_wait(20)
    try:
        if WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/div[1]/h1'), "Something went wrong")):
            bot.get("https://studio.youtube.com")
            bot.implicitly_wait(20)
            done_button = bot.find_element(By.XPATH, '//*[@id="img"]')
            done_button.click()#
            switch = WebDriverWait(bot, 10).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item'), "Switch"))
            done_button2 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[3]/div[1]/yt-multi-page-menu-section-renderer[1]/div[2]/ytd-compact-link-renderer[3]/a/tp-yt-paper-item')
            done_button2.click()#

            xpaths = [
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[1]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[2]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[3]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[4]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[5]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[6]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[7]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[8]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[9]/tp-yt-paper-icon-item',
                '/html/body/ytcp-app/ytcp-popup-container/tp-yt-iron-dropdown/div/ytd-multi-page-menu-renderer/div[4]/ytd-multi-page-menu-renderer/div[3]/div[1]/ytd-account-section-list-renderer[1]/div[2]/ytd-account-item-section-renderer/div[2]/ytd-account-item-renderer[10]/tp-yt-paper-icon-item',
            ]
            for xpath in xpaths:
                try:
                    switch = WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, xpath), "Medical Product Review"))
                    if switch:
                        print("Found element with XPath:", xpath)
                        break
                except:
                    continue
            done_button = bot.find_element(By.XPATH, xpath)
            done_button.click()#
            time.sleep(5)
            bot.quit()
        else:
            WebDriverWait(bot, 1).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="entity-name"]'), "Medical Product Review"))
            print("same channel found")
    except:
        bot.quit()  

###-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def sudo_uploader():
    TUIN()
    today = datetime.datetime.now().strftime('%d/%m/%Y')
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
    yesterday_date = yesterday.strftime('%d/%m/%Y')

    start = sheet.find("", in_column=13)
    start_row = start.row

    end_row = None
    for row in range(start_row, start_row + 10):
        cell_value = sheet.cell(row, 13).value
        if cell_value is None or cell_value.strip() == "":
            print("Row", row, "is empty.")
        else:
            print("No End Row")
            break

    if end_row is None:
        cell_value14 = sheet.cell(start_row-1, 14).value
        if cell_value14 == yesterday_date or today:
            end_row = start_row + 80 #Change the video uploading number----------------------------------------------------------------------------
        else:
            print("yesterdat not found")
           
    print("Start row:", start_row)
    print("End row:", end_row)


    for i in range(start_row, end_row + 1):
        value = sheet.cell(i, 11).value
        if value == "yes":
            url = sheet.cell(i, 1).value
            try:
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 14, today)
                    sheet.update_cell(i, 15, "Tablet uses in hindi")
                    continue
            except:
                print("waiting one min")
                time.sleep(60)
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 15, "Tablet uses in hindi")
                    continue
           
            myvalue = i
            print("jiten1", myvalue)
            def remove_bracket_contents(rawtitle):
                return re.sub(r"\([^\)]+\s*(each|Each)\)", "", rawtitle)
           
            mytabname = remove_bracket_contents(rawtitle).strip()
            print(mytabname, "uploading")
            simp_path = 'E:/otc/'+mytabname+'.mp4'
            if os.path.isfile(simp_path):
                bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
                wait = WebDriverWait(bot, 90)
                bot.get(channelurl)
                # bot.minimize_window()
                time.sleep(3)
                upload_button = bot.find_element(By.XPATH, '//*[@id="upload-icon"]')
                upload_button.click()
                time.sleep(3)

                file_input = bot.find_element(By.XPATH, '//*[@id="content"]/input')
                abs_path = os.path.abspath(simp_path)
                file_input.send_keys(abs_path)
            else:
                sheet.update_cell(i, 13, "File not found")
                sheet.update_cell(i, 14, today)
                sheet.update_cell(i, 15, "Tablet uses in hindi")
                continue  # Skip to the next iteration of the loop

                #Title
            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="next-button"]')))
            print("jiten2", myvalue)
            try:
                inputElement = bot.find_element(By.XPATH, '//*[@id="textbox"]')
                inputElement.click() # click on the input field to ensure it's selected
                inputElement.send_keys(Keys.CONTROL + "a") # press the Ctrl + A keys to select all text
                inputElement.send_keys(Keys.DELETE) # press the Delete key to delete the selected text
                inputElement.send_keys(""+mytabname+" Uses in Hindi | Side Effects | Dose") # enter your desired text
                time.sleep(2)
                inputElement = bot.find_elements(By.XPATH, '//*[@id="textbox"]')[1].send_keys(""+mytabname+" Uses in Hindi | Benefits | Side Effects | Dose\n\n\
------------------------------------\nRelated Searches\n\
"+mytabname+" Uses in Hindi\n\
"+mytabname+" Use in Hindi\n\
"+mytabname+" Kis kaam aati hai\n\
"+mytabname+" Review\n\
"+mytabname+" Use\n\
"+mytabname+" Side Effects\n\
"+mytabname+" ke Fayde\n\
"+mytabname+" ke fayde in hindi\n\
"+mytabname+" how to take\n\
"+mytabname+" how to use\n\
––––––––––––––––––––––––––––––\n\
Disclaimer:\n\
We are not promoting any medicine in our videos, our videos are for educating people about all medicines. \
Also, we are not suggesting anyone to take any medicine without the suggestion of your doctor. \
So this video is for information purposes only, always ask your doctor before eating any medicine.\n\
––––––––––––––––––––––––––––––\n\
SOME IMAGES ARE USED AS ILLUSTRATIONS FOR EDUCATIONAL PURPOSE UNDER FAIR USE - All images and videos used are in Public Domain\n\
––––––––––––––––––––––––––––––\n\
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for 'fair use' for purposes \
such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted \
by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips \
the balance in favor of fair use.")
               
                thumb_input = bot.find_element(By.XPATH, '//*[@id="file-loader"]')
                simp2_path = 'E:/otcthumbnail/'+mytabname+'.jpg'
                abs2_path = os.path.abspath(simp2_path)
                time.sleep(3)
                thumb_input.send_keys(abs2_path)
                time.sleep(2)
                bot.implicitly_wait(7)
                print("passing the loop")

                seemore_button = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-ve/ytcp-video-metadata-editor/div/div/ytcp-button/div')
                bot.implicitly_wait(7)
                print("see more mil gya")
                bot.execute_script('arguments[0].click();', seemore_button)
                time.sleep(2)
                print("see more click ho gya")
                bot.implicitly_wait(5)
                try:
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use in Hindi,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Kis kaam aati hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Review,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Side Effects,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Dose,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" kis liye hoti hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" ke fayde,")
                    bot.implicitly_wait(1)
                except:
                    print("tags not clickable")
                time.sleep(1)


                try:
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    time.sleep(5)
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    print("saved private complete")
                except:
                    print("check error de gya")
                time.sleep(2)
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="close-button"]')))
                next_button3 = bot.find_element(By.XPATH, '//*[@id="close-button"]')
                for i in range(1):
                    next_button3.click()#close button
                    time.sleep(2)
                print("first close done..............................")

                max_attempts = 10
                for attempt_number in range(1, max_attempts+1):
                    bot.get(f"{channelurl}/videos/upload?filter=%5B%7B%22name%22%3A%22VISIBILITY%22%2C%22value%22%3A%5B%22DRAFT%22%5D%7D%5D&sort=%7B%22columnType%22%3A%22date%22%2C%22sortOrder%22%3A%22DESCENDING%22%7D")
                    try:
                        element = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[9]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')))
                        print("Edit draft is clickable")
                        break
                    except:
                        print(f"Element is not clickable - attempt {attempt_number} of {max_attempts}")
                        time.sleep(7)

                try:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[9]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
                except:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[9]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
               
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="step-badge-4"]')))
                next_button = bot.find_element(By.XPATH, '//*[@id="step-badge-4"]')
                for i in range(1):
                    next_button.click()#publish page
                    time.sleep(2)
                    bot.implicitly_wait(20)

                wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')))
                next_button7 = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')
                for i in range(1):
                    next_button7.click()#Select Public
                    time.sleep(1)

                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="done-button"]')))
                done_button = bot.find_element(By.XPATH, '//*[@id="done-button"]')
                done_button.click()#Publish
                time.sleep(3)
               


                published = WebDriverWait(bot, 30).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="dialog-title"]'), "Video"))
                print("processing done")
                time.sleep(2)

                sheet.update_cell(myvalue, 13, "uploaded")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Tablet uses in hindi")
                try:
                    lastclose = bot.find_element(By.XPATH, '/html/body/ytcp-video-share-dialog/ytcp-dialog/tp-yt-paper-dialog/div[3]/ytcp-button/div')
                    lastclose.click()#Publish
                    time.sleep(1)
                    print("Last close done")
                except:
                    print("Last close Not done")

                try:
                    wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[4]/div/div')))
                    done_button = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[4]/div/div')
                    done_button.click()#Monetization drop down


                    wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="offRadio"]')))
                    done_button = bot.find_element(By.XPATH, '//*[@id="offRadio"]')
                    done_button.click()#Monetization on select

                    wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-video-monetization-edit-dialog/tp-yt-paper-dialog/div/div/ytcp-button[2]/div')))
                    done_button = bot.find_element(By.XPATH, '/html/body/ytcp-video-monetization-edit-dialog/tp-yt-paper-dialog/div/div/ytcp-button[2]/div')
                    done_button.click()#Monetization on Save

                    wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytpp-self-certification-questionnaire-dialog/ytcp-dialog/tp-yt-paper-dialog/div[2]/ytpp-self-certification-questionnaire/div[3]/div/ytcp-checkbox-lit/div[2]')))
                    done_button = bot.find_element(By.XPATH, '/html/body/ytpp-self-certification-questionnaire-dialog/ytcp-dialog/tp-yt-paper-dialog/div[2]/ytpp-self-certification-questionnaire/div[3]/div/ytcp-checkbox-lit/div[2]')
                    done_button.click()#Ad suitablity on

                    wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytpp-self-certification-questionnaire-dialog/ytcp-dialog/tp-yt-paper-dialog/div[3]/div/ytcp-button[2]/div')))
                    done_button = bot.find_element(By.XPATH, '/html/body/ytpp-self-certification-questionnaire-dialog/ytcp-dialog/tp-yt-paper-dialog/div[3]/div/ytcp-button[2]/div')
                    done_button.click()#Ad suitablity Submit
                    time.sleep(4)
                except:
                    print("Monetization on fails")
                bot.quit()
            except:
                sheet.update_cell(myvalue, 13, "function error")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Tablet uses in hindi")

           
        elif value == "Noooooo":
            sheet.update_cell(i, 13, "Not available")
            sheet.update_cell(i, 14, today)
            sheet.update_cell(i, 15, "Tablet uses in hindi")
           

###------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def sudo_uploader2():
    MUIN()
    today = datetime.datetime.now().strftime('%d/%m/%Y')
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
    yesterday_date = yesterday.strftime('%d/%m/%Y')

    start = sheet.find("", in_column=13)
    start_row = start.row

    end_row = None
    for row in range(start_row, start_row + 10):
        cell_value = sheet.cell(row, 13).value
        if cell_value is None or cell_value.strip() == "":
            print("Row", row, "is empty.")
        else:
            print("No End Row")
            break

    if end_row is None:
        cell_value14 = sheet.cell(start_row-1, 14).value
        if cell_value14 == yesterday_date or today:
            end_row = start_row + 10 #Change the video uploading number---------------------------------------------------------------------------
        else:
            print("yesterdat not found")
           
    print("Start row:", start_row)
    print("End row:", end_row)


    for i in range(start_row, end_row + 1):
        value = sheet.cell(i, 11).value
        if value == "yes":
            url = sheet.cell(i, 1).value
            try:
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 14, today)
                    sheet.update_cell(i, 15, "Medicine Uses in Hindi")
                    continue
            except:
                print("waiting one min")
                time.sleep(60)
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 14, today)
                    sheet.update_cell(i, 15, "Medicine Uses in Hindi")
                    continue
           
            myvalue = i
            print("jiten1", myvalue)
            def remove_bracket_contents(rawtitle):
                return re.sub(r"\([^\)]+\s*(each|Each)\)", "", rawtitle)
           
            mytabname = remove_bracket_contents(rawtitle).strip()
            print(mytabname, "uploading")
            simp_path = 'E:/otc/'+mytabname+'.mp4'
            if os.path.isfile(simp_path):
                bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
                wait = WebDriverWait(bot, 90)
                bot.get(channelurl2)
                # bot.minimize_window()
                time.sleep(3)
                upload_button = bot.find_element(By.XPATH, '//*[@id="upload-icon"]')
                upload_button.click()
                time.sleep(3)

                file_input = bot.find_element(By.XPATH, '//*[@id="content"]/input')
                abs_path = os.path.abspath(simp_path)
                file_input.send_keys(abs_path)
            else:
                sheet.update_cell(i, 13, "File not found")
                sheet.update_cell(i, 14, today)
                sheet.update_cell(i, 15, "Medicine Uses in Hindi")
                continue  # Skip to the next iteration of the loop

                #Title
            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="next-button"]')))
            print("jiten2", myvalue)
            try:
                inputElement = bot.find_element(By.XPATH, '//*[@id="textbox"]')
                inputElement.click() # click on the input field to ensure it's selected
                inputElement.send_keys(Keys.CONTROL + "a") # press the Ctrl + A keys to select all text
                inputElement.send_keys(Keys.DELETE) # press the Delete key to delete the selected text
                inputElement.send_keys(""+mytabname+" Uses in Hindi | Side Effects | Dose") # enter your desired text
                time.sleep(2)
                inputElement = bot.find_elements(By.XPATH, '//*[@id="textbox"]')[1].send_keys(""+mytabname+" Uses in Hindi | Benefits | Side Effects | Dose\n\n\
------------------------------------\nRelated Searches\n\
"+mytabname+" Uses in Hindi\n\
"+mytabname+" Use in Hindi\n\
"+mytabname+" Kis kaam aati hai\n\
"+mytabname+" Review\n\
"+mytabname+" Use\n\
"+mytabname+" Side Effects\n\
"+mytabname+" ke Fayde\n\
"+mytabname+" ke fayde in hindi\n\
"+mytabname+" how to take\n\
"+mytabname+" how to use\n\
––––––––––––––––––––––––––––––\n\
Disclaimer:\n\
We are not promoting any medicine in our videos, our videos are for educating people about all medicines. \
Also, we are not suggesting anyone to take any medicine without the suggestion of your doctor. \
So this video is for information purposes only, always ask your doctor before eating any medicine.\n\
––––––––––––––––––––––––––––––\n\
SOME IMAGES ARE USED AS ILLUSTRATIONS FOR EDUCATIONAL PURPOSE UNDER FAIR USE - All images and videos used are in Public Domain\n\
––––––––––––––––––––––––––––––\n\
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for 'fair use' for purposes \
such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted \
by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips \
the balance in favor of fair use.")
               
                thumb_input = bot.find_element(By.XPATH, '//*[@id="file-loader"]')
                simp2_path = 'E:/otcthumbnail/'+mytabname+'.jpg'
                abs2_path = os.path.abspath(simp2_path)
                time.sleep(3)
                thumb_input.send_keys(abs2_path)
                time.sleep(2)
                bot.implicitly_wait(7)
                print("passing the loop")

                seemore_button = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-ve/ytcp-video-metadata-editor/div/div/ytcp-button/div')
                bot.implicitly_wait(7)
                print("see more mil gya")
                bot.execute_script('arguments[0].click();', seemore_button)
                time.sleep(2)
                print("see more click ho gya")
                bot.implicitly_wait(5)
                try:
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use in Hindi,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Kis kaam aati hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Review,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Side Effects,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Dose,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" kis liye hoti hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" ke fayde,")
                    bot.implicitly_wait(1)
                except:
                    print("tags not clickable")
                time.sleep(1)


                try:
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    time.sleep(5)
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    print("saved private complete")
                except:
                    print("check error de gya")
                time.sleep(2)
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="close-button"]')))
                next_button3 = bot.find_element(By.XPATH, '//*[@id="close-button"]')
                for i in range(1):
                    next_button3.click()#close button
                    time.sleep(2)
                print("first close done..............................")

                max_attempts = 10
                for attempt_number in range(1, max_attempts+1):
                    bot.get(f"{channelurl2}/videos/upload?filter=%5B%7B%22name%22%3A%22VISIBILITY%22%2C%22value%22%3A%5B%22DRAFT%22%5D%7D%5D&sort=%7B%22columnType%22%3A%22date%22%2C%22sortOrder%22%3A%22DESCENDING%22%7D")
                    try:
                        element = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')))
                        print("Edit draft is clickable")
                        break
                    except:
                        print(f"Element is not clickable - attempt {attempt_number} of {max_attempts}")
                        time.sleep(7)

                try:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
                except:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
               
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="step-badge-3"]')))
                next_button = bot.find_element(By.XPATH, '//*[@id="step-badge-3"]')
                for i in range(1):
                    next_button.click()#publish page
                    time.sleep(2)
                    bot.implicitly_wait(20)

                wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')))
                next_button7 = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')
                for i in range(1):
                    next_button7.click()#Select Public
                    time.sleep(1)

                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="done-button"]')))
                done_button = bot.find_element(By.XPATH, '//*[@id="done-button"]')
                done_button.click()#Publish
                time.sleep(3)
               


                published = WebDriverWait(bot, 30).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="dialog-title"]'), "Video"))
                print("processing done")
                time.sleep(2)

                sheet.update_cell(myvalue, 13, "uploaded")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Medicine Uses in Hindi")
                try:
                    lastclose = bot.find_element(By.XPATH, '/html/body/ytcp-video-share-dialog/ytcp-dialog/tp-yt-paper-dialog/div[3]/ytcp-button/div')
                    lastclose.click()#Publish
                    time.sleep(1)
                    print("Last close done")
                except:
                    print("Last close Not done")
                bot.quit()
            except:
                sheet.update_cell(myvalue, 13, "function error")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Medicine Uses in Hindi")

           
        elif value == "Noooooo":
            sheet.update_cell(i, 13, "Not available")
            sheet.update_cell(i, 14, today)
            sheet.update_cell(i, 15, "Medicine Uses in Hindi")
           


###------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def sudo_uploader3():
    MPR()
    today = datetime.datetime.now().strftime('%d/%m/%Y')
    yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
    yesterday_date = yesterday.strftime('%d/%m/%Y')

    start = sheet.find("", in_column=13)
    start_row = start.row

    end_row = None
    for row in range(start_row, start_row + 10):
        cell_value = sheet.cell(row, 13).value
        if cell_value is None or cell_value.strip() == "":
            print("Row", row, "is empty.")
        else:
            print("No End Row")
            break

    if end_row is None:
        cell_value14 = sheet.cell(start_row-1, 14).value
        if cell_value14 == yesterday_date or today:
            end_row = start_row + 10 #Change the video uploading number---------------------------------------------------------------------------------
        else:
            print("yesterdat not found")
           
    print("Start row:", start_row)
    print("End row:", end_row)


    for i in range(start_row, end_row + 1):
        value = sheet.cell(i, 11).value
        if value == "yes":
            url = sheet.cell(i, 1).value
            try:
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 14, today)
                    sheet.update_cell(i, 15, "Medical Product Review")
                    continue
            except:
                print("waiting one min")
                time.sleep(60)
                source = requests.get (url, allow_redirects=False, headers=headers)
                soup = BeautifulSoup(source.text,'html.parser')
                try:
                    rawtitle = soup.find('h1', class_="ProductTitle__product-title___3QMYH").text
                except:
                    sheet.update_cell(i, 13, "No Title found")
                    sheet.update_cell(i, 14, today)
                    sheet.update_cell(i, 15, "Medical Product Review")
                    continue
           
            myvalue = i
            print("jiten1", myvalue)
            def remove_bracket_contents(rawtitle):
                return re.sub(r"\([^\)]+\s*(each|Each)\)", "", rawtitle)
           
            mytabname = remove_bracket_contents(rawtitle).strip()
            print(mytabname, "uploading")
            simp_path = 'E:/otc/'+mytabname+'.mp4'
            if os.path.isfile(simp_path):
                bot = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
                wait = WebDriverWait(bot, 90)
                bot.get(channelurl3)
                # bot.minimize_window()
                time.sleep(3)
                upload_button = bot.find_element(By.XPATH, '//*[@id="upload-icon"]')
                upload_button.click()
                time.sleep(3)

                file_input = bot.find_element(By.XPATH, '//*[@id="content"]/input')
                abs_path = os.path.abspath(simp_path)
                file_input.send_keys(abs_path)
            else:
                sheet.update_cell(i, 13, "File not found")
                sheet.update_cell(i, 14, today)
                sheet.update_cell(i, 15, "Medical Product Review")
                continue  # Skip to the next iteration of the loop

                #Title
            wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="next-button"]')))
            print("jiten2", myvalue)
            try:
                inputElement = bot.find_element(By.XPATH, '//*[@id="textbox"]')
                inputElement.click() # click on the input field to ensure it's selected
                inputElement.send_keys(Keys.CONTROL + "a") # press the Ctrl + A keys to select all text
                inputElement.send_keys(Keys.DELETE) # press the Delete key to delete the selected text
                inputElement.send_keys(""+mytabname+" Uses in Hindi | Side Effects | Dose") # enter your desired text
                time.sleep(2)
                inputElement = bot.find_elements(By.XPATH, '//*[@id="textbox"]')[1].send_keys(""+mytabname+" Uses in Hindi | Benefits | Side Effects | Dose\n\n\
------------------------------------\nRelated Searches\n\
"+mytabname+" Uses in Hindi\n\
"+mytabname+" Use in Hindi\n\
"+mytabname+" Kis kaam aati hai\n\
"+mytabname+" Review\n\
"+mytabname+" Use\n\
"+mytabname+" Side Effects\n\
"+mytabname+" ke Fayde\n\
"+mytabname+" ke fayde in hindi\n\
"+mytabname+" how to take\n\
"+mytabname+" how to use\n\
––––––––––––––––––––––––––––––\n\
Disclaimer:\n\
We are not promoting any medicine in our videos, our videos are for educating people about all medicines. \
Also, we are not suggesting anyone to take any medicine without the suggestion of your doctor. \
So this video is for information purposes only, always ask your doctor before eating any medicine.\n\
––––––––––––––––––––––––––––––\n\
SOME IMAGES ARE USED AS ILLUSTRATIONS FOR EDUCATIONAL PURPOSE UNDER FAIR USE - All images and videos used are in Public Domain\n\
––––––––––––––––––––––––––––––\n\
Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for 'fair use' for purposes \
such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted \
by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips \
the balance in favor of fair use.")
               
                thumb_input = bot.find_element(By.XPATH, '//*[@id="file-loader"]')
                simp2_path = 'E:/otcthumbnail/'+mytabname+'.jpg'
                abs2_path = os.path.abspath(simp2_path)
                time.sleep(3)
                thumb_input.send_keys(abs2_path)
                time.sleep(2)
                bot.implicitly_wait(7)
                print("passing the loop")

                seemore_button = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-ve/ytcp-video-metadata-editor/div/div/ytcp-button/div')
                bot.implicitly_wait(7)
                print("see more mil gya")
                bot.execute_script('arguments[0].click();', seemore_button)
                time.sleep(2)
                print("see more click ho gya")
                bot.implicitly_wait(5)
                try:
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use in Hindi,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Kis kaam aati hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Review,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Use,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Side Effects,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" Dose,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" kis liye hoti hai,")
                    bot.implicitly_wait(1)
                    bot.find_element(By.XPATH, '//*[@id="text-input"]').send_keys(""+mytabname+" ke fayde,")
                    bot.implicitly_wait(1)
                except:
                    print("tags not clickable")
                time.sleep(1)


                try:
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    time.sleep(5)
                    element = WebDriverWait(bot, 340).until(EC.text_to_be_present_in_element((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/div[1]/div/div/ytcp-animatable/ytcp-badge/div'), "Saved as private"))
                    print("saved private complete")
                except:
                    print("check error de gya")
                time.sleep(2)
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="close-button"]')))
                next_button3 = bot.find_element(By.XPATH, '//*[@id="close-button"]')
                for i in range(1):
                    next_button3.click()#close button
                    time.sleep(2)
                print("first close done..............................")

                max_attempts = 10
                for attempt_number in range(1, max_attempts+1):
                    bot.get(f"{channelurl3}/videos/upload?filter=%5B%7B%22name%22%3A%22VISIBILITY%22%2C%22value%22%3A%5B%22DRAFT%22%5D%7D%5D&sort=%7B%22columnType%22%3A%22date%22%2C%22sortOrder%22%3A%22DESCENDING%22%7D")
                    try:
                        element = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')))
                        print("Edit draft is clickable")
                        break
                    except:
                        print(f"Element is not clickable - attempt {attempt_number} of {max_attempts}")
                        time.sleep(7)

                try:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
                except:
                    next_button3 = bot.find_element(By.XPATH, '/html/body/ytcp-app/ytcp-entity-page/div/div/main/div/ytcp-animatable[4]/ytcp-content-section/ytcp-video-section/ytcp-video-section-content/div/ytcp-video-row/div/div[8]/ytcp-video-list-cell-actions/div/ytcp-button[3]/div')
                    for i in range(1):
                        next_button3.click()#MEdit draft
                        time.sleep(2)
                        print("video information open")
               
                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="step-badge-3"]')))
                next_button = bot.find_element(By.XPATH, '//*[@id="step-badge-3"]')
                for i in range(1):
                    next_button.click()#publish page
                    time.sleep(2)
                    bot.implicitly_wait(20)

                wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')))
                next_button7 = bot.find_element(By.XPATH, '/html/body/ytcp-uploads-dialog/tp-yt-paper-dialog/div/ytcp-animatable[1]/ytcp-uploads-review/div[2]/div[1]/ytcp-video-visibility-select/div[2]/tp-yt-paper-radio-group/tp-yt-paper-radio-button[3]')
                for i in range(1):
                    next_button7.click()#Select Public
                    time.sleep(1)

                wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="done-button"]')))
                done_button = bot.find_element(By.XPATH, '//*[@id="done-button"]')
                done_button.click()#Publish
                time.sleep(3)
               


                published = WebDriverWait(bot, 30).until(EC.text_to_be_present_in_element((By.XPATH, '//*[@id="dialog-title"]'), "Video"))
                print("processing done")
                time.sleep(2)

                sheet.update_cell(myvalue, 13, "uploaded")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Medical Product Review")
                try:
                    lastclose = bot.find_element(By.XPATH, '/html/body/ytcp-video-share-dialog/ytcp-dialog/tp-yt-paper-dialog/div[3]/ytcp-button/div')
                    lastclose.click()#Publish
                    time.sleep(1)
                    print("Last close done")
                except:
                    print("Last close Not done")

                bot.quit()
            except:
                sheet.update_cell(myvalue, 13, "function error")
                sheet.update_cell(myvalue, 14, today)
                sheet.update_cell(myvalue, 15, "Medical Product Review")

           
        elif value == "Noooooo":
            sheet.update_cell(i, 13, "Not available")
            sheet.update_cell(i, 14, today)
            sheet.update_cell(i, 15, "Medical Product Review")
           


def myuploader():
   
    # sudo_uploader2()
    # sudo_uploader3()
    sudo_uploader()


schedule.every().day.at("21:12").do(myuploader)

while True:
    # Checks whether a scheduled task
    # is pending to run or not
    try:
        schedule.run_pending()
        time.sleep(1)
    except:
        duration = 1000  # milliseconds
        frequency = 440  # Hz
        while True:
            winsound.Beep(frequency, duration)

0 comments:

Post a Comment

 
Top