Coverage for xdcc_dl/pack_search/procedures/ixirc.py : 12%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""LICENSE
2Copyright 2016 Hermann Krumrey <hermann@krumreyh.com>
3 2020 Jean Wicht <jean.wicht@gmail.com>
5This file is part of xdcc-dl.
7xdcc-dl is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
12xdcc-dl is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
17You should have received a copy of the GNU General Public License
18along with xdcc-dl. If not, see <http://www.gnu.org/licenses/>.
19LICENSE"""
21import requests
22from typing import List
23from xdcc_dl.entities.XDCCPack import XDCCPack
24from xdcc_dl.entities.IrcServer import IrcServer
27def find_ixirc_packs(search_phrase: str) -> List[XDCCPack]:
28 """
29 Searches for XDCC Packs matching the specified search string on ixirc.com
30 Implementation courtesy of Jean Wicht <jean.wicht@gmail.com>.
32 :param search_phrase: The search phrase to search for
33 :return: The list of found XDCC Packs
34 """
36 if not search_phrase:
37 return []
39 packs: List[XDCCPack] = []
40 page_id = 0
41 # the number of pages of results will be set properly in the request below
42 page_count = 42
43 while page_id < page_count:
44 request = requests.get(
45 "https://ixirc.com/api/",
46 params={"q": search_phrase, "pn": str(page_id)},
47 )
49 if request.status_code != 200:
50 return packs
52 data = request.json()
53 page_count = int(data["pc"])
55 if "results" not in data:
56 # no results
57 return []
59 for result in data["results"]:
60 if "uname" not in result:
61 # bot not online
62 continue
64 server = IrcServer(result["naddr"], result["nport"])
65 pack = XDCCPack(server, result["uname"], int(result["n"]))
66 pack.set_filename(result["name"])
67 pack.set_size(result["sz"])
68 packs.append(pack)
70 page_id += 1 # next page
72 return packs