multiF.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import threading
  2. from threading import *
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.firefox.options import Options
  6. import subprocess
  7. import requests
  8. from bs4 import BeautifulSoup
  9. import time
  10. from pyfzf.pyfzf import FzfPrompt
  11. import sqlite3
  12. import os
  13. fzf = FzfPrompt()
  14. options = Options()
  15. sleep = threading.Event()
  16. def get_html(url):
  17. r = requests.get(url)
  18. soup = BeautifulSoup(r.text, "lxml")
  19. item = soup.find("div", class_ = "tabs-b video-box").find("iframe").get("src")
  20. return item
  21. def get_translations(driver):
  22. time.sleep(1)
  23. try:
  24. driver.find_element(By.XPATH,"/html/body/div[1]/div").click()
  25. items = driver.find_elements(By.CLASS_NAME, value="list")
  26. table = [i.text for i in items]
  27. table = [i for i in table[0].split("\n")]
  28. a = fzf.prompt(table, ' --cycle')
  29. driver.find_element(By.XPATH,f"/html/body/div[1]/div/ul/li[{table.index(a[0])+1}]").click()
  30. time.sleep(1)
  31. except:
  32. print("Could not get different translations")
  33. def get_quality(driver):
  34. try:
  35. time.sleep(1)
  36. driver.find_element(By.XPATH, "/html/body/div[2]/pjsdiv/pjsdiv[20]/pjsdiv[1]/pjsdiv").click()
  37. driver.find_element(By.XPATH, "/html/body/div[2]/pjsdiv/pjsdiv[27]/pjsdiv[1]/pjsdiv/pjsdiv[9]").click()
  38. except:
  39. time.sleep(1)
  40. driver.find_element(By.XPATH, "/html/body/div/pjsdiv/pjsdiv[20]/pjsdiv[1]/pjsdiv").click()
  41. driver.find_element(By.XPATH, "/html/body/div/pjsdiv/pjsdiv[27]/pjsdiv[1]/pjsdiv/pjsdiv[9]").click()
  42. def get_film_lord(driver):
  43. try:
  44. step1 = driver.find_element(By.XPATH, "/html/body/div[2]/pjsdiv/pjsdiv[1]/video")
  45. except:
  46. step1 = driver.find_element(By.XPATH, "/html/body/div/pjsdiv/pjsdiv[1]/video")
  47. step2 = str(step1.get_attribute("src"))
  48. return step2
  49. def get_film_zona(driver):
  50. try:
  51. step1 = driver.find_element(by=By.XPATH, value='//*[@id="player_html5_api"]')
  52. except:
  53. print("err")
  54. step2 = str(step1.get_attribute("src"))
  55. return step2
  56. def with_player(link):
  57. print("Link to the movie:", link)
  58. choice = fzf.prompt(["mpv", "vlc"], '--cycle')[0]
  59. print("Wait. Film is loading ... ")
  60. try:
  61. if choice == 'mpv' or choice == 'ьзм' :
  62. subprocess.run(['mpv', link])
  63. elif choice == 'vlc' or choice == 'мдс':
  64. subprocess.run(['vlc', link])
  65. except:
  66. print("Error")
  67. def get_link():
  68. Database = sqlite3.connect("Film_list.db")
  69. cur = Database.cursor()
  70. a=cur.execute("SELECT COUNT (*) FROM Film_list").fetchall()[0][0]
  71. name_list = ['']*a
  72. i=0
  73. for name in cur.execute("SELECT NAME FROM Film_list "):
  74. name_list[i]=name[0]
  75. i+=1
  76. names = fzf.prompt(name_list, '--cycle')[0]
  77. with open("link.txt", 'w', encoding='utf8') as file:
  78. file.write(next(cur.execute(f"SELECT LINK FROM Film_list WHERE NAME='{names}'"))[0])
  79. sleep.set()
  80. def clear_txt():
  81. try:
  82. path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'link.txt')
  83. os.remove(path)
  84. except:
  85. pass
  86. def start_browser():
  87. print("Wait. Browser is loading ...")
  88. options.page_load_strategy="eager"
  89. #options.headless = True
  90. driver = webdriver.Firefox(options=options)
  91. sleep.wait()
  92. with open('link.txt',encoding='utf8') as file:
  93. url = file.read()
  94. try:
  95. print("Translations are loading...")
  96. driver.get(url)
  97. if url.find("zona") != -1:
  98. driver.get(url)
  99. time.sleep(1)
  100. link = get_film_zona(driver)
  101. elif url.find("lord") != -1:
  102. url = get_html(url)
  103. driver.get(url)
  104. get_translations(driver)
  105. print("Wait quality is loading... ")
  106. get_quality(driver)
  107. link = get_film_lord(driver)
  108. except:
  109. print("Download film error")
  110. finally:
  111. clear_txt()
  112. driver.close()
  113. driver.quit()
  114. with_player(link)
  115. if __name__=="__main__":
  116. t1=Thread(target=start_browser)
  117. t2=Thread(target=get_link)
  118. t1.start()
  119. t2.start()
  120. t2.join()
  121. t1.join()