pokepisode.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Form implementation generated from reading ui file 'pokepisode.ui'
  4. #
  5. # Created by: PyQt5 UI code generator 5.15.9
  6. #
  7. # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  8. # run again. Do not edit this file unless you know what you are doing.
  9. from PyQt5 import QtCore, QtGui, QtWidgets
  10. from PyQt5.QtWidgets import QApplication, QMainWindow
  11. import requests
  12. from bs4 import BeautifulSoup
  13. import json
  14. from datetime import datetime
  15. import re
  16. import sys
  17. # This changes almost every week
  18. # Of the many problems in this code, this is the biggest. I must
  19. # scrape this crap
  20. GOGOANIME = "anitaku.to"
  21. class Ui_MainWindow(object):
  22. def setupUi(self, MainWindow):
  23. MainWindow.setObjectName("MainWindow")
  24. MainWindow.resize(800, 600)
  25. self.centralwidget = QtWidgets.QWidget(MainWindow)
  26. self.centralwidget.setObjectName("centralwidget")
  27. self.TitleLabel = QtWidgets.QLabel(self.centralwidget)
  28. self.TitleLabel.setGeometry(QtCore.QRect(290, 20, 141, 31))
  29. self.TitleLabel.setObjectName("TitleLabel")
  30. self.gogoLinkButton = QtWidgets.QPushButton(self.centralwidget)
  31. self.gogoLinkButton.setGeometry(QtCore.QRect(60, 80, 75, 23))
  32. self.gogoLinkButton.setObjectName("gogoLinkButton")
  33. self.gogoLinkButton.clicked.connect(self.display_gogoanime_link)
  34. self.GoGoStatusLabel = QtWidgets.QLabel(self.centralwidget)
  35. self.GoGoStatusLabel.setGeometry(QtCore.QRect(60, 120, 500, 23))
  36. self.GoGoStatusLabel.setObjectName("GoGoStatusLabel")
  37. self.TorLinkButton = QtWidgets.QPushButton(self.centralwidget)
  38. self.TorLinkButton.setGeometry(QtCore.QRect(60, 150, 75, 23))
  39. self.TorLinkButton.setObjectName("TorLinkButton")
  40. self.TorLinkButton.clicked.connect(self.display_torrent_link)
  41. self.TorStatusLabel = QtWidgets.QLabel(self.centralwidget)
  42. self.TorStatusLabel.setGeometry(QtCore.QRect(60, 190, 500, 23))
  43. self.TorStatusLabel.setObjectName("TorStatusLabel")
  44. MainWindow.setCentralWidget(self.centralwidget)
  45. self.menubar = QtWidgets.QMenuBar(MainWindow)
  46. self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
  47. self.menubar.setObjectName("menubar")
  48. self.menuPokepisode = QtWidgets.QMenu(self.menubar)
  49. self.menuPokepisode.setObjectName("menuPokepisode")
  50. MainWindow.setMenuBar(self.menubar)
  51. self.statusbar = QtWidgets.QStatusBar(MainWindow)
  52. self.statusbar.setObjectName("statusbar")
  53. MainWindow.setStatusBar(self.statusbar)
  54. self.menubar.addAction(self.menuPokepisode.menuAction())
  55. self.retranslateUi(MainWindow)
  56. QtCore.QMetaObject.connectSlotsByName(MainWindow)
  57. def retranslateUi(self, MainWindow):
  58. _translate = QtCore.QCoreApplication.translate
  59. MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
  60. self.TitleLabel.setText(_translate("MainWindow", "PokEpisode"))
  61. self.gogoLinkButton.setText(_translate("MainWindow", "GoGo"))
  62. self.GoGoStatusLabel.setText(_translate("MainWindow", ""))
  63. self.TorLinkButton.setText(_translate("MainWindow", "Tor"))
  64. self.TorStatusLabel.setText(_translate("MainWindow", ""))
  65. self.menuPokepisode.setTitle(_translate("MainWindow", "Pokepisode"))
  66. def request(self, url, jsonify=False):
  67. r = requests.get(url)
  68. if not r.ok:
  69. self.show_error(f"Could not request url: {url}")
  70. return None
  71. return r.json() if jsonify else r.text
  72. def show_error(self, message):
  73. error_dialog = QtWidgets.QErrorMessage()
  74. error_dialog.showMessage(message)
  75. error_dialog.exec_()
  76. def gogoanime(self):
  77. data = self.request("https://ajax.gogocdn.net/ajax/load-list-episode?ep_start=0&ep_end=100000000&id=13784&default_ep=42&alias=pokemon-shinsaku-anime")
  78. if not data:
  79. return None
  80. soup = BeautifulSoup(data, 'html.parser')
  81. newest = soup.find_all("li")[0]
  82. number = int(newest.find('div', attrs={'class': 'name'}).text.split(" ")[-1])
  83. link = f"https://{GOGOANIME}" + newest.find('a')['href'][1:]
  84. return {"link": link, "number": number}
  85. def somestuffs(self):
  86. data = self.request(f"https://some-stuffs.com/")
  87. if not data:
  88. return None
  89. soup = BeautifulSoup(data, 'html.parser')
  90. newest = soup.find("script", attrs={'id': '__NEXT_DATA__'}).text
  91. content = json.loads(newest)["props"]["pageProps"]["allPosts"]
  92. details = [(episode) for episode in content if episode["categories"][0] == "pokemon"][0]
  93. number = int(details["slug"].split("-")[-1])
  94. soup = BeautifulSoup(details["mdContent"], 'html.parser')
  95. url = soup.find("a")['href']
  96. torrent = url.replace("view", "download") + ".torrent"
  97. return {"torrent": torrent, "url": url, "number": number}
  98. def wikipedia():
  99. data = request("https://en.wikipedia.org/w/index.php?title=Pok%C3%A9mon_Horizons:_The_Series&useskin=vector")
  100. soup = BeautifulSoup(data, 'html.parser')
  101. table = soup.find("table", {"class": "wikitable plainrowheaders wikiepisodetable"})
  102. rows = table.find_all("tr")
  103. current_date = datetime.now()
  104. last_episode = {}
  105. next_episode = {}
  106. def title_format(title):
  107. return re.findall('".*?"', title)[0]
  108. for i, row in enumerate(rows):
  109. columns = row.find_all("td")
  110. if len(columns) > 1:
  111. date_string = columns[6].text.strip().split("(")[-1].replace(")","")
  112. episode_date = datetime.strptime(date_string, "%Y-%m-%d")
  113. if episode_date <= current_date:
  114. last_episode = {
  115. "number": columns[1].text.strip(),
  116. "title": title_format(columns[2].text.strip()),
  117. "date": date_string
  118. }
  119. else:
  120. next_episode = {
  121. "number": columns[1].text.strip(),
  122. "title": title_format(columns[2].text.strip()),
  123. "date": date_string
  124. }
  125. break
  126. return (last_episode, next_episode)
  127. def display_gogoanime_link(self):
  128. result = self.gogoanime()
  129. if result:
  130. self.GoGoStatusLabel.setText(f"GoGoAnime link: {result['link']}")
  131. def display_torrent_link(self):
  132. result = self.somestuffs()
  133. if result:
  134. self.TorStatusLabel.setText(f"Torrent link: {result['url']}")
  135. def display_new_episode(self):
  136. result = self.
  137. if __name__ == "__main__":
  138. import sys
  139. app = QtWidgets.QApplication(sys.argv)
  140. MainWindow = QtWidgets.QMainWindow()
  141. ui = Ui_MainWindow()
  142. ui.setupUi(MainWindow)
  143. MainWindow.show()
  144. sys.exit(app.exec_())