Browse Source

First commit

Douglas A 1 year ago
commit
c4f6d2555f
1 changed files with 48 additions and 0 deletions
  1. 48 0
      app.py

+ 48 - 0
app.py

@@ -0,0 +1,48 @@
+from bs4 import BeautifulSoup
+import requests
+
+from typing import List
+import os
+
+
+def search_series(serie_name: str) -> List[str]:
+    base_url = "https://iptorrents.com/"
+    search_url = f"{base_url}search.php?cat=0search={serie_name}"
+    response = requests.get(search_url)
+    response.raise_for_status()
+
+    soup = BeautifulSoup(response.content, 'html.parser')
+    results = soup.find_all('a', {'class': 'site-main'})
+    torrents = []
+    for result in results:
+        link = result['href']
+        if link.startswith('torrents'):
+            torrents.append(f"{base_url}{link}")
+    return torrents
+
+
+def download_torrent(url: str, file_name: str) -> None:
+    response = requests.get(url)
+    with open(file_name, 'wb') as f:
+        f.write(response.content)
+
+
+def main() -> None:
+    serie_name = input("Name serie: ")
+    torrents = search_series(serie_name)
+    if len(torrents) <= 0:
+        return
+    for idx, torrent in enumerate(torrents):
+        print(f"{idx+1}. {torrent}")
+    choice = int(input("Qual serie? "))
+    if 0 <= choice < len(torrents):
+        torrent_url = torrents[choice]
+        torrent_name = f"{os.path.basename(torrent_url)}.torrent"
+        download_torrent(torrent_url, torrent_name)
+        print(f"downloaded torrent {torrent_name}")
+    else:
+        print("Escolha invalida")
+
+
+if __name__ == '__main__':
+    main()