Coverage for xdcc_dl/pack_search/procedures/nibl.py : 18%

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>
4This file is part of xdcc-dl.
6xdcc-dl is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11xdcc-dl is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with xdcc-dl. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20# imports
21import requests
22from typing import List
23from bs4 import BeautifulSoup
24from xdcc_dl.entities.XDCCPack import XDCCPack
25from xdcc_dl.entities.IrcServer import IrcServer
26from puffotter.units import byte_string_to_byte_count
29def find_nibl_packs(search_phrase: str) -> List[XDCCPack]:
30 """
31 Searches for XDCC Packs matching the specified search string on nibl.co.uk
33 :param search_phrase: The search phrase to search for
34 :return: The list of found XDCC Packs
35 """
37 # Prepare the search term, nibl.co.uk uses + symbols as spaces.
38 split_search_term = search_phrase.split(" ")
39 prepared_search_term = split_search_term[0]
40 i = 1
41 while i < len(split_search_term):
42 prepared_search_term += "+" + split_search_term[i]
43 i += 1
45 # Get the data from the website
47 url = "https://nibl.co.uk/bots.php?search=" + prepared_search_term
48 html = requests.get(url).text
50 content = BeautifulSoup(html, "html.parser")
51 file_names = content.select(".filename")
52 pack_numbers = content.select(".packnumber")
53 bot_names = content.select(".name")
54 file_sizes = content.select(".filesize")
56 results = []
57 i = 0 # We need a counter variable since we have four lists of data
59 while i < len(file_names):
61 # The filename has two links after it, which need to be cut out
62 filename = file_names[i].text.rsplit(" \n", 1)[0]
64 # The bot name has a link after it, which needs to be cut out
65 bot = bot_names[i].text.rsplit(" ", 1)[0]
67 server = "irc.rizon.net"
68 packnumber = int(pack_numbers[i].text)
69 size = file_sizes[i].text.lower()
71 result = XDCCPack(IrcServer(server), bot, packnumber)
73 result.set_size(byte_string_to_byte_count(size))
74 result.set_filename(filename)
75 results.append(result)
76 i += 1
78 return results