Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Fixed some github issues

See merge request namibsun/python/xdcc-dl!3
  • Loading branch information
namboy94 committed Oct 3, 2019
2 parents 3604156 + ebac1fc commit 00c80df
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 129 deletions.
8 changes: 7 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stages:
- release

default:
image: namboy94/ci-docker-environment:0.5.0
image: namboy94/ci-docker-environment:0.8.0
before_script:
- echo "$SERVER_ACCESS_KEY" > ~/.ssh/id_rsa
- chmod 0600 ~/.ssh/id_rsa
Expand All @@ -27,6 +27,12 @@ stylecheck:
script:
- python-codestyle-check

type_check:
stage: test
tags: [docker]
script:
- python-static-type-check

unittest:
stage: test
tags: [docker]
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
V 3.2.0:
- Added notice that python 2 is no longer supported
- Fixed program hanging when no channels are joined
- Added timeout to xdcc-dl
- Improved xdcc-search to include server configuration
V 3.1.2:
- Integrated sentry
- Integrated mypy static type checking
V 3.1.1:
- Use docker in CI
V 3.1.0:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ An XDCC File downloader based on the [irclib](https://github.com/jaraco/irc) fra

Either install the program using `pip install xdcc-dl` or `python setup.py install`

Please not that python 2 is no longer supported, the project requires python 3 to run.

## Usage

### Message-based CLI
Expand Down
69 changes: 35 additions & 34 deletions bin/xdcc-browse
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ LICENSE"""

import argparse
from requests.exceptions import ConnectionError
from puffotter.init import cli_start, argparse_add_verbosity
from xdcc_dl import sentry_dsn
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
Expand All @@ -28,39 +30,14 @@ from xdcc_dl.xdcc import download_packs
from xdcc_dl.pack_search.SearchEngine import SearchEngineType


def main():
def main(args: argparse.Namespace):
"""
Conducts a XDCC pack search
Conducts a XDCC pack search with the option to immediately download any
found packs
:param args: The command line arguments
: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)

Expand All @@ -83,16 +60,40 @@ def main():
for pack in packs:
Logger().info("Downloading pack {}".format(pack))

download_packs(packs)
download_packs(packs, timeout=args.timeout)

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!")
raise KeyboardInterrupt()


if __name__ == "__main__":
main()
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("-t", "--throttle",
help="Limits the download speed of xdcc-dl. "
"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")
argparse_add_verbosity(parser)
cli_start(
main, parser,
sentry_dsn=sentry_dsn,
package_name="xdcc-dl",
exit_msg="Thanks for using xdcc-dl!"
)
61 changes: 30 additions & 31 deletions bin/xdcc-dl
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,40 @@ 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"""

# imports
import os
import argparse
from puffotter.init import cli_start, argparse_add_verbosity
from xdcc_dl import sentry_dsn
from xdcc_dl.xdcc import download_packs
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():
def main(args: argparse.Namespace):
"""
Starts the main method of the program
:param args: The command line arguments
:return: None
"""
try:
set_throttle_value(args.throttle)
set_logging_level(args.quiet, args.verbose, args.debug)

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

download_packs(packs, timeout=args.timeout)

except DownloadIncomplete:
Logger().warning("Download incomplete.")
raise KeyboardInterrupt()


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("message",
help="An XDCC Message. Supports ranges (1-100), "
Expand All @@ -48,34 +66,15 @@ def main():
"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)

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

download_packs(packs)

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()
parser.add_argument("--timeout", default=120, type=int,
help="Sets a timeout for starting the download")
argparse_add_verbosity(parser)
cli_start(
main, parser,
sentry_dsn=sentry_dsn,
package_name="xdcc-dl",
exit_msg="Thanks for using xdcc-dl!"
)
32 changes: 20 additions & 12 deletions bin/xdcc-search
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,40 @@ along with xdcc-dl. If not, see <http://www.gnu.org/licenses/>.
LICENSE"""

import argparse
from puffotter.init import cli_start
from requests.exceptions import ConnectionError
from xdcc_dl import sentry_dsn
from xdcc_dl.pack_search.SearchEngine import SearchEngineType


