Added Downloader pySmartDL (#504)

* fixed headers

Co-authored-by: Blatzar <46196380+Blatzar@users.noreply.github.com>
master
Arjix 2020-09-13 10:49:11 +03:00 committed by GitHub
parent bccf81c154
commit 80ed758b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 48 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import click
import click
import sys
import os
import importlib
@ -43,9 +43,9 @@ def cli(log_level):
Download or watch your favourite anime
"""
if not util.check_in_path('aria2c'):
raise RuntimeError("Aria2 is not in path. Please follow installation instructions: https://github.com/vn-ki/anime-downloader/wiki/Installation")
util.setup_logger(log_level)
# if not util.check_in_path('aria2c'):
# raise logger.ERROR("Aria2 is not in path. Please follow installation instructions: https://github.com/vn-ki/anime-downloader/wiki/Installation")
def main():
@ -55,5 +55,5 @@ def main():
if 'DEBUG' in sys.argv:
raise
click.echo(click.style('ERROR:', fg='black', bg='red') +
' '+click.style(str(e), fg='red'))
' ' + click.style(str(e), fg='red'))
sys.exit(1)

View File

@ -0,0 +1,29 @@
from anime_downloader.downloader.base_downloader import BaseDownloader
from pySmartDL import SmartDL
from pathlib import Path
import time
import sys
import os
class pySmartDL(BaseDownloader):
def _download(self):
path = Path(self.path)
headers = self.source.headers
if 'user-agent' not in headers:
headers['user-agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0"
# This allows backwards compatible while also working with
# PySmartDl as it only passes user agent if spelled "User-Agent"
headers['User-Agent'] = headers.pop('user-agent')
if self.source.referer:
headers['Referer'] = self.source.referer
url = self.source.stream_url
request_args = {'headers': headers}
dest = str(self.path) # str(path.parent.absolute())
obj = SmartDL(url, dest, request_args=request_args, progress_bar=True)
obj.start()

View File

@ -1,6 +1,6 @@
from anime_downloader.downloader.http_downloader import HTTPDownloader
from anime_downloader.downloader.external_downloader import ExternalDownloader
from anime_downloader.downloader.SmartDL import pySmartDL
def get_downloader(downloader):
"""get_downloader returns the proper downloader class
@ -9,4 +9,8 @@ def get_downloader(downloader):
"""
if downloader == 'http':
return HTTPDownloader
elif downloader == 'pySmartDL':
return pySmartDL
return ExternalDownloader

View File

@ -30,7 +30,7 @@ class BaseDownloader:
# Added Referer Header as kwik needd it.
headers = self.source.headers
if 'user-agent' not in headers:
headers['user-agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0",
headers['user-agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0"
if self.source.referer:
headers['referer'] = self.source.referer

View File

@ -11,6 +11,7 @@ session = session.get_session()
session = requests
logger = logging.getLogger(__name__)
class HTTPDownloader(BaseDownloader):
def _download(self):
logger.warning('Using internal downloader which might be slow. Use aria2 for full bandwidth.')
@ -28,7 +29,7 @@ class HTTPDownloader(BaseDownloader):
url = self.source.stream_url
headers = self.source.headers
if 'user-agent' not in headers:
headers['user-agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0",
headers['user-agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0"
if self.source.referer:
headers['Referer'] = self.source.referer
@ -59,7 +60,7 @@ class HTTPDownloader(BaseDownloader):
def _non_range_download(self):
url = self.source.stream_url
headers = {
'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0",
'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Gecko/20100101Firefox/56.0"
}
if self.source.referer:
headers['Referer'] = self.source.referer

View File

@ -3,11 +3,14 @@ from anime_downloader.sites.exceptions import NotFoundError
class BaseExtractor:
def __init__(self, url, quality=None, headers={}):
def __init__(self, url, quality=None, headers=None):
if not url.startswith('http'):
url = 'https://' + url
self.url = url
if headers is None:
headers = {}
# TODO: Maybe quality should be only delt with inside epiosde(?)
self.quality = quality

View File

@ -422,7 +422,7 @@ class AnimeEpisode:
else:
path = os.path.join(path, file_name)
Downloader = get_downloader('http')
Downloader = get_downloader('pySmartDL')
downloader = Downloader(self.source(),
path, force, range_size=range_size)

View File

@ -21,6 +21,7 @@ setup(
url='https://github.com/vn-ki/anime-downloader',
keywords=['anime', 'downloader', '9anime', 'download', 'kissanime'],
install_requires=[
'pySmartDL>=1.3.3',
'beautifulsoup4>=4.6.0',
'requests>=2.18.4',
'Click>=6.7',