Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request namibsun/python/xdcc-dl!1
  • Loading branch information
namboy94 committed Jan 22, 2019
2 parents d4e81b4 + 58ec530 commit 89fc658
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ unittest:
- progstats
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- pip install irc
- python-unittest

release_upload:
Expand All @@ -39,6 +40,7 @@ pypi_upload:
- python3
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- pip install irc
- pypi-upload

gitstats:
Expand All @@ -58,4 +60,5 @@ docgen:
- progstats
script:
- python3 -m venv virtual && source virtual/bin/activate && pip install ci-scripts
- pip install irc
- sphinx-docgen
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
V 3.1.0:
- Implemented xdcc-browse
- Handles failed requests for packs better
- Fixed horriblesubs search for pack names containing commas
V 3.0.3:
- Imported legacy projects
V 3.0.2:
Expand Down
98 changes: 98 additions & 0 deletions bin/xdcc-browse
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python
"""LICENSE
Copyright 2016 Hermann Krumrey <[email protected]>
This file is part of xdcc-dl.
xdcc-dl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
xdcc-dl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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"""

import argparse
from requests.exceptions import ConnectionError
from xdcc_dl.xdcc.exceptions import DownloadIncomplete
from xdcc_dl.helper import set_throttle_value, set_logging_level, prepare_packs
from xdcc_dl.entities import XDCCPack
from xdcc_dl.logging import Logger
from xdcc_dl.xdcc import download_packs
from xdcc_dl.pack_search.SearchEngine import SearchEngineType


def main():
"""
Conducts a XDCC pack search
:return: None
"""
parser = argparse.ArgumentParser()
parser.add_argument("search_term", help="The term to search for")
parser.add_argument("--search_engine",
default=SearchEngineType.HORRIBLESUBS.name.lower(),
choices=SearchEngineType.choices(True),
help="The Search Engine to use")
parser.add_argument("-s", "--server",
default="irc.rizon.net",
help="Specifies the IRC Server. "
"Defaults to irc.rizon.net")
parser.add_argument("-o", "--out",
help="Specifies the target file. "
"Defaults to the pack's file name. "
"When downloading multiple packs, index "
"numbers will be appended to the filename")
parser.add_argument("-v", "--verbose", action="store_true",
help="Sets the verbosity of the program to INFO")
parser.add_argument("-d", "--debug", action="store_true",
help="Sets the verbosity of the program to DEBUG")
parser.add_argument("-q", "--quiet", action="store_true",
help="Disables all output")
parser.add_argument("-t", "--throttle",
help="Limits the download speed of xdcc-dl. "
"Append K,M or G for more convenient units")
args = parser.parse_args()

try:

set_logging_level(args.quiet, args.verbose, args.debug)
set_throttle_value(args.throttle)

search_engine = SearchEngineType.resolve(args.search_engine)

results = search_engine.search(args.search_term)
for i, result in enumerate(results):
Logger().print("{}: {}".format(i + 1, result))

selection = input("Enter the packs to download: ")
parsepacks = XDCCPack.from_xdcc_message(
"/msg A xdcc send #{}".format(selection)
)

packs = []
for pack in parsepacks: # type: XDCCPack
packs.append(results[pack.packnumber - 1])
prepare_packs(packs, args.out)

for pack in packs:
Logger().info("Downloading pack {}".format(pack))

download_packs(packs)

except ConnectionError:
print("Connection Error, could not conduct search")
except KeyboardInterrupt:
Logger().print("Thanks for using xdcc-dl!")
except DownloadIncomplete:
Logger().warning("Download incomplete.")
Logger().print("Thanks for using xdcc-dl!")


if __name__ == "__main__":
main()
78 changes: 35 additions & 43 deletions bin/xdcc-dl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ LICENSE"""

# imports
import os
import logging
import argparse
from xdcc_dl.xdcc import download_packs
from xdcc_dl.logging import Logger
from xdcc_dl.helper import set_throttle_value
from xdcc_dl.helper import set_throttle_value, set_logging_level, prepare_packs
from xdcc_dl.entities import XDCCPack
from xdcc_dl.logging import Logger
from xdcc_dl.xdcc.exceptions import DownloadIncomplete


def main():
Expand All @@ -34,55 +34,47 @@ def main():
:return: None
"""
try:
parser = argparse.ArgumentParser()
parser.add_argument("message",
help="An XDCC Message. Supports ranges (1-100), "
"ranges with steps (1-100;2) as well as "
"comma-separated packs: (1,2,3).")
parser.add_argument("-s", "--server",
default="irc.rizon.net",
help="Specifies the IRC Server. "
"Defaults to irc.rizon.net")
parser.add_argument("-o", "--out",
help="Specifies the target file. "
"Defaults to the pack's file name. "
"When downloading multiple packs, index "
"numbers will be appended to the filename")
parser.add_argument("-v", "--verbose", action="store_true",
help="Sets the verbosity of the program to INFO")
parser.add_argument("-q", "--quiet", action="store_true",
help="Disables all output")
parser.add_argument("-t", "--throttle",
help="Limits the download speed of xdcc-dl. "
"Append K,M or G for more convenient units")
args = parser.parse_args()
parser = argparse.ArgumentParser()
parser.add_argument("message",
help="An XDCC Message. Supports ranges (1-100), "
"ranges with steps (1-100;2) as well as "
"comma-separated packs: (1,2,3).")
parser.add_argument("-s", "--server",
default="irc.rizon.net",
help="Specifies the IRC Server. "
"Defaults to irc.rizon.net")
parser.add_argument("-o", "--out",
help="Specifies the target file. "
"Defaults to the pack's file name. "
"When downloading multiple packs, index "
"numbers will be appended to the filename")
parser.add_argument("-v", "--verbose", action="store_true",
help="Sets the verbosity of the program to INFO")
parser.add_argument("-d", "--debug", action="store_true",
help="Sets the verbosity of the program to DEBUG")
parser.add_argument("-q", "--quiet", action="store_true",
help="Disables all output")
parser.add_argument("-t", "--throttle",
help="Limits the download speed of xdcc-dl. "
"Append K,M or G for more convenient units")
args = parser.parse_args()