def main():
def main(args: argparse.Namespace):
"""
Conducts a XDCC pack search
:param args: The command line arguments
:return: None
"""
parser = argparse.ArgumentParser()
parser.add_argument("search_term", help="The term to search for")
parser.add_argument("search_engine",
choices=SearchEngineType.choices(True),
help="The Search Engine to use")
args = parser.parse_args()

try:
search_engine = SearchEngineType.resolve(args.search_engine)
results = search_engine.search(args.search_term)
for result in results:
print(result)
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 + ")"
print(message)
except ConnectionError:
print("Connection Error, could not conduct search")
except KeyboardInterrupt:
print("Thanks for using xdcc-dl!")
raise KeyboardInterrupt()


if __name__ == "__main__":
main()
parser = argparse.ArgumentParser()
parser.add_argument("search_term", help="The term to search for")
parser.add_argument("search_engine",
choices=SearchEngineType.choices(True),
help="The Search Engine to use")
cli_start(
main, parser,
sentry_dsn=sentry_dsn,
package_name="xdcc-dl",
exit_msg="Thanks for using xdcc-dl!"
)
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
"cfscrape",
"typing",
"colorama",
"irc"
"irc",
"puffotter",
"sentry-sdk"
],
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.1.1
3.2.0
6 changes: 6 additions & 0 deletions xdcc_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
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"""


sentry_dsn = "https://f20c5998b8fc46109e71fd9ddeebd64b@sentry.namibsun.net/7"
"""
The sentry DSN used for logging exceptions
"""
3 changes: 1 addition & 2 deletions xdcc_dl/entities/XDCCPack.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ def from_xdcc_message(cls, xdcc_message: str,
return packs

except ValueError:
packnumbers = xdcc_message.rsplit("#", 1)[1]
start, end = packnumbers.split("-")
start, end = xdcc_message.rsplit("#", 1)[1].split("-")

try:
step = int(end.split(";")[1])
Expand Down
20 changes: 5 additions & 15 deletions xdcc_dl/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
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
from xdcc_dl.xdcc.XDCCClient import XDCCClient
from puffotter.units import byte_string_to_byte_count


def set_throttle_value(throttle_string: str):
Expand All @@ -34,20 +35,9 @@ def set_throttle_value(throttle_string: str):
"""
try:
if throttle_string is not None:
multiplier = 1
units = {"k": 1000, "m": 1000000, "g": 1000000000}
throttle_num = ""
for i, char in enumerate(throttle_string):
if char.isdigit():
throttle_num += char
else:
if len(throttle_string) - 1 != i:
raise KeyError
else:
multiplier = units[char.lower()]
limit = multiplier * int(throttle_num)
XDCCCLient.download_limit = limit
except KeyError:
limit = byte_string_to_byte_count(throttle_string)
XDCCClient.download_limit = limit
except ValueError:
print("Invalid throttle value")
sys.exit(1)

Expand Down
6 changes: 3 additions & 3 deletions xdcc_dl/pack_search/SearchEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
LICENSE"""

from enum import Enum
from typing import List, Set
from typing import List, Set, Callable, Optional
from xdcc_dl.entities.XDCCPack import XDCCPack
from xdcc_dl.pack_search.procedures.nibl import find_nibl_packs
from xdcc_dl.pack_search.procedures.ixirc import find_ixirc_packs
Expand All @@ -30,7 +30,7 @@ class SearchEngine:
An XDCC Pack Search Engine
"""

def __init__(self, name: str, procedure: callable):
def __init__(self, name: str, procedure: Callable):
"""
Initializes the Search Engine
:param name: The name of the search engine
Expand Down Expand Up @@ -72,7 +72,7 @@ def choices(cls, lower: bool = True) -> Set[str]:
return set(choices)

@classmethod
def resolve(cls, name: str) -> SearchEngine or None:
def resolve(cls, name: str) -> Optional[SearchEngine]:
"""
Resolves a string identifier of a search engine and provides
the correct search engine
Expand Down
2 changes: 1 addition & 1 deletion xdcc_dl/pack_search/procedures/horriblesubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ def parse_result(result: str) -> Dict[str, str]:

else:
# Segment is a string
data[current_key] = segment
data[str(current_key)] = segment

return data
Loading

0 comments on commit 00c80df

Please sign in to comment.