From ee9f4f5320802d2f5cdfb23baea5dee28da127a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Wed, 5 Jun 2013 10:33:13 +0200 Subject: [PATCH] Initial commit for the new extractors module --- test_extractor_module.py | 7 +++++++ youtube_dl/extractors/Test2IE.py | 8 ++++++++ youtube_dl/extractors/TestIE.py | 8 ++++++++ youtube_dl/extractors/__init__.py | 34 +++++++++++++++++++++++++++++++ youtube_dl/extractors/ie.py | 8 ++++++++ 5 files changed, 65 insertions(+) create mode 100755 test_extractor_module.py create mode 100644 youtube_dl/extractors/Test2IE.py create mode 100644 youtube_dl/extractors/TestIE.py create mode 100644 youtube_dl/extractors/__init__.py create mode 100644 youtube_dl/extractors/ie.py diff --git a/test_extractor_module.py b/test_extractor_module.py new file mode 100755 index 000000000..2742b2ae3 --- /dev/null +++ b/test_extractor_module.py @@ -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() diff --git a/youtube_dl/extractors/Test2IE.py b/youtube_dl/extractors/Test2IE.py new file mode 100644 index 000000000..3f1cef5d6 --- /dev/null +++ b/youtube_dl/extractors/Test2IE.py @@ -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' diff --git a/youtube_dl/extractors/TestIE.py b/youtube_dl/extractors/TestIE.py new file mode 100644 index 000000000..6c870a123 --- /dev/null +++ b/youtube_dl/extractors/TestIE.py @@ -0,0 +1,8 @@ + + + +class TestIE(object): + IE_NAME = 'Test' + @classmethod + def test(cls): + print("test class") diff --git a/youtube_dl/extractors/__init__.py b/youtube_dl/extractors/__init__.py new file mode 100644 index 000000000..a154cbf7a --- /dev/null +++ b/youtube_dl/extractors/__init__.py @@ -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'] diff --git a/youtube_dl/extractors/ie.py b/youtube_dl/extractors/ie.py new file mode 100644 index 000000000..f8bddea83 --- /dev/null +++ b/youtube_dl/extractors/ie.py @@ -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')