if args.quiet:
log_level = logging.ERROR
elif args.verbose:
log_level = logging.DEBUG
else:
log_level = logging.INFO
Logger.logging_level = log_level
try:
set_logging_level(args.quiet, args.verbose, args.debug)
set_throttle_value(args.throttle)

packs = XDCCPack.from_xdcc_message(
args.message, os.getcwd(), args.server
)

set_throttle_value(args.throttle)

if args.out is not None:
if len(packs) == 1:
packs[0].set_filename(args.out, True)
else:
for i, pack in enumerate(packs):
pack.set_filename(args.out + "-" + str(i).zfill(3), True)
prepare_packs(packs, args.out)

download_packs(packs)

except KeyboardInterrupt:
Logger().info("Thanks for using xdcc-dl!")
Logger().print("Thanks for using xdcc-dl!")
except DownloadIncomplete:
Logger().warning("Download incomplete.")
Logger().print("Thanks for using xdcc-dl!")


if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions bin/xdcc-search
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ def main():
help="The Search Engine to use")
args = parser.parse_args()

search_engine = SearchEngineType.resolve(args.search_engine)

try:
search_engine = SearchEngineType.resolve(args.search_engine)
results = search_engine.search(args.search_term)
for result in results:
print(result)
except ConnectionError:
print("Connection Error, could not conduct search")
except KeyboardInterrupt:
print("Thanks for using xdcc-dl!")


if __name__ == "__main__":
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
packages=find_packages(),
scripts=list(map(lambda x: os.path.join("bin", x), os.listdir("bin"))),
install_requires=[
"irc", "bs4", "requests", "cfscrape", "typing", "colorama"
"bs4",
"requests",
"cfscrape",
"typing",
"colorama",
"irc"
],
include_package_data=True,
zip_safe=False
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.3
3.1.0
40 changes: 40 additions & 0 deletions xdcc_dl/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
LICENSE"""

import sys
import logging
from typing import List, Optional
from xdcc_dl.logging import Logger
from xdcc_dl.entities.XDCCPack import XDCCPack
from xdcc_dl.xdcc.XDCCClient import XDCCCLient


Expand Down Expand Up @@ -46,3 +50,39 @@ def set_throttle_value(throttle_string: str):
except KeyError:
print("Invalid throttle value")
sys.exit(1)


def set_logging_level(quiet: bool, verbose: bool, debug: 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
:return: None
"""
if quiet:
Logger.logging_level = logging.ERROR
elif verbose:
Logger.logging_level = logging.INFO
elif debug:
Logger.logging_level = logging.DEBUG
else:
Logger.logging_level = logging.WARNING


def prepare_packs(packs: List[XDCCPack], location: Optional[str]):
"""
Prepares the output path of a list of packs based on a location string
:param location: The location at which to save the packs.
:param packs: The packs to prepare
:return: None
"""

if location is not None:
if len(packs) == 1:
packs[0].set_filename(location, True)
else:
# Generate unique names for each pack file
for i, pack in enumerate(packs):
pack.set_filename(location + "-" + str(i).zfill(3), True)
20 changes: 17 additions & 3 deletions xdcc_dl/logging/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
LICENSE"""

import logging
from typing import Optional
from datetime import datetime
from subprocess import check_output
from colorama import Fore, Back, Style
Expand All @@ -39,18 +40,19 @@ class Logger(object):
Keeps track of the last character to be printed
"""

def log(self, message: str, level: int, back: Back = Back.BLACK,
def log(self, message: str, level: Optional[int], back: Back = Back.BLACK,
fore: Fore = Fore.GREEN, end: str = "\n"):
"""
Logs a message at the specified logging level
:param message: The message to log
:param level: The level at which to log the message
:param level: The level at which to log the message.
If set as None, will always be printed.
:param back: The background color to print
:param fore: The foreground color to print
:param end: Characters to append to the string (Default newline)
:return: None
"""
if self.logging_level <= level:
if level is None or self.logging_level <= level:

if self.last_end == "\r" and end != "\r":
print()
Expand Down Expand Up @@ -112,3 +114,15 @@ def warning(self, message: str, back: Back = Back.YELLOW,
:return: None
"""
self.log(message, logging.WARNING, back, fore, end)

def print(self, message: str, back: Back = Back.BLACK,
fore: Fore = Fore.GREEN, end: str = "\n"):
"""
Prints a message
:param message: The message to print
:param back: The background color to print
:param fore: The foreground color to print
:param end: Characters to append to the string (Default newline)
:return: None
"""
self.log(message, None, back, fore, end)
Loading

0 comments on commit 89fc658

Please sign in to comment.