1+ import urllib .request
2+ import urllib .parse
3+ from bs4 import BeautifulSoup
4+ from ui .ui_print import *
5+ import releases
6+
7+ name = "limetorrents"
8+ session = urllib .request .build_opener ()
9+
10+
11+ def setup (cls , new = False ):
12+ from scraper .services import setup
13+ setup (cls , new )
14+
15+
16+ def scrape (query , altquery ):
17+ from scraper .services import active
18+ scraped_releases = []
19+ if 'limetorrents' in active :
20+ ui_print ("[limetorrents] using extended query: " + query , ui_settings .debug )
21+
22+ headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' }
23+
24+ url = f'https://www.limetorrents.lol/search/all/' + urllib .parse .quote (query , safe = ':/' ) + '/'
25+ response = None
26+ try :
27+ ui_print ("[limetorrents] Sending GET request to URL: " + url , ui_settings .debug )
28+ request = urllib .request .Request (url , headers = headers )
29+ response = session .open (request )
30+ status_code = response .getcode ()
31+
32+ if status_code == 200 :
33+ content = response .read ().decode ('utf-8' , errors = 'ignore' )
34+ soup = BeautifulSoup (content , 'html.parser' )
35+ torrentList = soup .select ('tr:has(td.tdleft)' )[4 ::1 ]
36+ if torrentList :
37+ ui_print (f"[limetorrents] Found { len (torrentList )} torrent(s)" , ui_settings .debug )
38+ for count , torrent in enumerate (torrentList ):
39+ title_element = torrent .select_one ('div.tt-name a:nth-of-type(2)' )
40+ title = title_element .get_text () if title_element else 'Unknown Title'
41+ title = regex .sub (r'[^\w\s\.\-]' , '' , title ) # a good place for this is in the classes.py during the regex bits that checks for matches
42+ title = title .replace (" " , '.' )
43+ title = regex .sub (r'\.+' , "." , title )
44+ if regex .match (r'(' + altquery .replace ('.' , r'\.' ).replace (r"\.*" , ".*" ) + ')' , title , regex .I ):
45+ download_element = torrent .select_one ('td.item-icons a[href^="magnet"]' )
46+ download = download_element ['href' ] if download_element else '#'
47+
48+ link_element = torrent .select_one ('div.tt-name a:nth-of-type(1)' )
49+ link = link_element ['href' ] if link_element else '#'
50+ download = link .replace ("http://itorrents.org/torrent/" , "magnet:?xt=urn:btih:" ).replace (".torrent?title=" , "&dn=" )
51+
52+ size_element = torrent .select_one ('td.tdnormal:nth-of-type(3)' )
53+ size = size_element .get_text ().strip () if size_element else '0 GB'
54+ size_match = regex .search (r'([0-9]*\.?[0-9]+)\s*(KB|MB|GB)' , size , regex .I )
55+
56+ seeders_element = torrent .select_one ('td.tdseed' )
57+ seeders = int (seeders_element .get_text ().strip ()) if seeders_element else 0
58+
59+ if size_match :
60+ size_value = float (size_match .group (1 ))
61+ size_unit = size_match .group (2 ).upper ()
62+
63+ if size_unit == 'KB' :
64+ size = size_value / (1024 * 1024 )
65+ elif size_unit == 'MB' :
66+ size = size_value / 1024
67+ elif size_unit == 'GB' :
68+ size = size_value
69+ else :
70+ size = float (size_value )
71+
72+ scraped_releases += [releases .release ('[limetorrents]' , 'torrent' , title , [], size , [download ], seeders = seeders )]
73+ ui_print (f"[limetorrents] Scraped release: title={ title } , size={ size :.2f} GB, seeders={ seeders } " , ui_settings .debug )
74+ else :
75+ ui_print ("[limetorrents] No torrents found" , ui_settings .debug )
76+ else :
77+ ui_print ("[limetorrents] Failed to retrieve the page. Status code: " + str (status_code ), ui_settings .debug )
78+
79+ except Exception as e :
80+ if hasattr (response , "status_code" ) and not str (response .status_code ).startswith ("2" ):
81+ ui_print ('[limetorrents] error ' + str (response .status_code ) + ': limetorrents is temporarily not reachable' )
82+ else :
83+ ui_print ('[limetorrents] error: unknown error. turn on debug printing for more information.' )
84+ response = None
85+ ui_print ('[limetorrents] error: exception: ' + str (e ), ui_settings .debug )
86+ return scraped_releases
0 commit comments