mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-27 13:54:14 +09:00
refactoring code and fix bugs
This commit is contained in:
parent
90ed89d2d4
commit
f2473ff30f
@ -88,6 +88,15 @@ class FakeYDL(YoutubeDL):
|
|||||||
old_report_warning(message)
|
old_report_warning(message)
|
||||||
self.report_warning = types.MethodType(report_warning, self)
|
self.report_warning = types.MethodType(report_warning, self)
|
||||||
|
|
||||||
|
class FakeLogger(object):
|
||||||
|
def debug(self, msg):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def warning(self, msg):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def error(self, msg):
|
||||||
|
pass
|
||||||
|
|
||||||
def gettestcases(include_onlymatching=False):
|
def gettestcases(include_onlymatching=False):
|
||||||
for ie in youtube_dl.extractor.gen_extractors():
|
for ie in youtube_dl.extractor.gen_extractors():
|
||||||
|
@ -9,7 +9,7 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from test.helper import http_server_port, try_rm
|
from test.helper import FakeLogger, http_server_port, try_rm
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from youtube_dl.compat import compat_http_server
|
from youtube_dl.compat import compat_http_server
|
||||||
from youtube_dl.downloader.http import HttpFD
|
from youtube_dl.downloader.http import HttpFD
|
||||||
@ -66,17 +66,6 @@ class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
|
|||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
class FakeLogger(object):
|
|
||||||
def debug(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def warning(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def error(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestHttpFD(unittest.TestCase):
|
class TestHttpFD(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.httpd = compat_http_server.HTTPServer(
|
self.httpd = compat_http_server.HTTPServer(
|
||||||
|
@ -10,10 +10,11 @@ import subprocess
|
|||||||
import unittest
|
import unittest
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from test.helper import http_server_port, try_rm
|
from test.helper import FakeLogger, http_server_port, try_rm
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from youtube_dl.compat import compat_http_server
|
from youtube_dl.compat import compat_http_server
|
||||||
from youtube_dl.utils import encodeFilename
|
from youtube_dl.utils import encodeFilename
|
||||||
|
from youtube_dl.downloader.external import Aria2pFD
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -64,17 +65,6 @@ class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
|
|||||||
assert False, 'unrecognised server path'
|
assert False, 'unrecognised server path'
|
||||||
|
|
||||||
|
|
||||||
class FakeLogger(object):
|
|
||||||
def debug(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def warning(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def error(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(Aria2pFD.available(), 'aria2p module not found')
|
@unittest.skipUnless(Aria2pFD.available(), 'aria2p module not found')
|
||||||
class TestAria2pFD(unittest.TestCase):
|
class TestAria2pFD(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -86,22 +76,21 @@ class TestAria2pFD(unittest.TestCase):
|
|||||||
self.server_thread.start()
|
self.server_thread.start()
|
||||||
|
|
||||||
def download(self, params, ep):
|
def download(self, params, ep):
|
||||||
try:
|
with subprocess.Popen(
|
||||||
with subprocess.Popen(
|
['aria2c', '--enable-rpc'],
|
||||||
['aria2c', '--enable-rpc'],
|
stdout=subprocess.DEVNULL,
|
||||||
stdout=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL
|
||||||
stderr=subprocess.DEVNULL
|
) as process:
|
||||||
) as process:
|
if not process.poll():
|
||||||
if not process.poll():
|
filename = 'testfile.mp4'
|
||||||
filename = 'testfile.mp4'
|
params['logger'] = FakeLogger()
|
||||||
params['logger'] = FakeLogger()
|
params['outtmpl'] = filename
|
||||||
params['outtmpl'] = filename
|
ydl = YoutubeDL(params)
|
||||||
ydl = YoutubeDL(params)
|
try_rm(encodeFilename(filename))
|
||||||
try_rm(encodeFilename(filename))
|
self.assertEqual(ydl.download(['http://127.0.0.1:%d/%s' % (self.port, ep)]), 0)
|
||||||
self.assertEqual(ydl.download(['http://127.0.0.1:%d/%s' % (self.port, ep)]), 0)
|
self.assertEqual(os.path.getsize(encodeFilename(filename)), TEST_SIZE)
|
||||||
self.assertEqual(os.path.getsize(encodeFilename(filename)), TEST_SIZE)
|
try_rm(encodeFilename(filename))
|
||||||
try_rm(encodeFilename(filename))
|
process.kill()
|
||||||
process.kill()
|
|
||||||
|
|
||||||
def download_all(self, params):
|
def download_all(self, params):
|
||||||
for ep in ('regular', 'no-content-length', 'no-range', 'no-range-no-content-length'):
|
for ep in ('regular', 'no-content-length', 'no-range', 'no-range-no-content-length'):
|
||||||
|
@ -8,7 +8,7 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
from test.helper import http_server_port
|
from test.helper import http_server_port, FakeLogger
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
from youtube_dl.compat import compat_http_server, compat_urllib_request
|
from youtube_dl.compat import compat_http_server, compat_urllib_request
|
||||||
import ssl
|
import ssl
|
||||||
@ -52,17 +52,6 @@ class HTTPTestRequestHandler(compat_http_server.BaseHTTPRequestHandler):
|
|||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
class FakeLogger(object):
|
|
||||||
def debug(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def warning(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def error(self, msg):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestHTTP(unittest.TestCase):
|
class TestHTTP(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.httpd = compat_http_server.HTTPServer(
|
self.httpd = compat_http_server.HTTPServer(
|
||||||
|
@ -221,7 +221,7 @@ class Aria2pFD(ExternalFD):
|
|||||||
|
|
||||||
def _call_downloader(self, tmpfilename, info_dict):
|
def _call_downloader(self, tmpfilename, info_dict):
|
||||||
aria2 = self.aria2p.API(
|
aria2 = self.aria2p.API(
|
||||||
aria2p.Client(
|
self.aria2p.Client(
|
||||||
host='http://localhost',
|
host='http://localhost',
|
||||||
port=6800,
|
port=6800,
|
||||||
secret=''
|
secret=''
|
||||||
@ -235,11 +235,11 @@ class Aria2pFD(ExternalFD):
|
|||||||
}
|
}
|
||||||
download_dir = os.path.dirname(tmpfilename)
|
download_dir = os.path.dirname(tmpfilename)
|
||||||
if download_dir:
|
if download_dir:
|
||||||
options["dir"] = download_dir
|
options['dir'] = download_dir
|
||||||
else:
|
else:
|
||||||
options["dir"] = os.path.abspath('.')
|
options['dir'] = os.path.abspath('.')
|
||||||
options["out"] = os.path.basename(tmpfilename)
|
options['out'] = os.path.basename(tmpfilename)
|
||||||
options["header"] = []
|
options['header'] = []
|
||||||
for key, val in info_dict['http_headers'].items():
|
for key, val in info_dict['http_headers'].items():
|
||||||
options['header'].append('{0}: {1}'.format(key, val))
|
options['header'].append('{0}: {1}'.format(key, val))
|
||||||
download = aria2.add_uris([info_dict['url']], options)
|
download = aria2.add_uris([info_dict['url']], options)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user