Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Improved download speeds, silent flag, download speed display

See merge request namibsun/python/xdcc-dl!4
  • Loading branch information
namboy94 committed Oct 6, 2019
2 parents 00c80df + e3c84fc commit c49fdfc
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 55 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
V 3.3.0:
- Added download speed progress
- 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
Expand Down
12 changes: 10 additions & 2 deletions bin/xdcc-browse
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main(args: argparse.Namespace):
:return: None
"""
try:
set_logging_level(args.quiet, args.verbose, args.debug)
set_logging_level(args.quiet, args.verbose, args.debug, args.silent)
set_throttle_value(args.throttle)

search_engine = SearchEngineType.resolve(args.search_engine)
Expand All @@ -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")
Expand Down Expand Up @@ -90,6 +94,10 @@ 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("--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,
Expand Down
12 changes: 10 additions & 2 deletions bin/xdcc-dl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ def main(args: argparse.Namespace):
"""
try:
set_throttle_value(args.throttle)
set_logging_level(args.quiet, args.verbose, args.debug)
set_logging_level(args.quiet, args.verbose, args.debug, args.silent)

packs = XDCCPack.from_xdcc_message(
args.message, os.getcwd(), args.server
)
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.")
Expand All @@ -71,7 +75,11 @@ 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")
cli_start(
main, parser,
sentry_dsn=sentry_dsn,
Expand Down
8 changes: 6 additions & 2 deletions bin/xdcc-search
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.3.0
7 changes: 5 additions & 2 deletions xdcc_dl/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ def set_throttle_value(throttle_string: str):
sys.exit(1)


def set_logging_level(quiet: bool, verbose: bool, debug: bool):
def set_logging_level(quiet: bool, verbose: bool, debug: bool, silent: bool):
"""
Sets the logging level based on a combination of flags
If all flags are False, the logging level will be set to WARNING
:param quiet: If set to True, will set logging to ERROR
:param verbose: If set to True, will set logging to INFO
:param debug: If set to True, will set logging to DEBUG
:param silent: If set to True, will disable ALL printing
:return: None
"""
if quiet:
if silent:
Logger.logging_level = -1
elif quiet:
Logger.logging_level = logging.ERROR
elif verbose:
Logger.logging_level = logging.INFO
Expand Down
14 changes: 11 additions & 3 deletions xdcc_dl/logging/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
from typing import Optional
from datetime import datetime
from subprocess import check_output
from subprocess import check_output, CalledProcessError
from colorama import Fore, Back, Style


Expand Down Expand Up @@ -52,6 +52,9 @@ def log(self, message: str, level: Optional[int], back: Back = Back.BLACK,
:param end: Characters to append to the string (Default newline)
:return: None
"""
if self.logging_level == -1:
return

if level is None or self.logging_level <= level:

if self.last_end == "\r" and end != "\r":
Expand All @@ -60,8 +63,13 @@ def log(self, message: str, level: Optional[int], back: Back = Back.BLACK,
log_message = datetime.now().strftime("[%Y-%d-%m:%H-%M-%S]")
log_message += " " + fore + back + message

rows, columns = check_output(['stty', 'size']).split()
log_message = log_message[0:int(columns)]
try:
rows, _columns = check_output(['stty', 'size']).split()
columns = int(_columns)
except (ValueError, CalledProcessError):
columns = 80

log_message = log_message[0:columns]

print(log_message + Style.RESET_ALL, end=end)

Expand Down
Loading

0 comments on commit c49fdfc

Please sign in to comment.