app.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from bs4 import BeautifulSoup
  2. import requests
  3. from typing import List
  4. import os
  5. def search_series(serie_name: str) -> List[str]:
  6. base_url = "https://iptorrents.com/"
  7. search_url = f"{base_url}search.php?cat=0search={serie_name}"
  8. response = requests.get(search_url)
  9. response.raise_for_status()
  10. soup = BeautifulSoup(response.content, 'html.parser')
  11. results = soup.find_all('a', {'class': 'site-main'})
  12. torrents = []
  13. for result in results:
  14. link = result['href']
  15. if link.startswith('torrents'):
  16. torrents.append(f"{base_url}{link}")
  17. return torrents
  18. def download_torrent(url: str, file_name: str) -> None:
  19. response = requests.get(url)
  20. with open(file_name, 'wb') as f:
  21. f.write(response.content)
  22. def main() -> None:
  23. serie_name = input("Name serie: ")
  24. torrents = search_series(serie_name)
  25. if len(torrents) <= 0:
  26. return
  27. for idx, torrent in enumerate(torrents):
  28. print(f"{idx+1}. {torrent}")
  29. choice = int(input("Qual serie? "))
  30. if 0 <= choice < len(torrents):
  31. torrent_url = torrents[choice]
  32. torrent_name = f"{os.path.basename(torrent_url)}.torrent"
  33. download_torrent(torrent_url, torrent_name)
  34. print(f"downloaded torrent {torrent_name}")
  35. else:
  36. print("Escolha invalida")
  37. if __name__ == '__main__':
  38. main()