mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-05 02:32:52 +08:00
Initial commit for the new extractors module
This commit is contained in:
parent
951b9dfd94
commit
ee9f4f5320
7
test_extractor_module.py
Executable file
7
test_extractor_module.py
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
import youtube_dl.extractors as ex
|
||||
|
||||
print('Testing the new IEs module')
|
||||
print(ex.gen_extractors())
|
||||
print(ex.get_info_extractor('Test'))
|
||||
ex.get_info_extractor('Test2').test()
|
8
youtube_dl/extractors/Test2IE.py
Normal file
8
youtube_dl/extractors/Test2IE.py
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
# Is that actually needed?, if I comment it, it doesn't fail in python2.6 or python2.7
|
||||
#from __future__ import absolute_import
|
||||
|
||||
from .ie import *
|
||||
|
||||
class Test2IE(BaseIETest):
|
||||
IE_NAME = 'Test2'
|
8
youtube_dl/extractors/TestIE.py
Normal file
8
youtube_dl/extractors/TestIE.py
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
|
||||
class TestIE(object):
|
||||
IE_NAME = 'Test'
|
||||
@classmethod
|
||||
def test(cls):
|
||||
print("test class")
|
34
youtube_dl/extractors/__init__.py
Normal file
34
youtube_dl/extractors/__init__.py
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
# Here is where we add new extractors, the order is important.
|
||||
# You add the IE name without the IE suffix, i.e: for YoutubeIE you add 'Youtube'
|
||||
extractor_names = ['Test','Test2']
|
||||
|
||||
|
||||
extractor_classes = None
|
||||
|
||||
def gen_extractors():
|
||||
return [get_info_extractor(name)() for name in extractor_names]
|
||||
|
||||
def ie_fullname(IE_name):
|
||||
return '%sIE' % IE_name
|
||||
|
||||
def get_ieclass_from_module(IE_name):
|
||||
full_name = ie_fullname(IE_name)
|
||||
module = __import__(full_name,
|
||||
globals(),
|
||||
level = 1 # We want to use the relative import, only needed in Python 3
|
||||
)
|
||||
return getattr(module, full_name) # We get the IE class from the module object
|
||||
|
||||
def gen_extractor_classes():
|
||||
global extractor_classes
|
||||
# We save the results for later use, it may save us some time
|
||||
if extractor_classes is None:
|
||||
# We must keep 2.6 compatibility, so no dict comprehension
|
||||
extractor_classes = dict((ie_fullname(name), get_ieclass_from_module(name)) for name in extractor_names)
|
||||
return extractor_classes
|
||||
|
||||
def get_info_extractor(ie_name):
|
||||
"""Returns the info extractor class with the given ie_name"""
|
||||
return gen_extractor_classes()[ie_name+'IE']
|
8
youtube_dl/extractors/ie.py
Normal file
8
youtube_dl/extractors/ie.py
Normal file
@ -0,0 +1,8 @@
|
||||
# Here should go the real base InfoExtractor class and all the modules needed.
|
||||
|
||||
from ..utils import *
|
||||
|
||||
class BaseIETest(object):
|
||||
@classmethod
|
||||
def test(cls):
|
||||
print(cls.__name__ +' is a subclass of BaseIETest')
|
Loading…
Reference in New Issue
Block a user