Added Downloader pySmartDL (#504)
* fixed headers Co-authored-by: Blatzar <46196380+Blatzar@users.noreply.github.com>master
parent
bccf81c154
commit
80ed758b89
|
@ -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)
|
||||
|
|
|
@ -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()
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue