bittorrent.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import requests
  2. import sys
  3. from bs4 import BeautifulSoup as bs
  4. from plugins.plugin import Plugin
  5. sys.path.append("..")
  6. from src.torrent import Torrent
  7. from src.history import History
  8. from src.config import Config
  9. class BitTorrent(Plugin):
  10. def __init__(self, history: History=History(), config: Config=Config()) -> None:
  11. super().__init__(history, config)
  12. self.history = history
  13. self.config = config
  14. self.name = "[-] BitTorrent"
  15. self.category = "BitTorrent"
  16. self.params = {
  17. 'instance' : False
  18. }
  19. self.flag = "-bt"
  20. self.full_flag = "--bittorrent"
  21. self.flag_help = "show torrents from popular trackers"
  22. self.flag_action = "store_true"
  23. def get_torrent(self, instance):
  24. torrents = list()
  25. html = requests.get("https://torrenther.com/")
  26. soup = bs(html.text, 'html.parser')
  27. for video_box in soup.find_all("div", {"class": "d1shortss"}):
  28. vpage_url = video_box.find("a", href=True)['href']
  29. title = video_box.find("a", {"class" : "d1short-name"}).text
  30. v_html = requests.get(vpage_url)
  31. v_soup = bs(v_html.text, 'html.parser')
  32. torrent_url = v_soup.find("div", {"id": "download"}).find("a", href=True)['href']
  33. print(title, torrent_url)
  34. torrent = Torrent(title=title, url=torrent_url)
  35. torrents.append(torrent.to_json())
  36. return torrents
  37. def get_torrents(self, params):
  38. instance = 'https://torrenther.com/'
  39. if 'instance' in params:
  40. instance = params['instance']
  41. torrents = self.get_torrenther(instance)
  42. return torrents
  43. def get_items(self, params):
  44. return self.get_torrents(params)