start.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. from selenium import webdriver
  2. import time
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.firefox.options import Options
  5. from pyfzf.pyfzf import FzfPrompt
  6. import os
  7. import sqlite3
  8. from os.path import exists
  9. print("Загрузка...5 секунд....")
  10. options = Options()
  11. options.headless = True
  12. driver = webdriver.Firefox(options=options)
  13. driver.get("https://www.youtube.com/channel/UCZ26MoNJKaGXFQWKuGVzmAg")
  14. time.sleep(2)
  15. ### ЕСЛИ ВЫ СМОТРИТЕ YOUTUBE С ТЕРРИТОРИИ СНГ ЗАКОММЕНТИРУЙТЕ 3 СТРОЧКИ
  16. element = driver.find_element(By.XPATH, """/html/body/c-wiz/div/div/div/div[2]/div[1]/div[4]/form/div[1]/div/button""")
  17. element.click()
  18. time.sleep(3)
  19. ### ПОМНИТЕ СЕСЕВЫЕ ПРОГУЛКИ С ТЕРРИТОРИИ СНГ ОПАСНЫ ДЛЯ ВАС!
  20. print("Браузер загружен!")
  21. fzf = FzfPrompt()
  22. def search():
  23. sear = input("Введите то что вы хотите найти: ")
  24. print("Начинаю поиск " + sear)
  25. search_bar = driver.find_element(By.XPATH, """//input[@id="search"]""")
  26. search_bar.send_keys(sear)
  27. searchbutton = driver.find_element(By.XPATH, '//*[@id="search-icon-legacy"]')
  28. searchbutton.click()
  29. time.sleep(2)
  30. sear_list = []
  31. videos = driver.find_elements(By.ID, "video-title")
  32. for i in range(len(videos)):
  33. print(videos[i].text)
  34. sear_l = videos[i].text
  35. sear_list.append(sear_l)
  36. if i == 10:
  37. break
  38. target_half=fzf.prompt(sear_list)
  39. print(target_half[0])
  40. vibor2 = target_half[0]
  41. for i in range(len(videos)):
  42. name = videos[i].text
  43. if name == vibor2:
  44. print(videos[i].get_attribute('href'))
  45. zzzz = videos[i].get_attribute('href')
  46. comand = "mpv " + zzzz
  47. os.system(comand)
  48. def func():
  49. db = sqlite3.connect('Chanelll.db')
  50. db.row_factory = lambda cursor, row: row[0]
  51. c = db.cursor()
  52. ids = c.execute('SELECT NAME FROM Chanelll').fetchall()
  53. ids.append("ПОИСК+++")
  54. target_chanel=fzf.prompt(ids)
  55. print(target_chanel[0])
  56. vibor = target_chanel[0]
  57. if vibor == "ПОИСК+++":
  58. search()
  59. else:
  60. nomber_chanel = (ids.index(target_chanel[0]))
  61. url = f[nomber_chanel]
  62. end_url = url[0]
  63. driver.get(end_url)
  64. time.sleep(2)
  65. spisokNAME=[]
  66. video_name = driver.find_elements(By.ID, "video-title")
  67. for i in range(len(video_name)):
  68. print(video_name[i].text)
  69. ggg = video_name[i].text
  70. spisokNAME.append(ggg)
  71. if i == 20:
  72. break
  73. target1=fzf.prompt(spisokNAME)
  74. print(target1[0])
  75. cccc = target1[0]
  76. for i in range(len(video_name)):
  77. ggg = video_name[i].text
  78. if ggg == cccc:
  79. print(video_name[i].get_attribute('href'))
  80. link = video_name[i].get_attribute('href')
  81. comand2 = "mpv " + link
  82. os.system(comand2)
  83. while(True):
  84. chanel_list = []
  85. kom = exists("Chanelll.db")
  86. f = [i.strip('\n').split(',') for i in open('subscribe.txt')]
  87. if kom == True:
  88. print("База каналов найдена!")
  89. db = sqlite3.connect('Chanel.db')
  90. func()
  91. else:
  92. print("Генерируем базу каналов, это может занять некоторое время...")
  93. db = sqlite3.connect('Chanelll.db')
  94. cur = db.cursor()
  95. cur.execute("""CREATE TABLE IF NOT EXISTS Chanelll (
  96. ID INTEGER PRIMARY KEY,
  97. NAME TEXT,
  98. URL TEXT
  99. )""")
  100. db.commit()
  101. for k in f:
  102. h = (k[0])
  103. driver.get(h)
  104. time.sleep(3)
  105. element2 = driver.find_element(By.XPATH, """//*[@id="channel-name"]""")
  106. pre_canell = element2.text
  107. cur.execute("""INSERT INTO Chanelll(NAME, URL) VALUES (?,?);""", (pre_canell, h))
  108. db.commit()
  109. print(pre_canell + " Добавлен в базу! ")
  110. chanel_list.append(pre_canell)
  111. func()