Commit c9c91345 authored by Hermann Krumrey's avatar Hermann Krumrey

Add --fallback-channel option

parent 1248e4ca
......@@ -3,6 +3,7 @@ V 3.3.0:
- Fixed slow download speeds
- Fixed crashes when running without a tty
- Added --silent flag
- Added --fallback-channel option
V 3.2.0:
- Added notice that python 2 is no longer supported
- Fixed program hanging when no channels are joined
......
......@@ -60,7 +60,11 @@ def main(args: argparse.Namespace):
for pack in packs:
Logger().info("Downloading pack {}".format(pack))
download_packs(packs, timeout=args.timeout)
download_packs(
packs,
timeout=args.timeout,
fallback_channel=args.fallback_channel
)
except ConnectionError:
print("Connection Error, could not conduct search")
......@@ -92,6 +96,8 @@ if __name__ == "__main__":
help="Sets a timeout for starting the download")
parser.add_argument("--silent", action="store_true",
help="Disables all print output")
parser.add_argument("--fallback-channel",
help="Fallback channel in case ")
argparse_add_verbosity(parser)
cli_start(
main, parser,
......
......@@ -44,7 +44,11 @@ def main(args: argparse.Namespace):
)
prepare_packs(packs, args.out)
download_packs(packs, timeout=args.timeout)
download_packs(
packs,
timeout=args.timeout,
fallback_channel=args.fallback_channel
)
except DownloadIncomplete:
Logger().warning("Download incomplete.")
......@@ -71,6 +75,8 @@ if __name__ == "__main__":
"Append K,M or G for more convenient units")
parser.add_argument("--timeout", default=120, type=int,
help="Sets a timeout for starting the download")
parser.add_argument("--fallback-channel",
help="Fallback channel in case ")
argparse_add_verbosity(parser)
parser.add_argument("--silent", action="store_true",
help="Disables all print output")
......
......@@ -35,9 +35,13 @@ def main(args: argparse.Namespace):
search_engine = SearchEngineType.resolve(args.search_engine)
results = search_engine.search(args.search_term)
for result in results:
message = "{} (xdcc-dl \"{}\")".format(result.filename, result.get_request_message(True))
message = "{} (xdcc-dl \"{}\")".format(
result.filename,
result.get_request_message(True)
)
if result.server.address != "irc.rizon.net":
message = message[0:-1] + " --server " + result.server.address + ")"
message = message[0:-1]
message += " --server " + result.server.address + ")"
print(message)
except ConnectionError:
print("Connection Error, could not conduct search")
......
......@@ -81,13 +81,16 @@ class XDCCClient(SimpleIRCClient):
self,
pack: XDCCPack,
retry: bool = False,
timeout: int = 120
timeout: int = 120,
fallback_channel: Optional[str] = None
):
"""
Initializes the XDCC IRC client
:param pack: The pack to downloadX
:param retry: Set to true for retried downloads.
:param timeout: Sets the timeout time for starting downloads
:param fallback_channel: A fallback channel for when whois
fails to find a valid channel
"""
self.logger = Logger()
......@@ -104,6 +107,7 @@ class XDCCClient(SimpleIRCClient):
self.connect_start_time = 0.0
self.timeout = timeout
self.timed_out = False
self.fallback_channel = fallback_channel
self.connected = True
self.disconnected = False
......@@ -269,7 +273,14 @@ class XDCCClient(SimpleIRCClient):
"""
self.logger.info("WHOIS End")
if self.channels is None:
self.on_join(conn, _, True)
if self.fallback_channel is not None:
channel = self.fallback_channel
if not channel.startswith("#"):
channel = "#" + channel
conn.join(channel)
return
else:
self.on_join(conn, _, True)
def on_join(
self,
......
......@@ -17,19 +17,27 @@ You should have received a copy of the GNU General Public License
along with xdcc-dl. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""
from typing import List
from typing import List, Optional
from xdcc_dl.entities.XDCCPack import XDCCPack
from xdcc_dl.xdcc.XDCCClient import XDCCClient
def download_packs(packs: List[XDCCPack], timeout: int = 120):
def download_packs(
packs: List[XDCCPack],
timeout: int = 120,
fallback_channel: Optional[str] = None
):
"""
Downloads a list of XDCC Packs
:param packs: The packs to download
:param timeout: Specifies timeout time
:param fallback_channel: A fallback channel for when no channels were found
:return: None
"""
for pack in packs:
client = XDCCClient(pack, timeout=timeout)
client = XDCCClient(
pack,
timeout=timeout,
fallback_channel=fallback_channel
)
client.download()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment