add video title command
This commit is contained in:
parent
da612c58c4
commit
4d82163b41
6 changed files with 80 additions and 8 deletions
|
|
@ -45,6 +45,10 @@ class YoutubeBackend(Backend, ICapVideoProvider):
|
||||||
def iter_page_urls(self, mozaic_url):
|
def iter_page_urls(self, mozaic_url):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@need_browser
|
||||||
|
def get_video_title(self, page_url):
|
||||||
|
return self.browser.get_video_title(page_url)
|
||||||
|
|
||||||
@need_browser
|
@need_browser
|
||||||
def get_video_url(self, page_url):
|
def get_video_url(self, page_url):
|
||||||
return self.browser.get_video_url(page_url)
|
return self.browser.get_video_url(page_url)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright(C) 2009-2010 Christophe Benz
|
Copyright(C) 2010 Christophe Benz
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -21,9 +21,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from weboob.tools.browser import Browser
|
from weboob.tools.browser import Browser
|
||||||
|
from weboob.tools.parser import LxmlHtmlParser
|
||||||
|
|
||||||
|
from .pages import VideoPage
|
||||||
|
|
||||||
class YoutubeBrowser(Browser):
|
class YoutubeBrowser(Browser):
|
||||||
regex = re.compile(r'&t=([^ ,&]*)')
|
regex = re.compile(r'&t=([^ ,&]*)')
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs['parser'] = LxmlHtmlParser
|
||||||
|
self.PAGES = {r'http://.*\.youtube\.com/watch\?v=(.+)': VideoPage}
|
||||||
|
Browser.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_video_title(self, page_url):
|
||||||
|
self.location(page_url)
|
||||||
|
return self.page.title
|
||||||
|
|
||||||
def get_video_url(self, page_url):
|
def get_video_url(self, page_url):
|
||||||
result = self.openurl(page_url).read()
|
result = self.openurl(page_url).read()
|
||||||
for _signature in re.finditer(self.regex, result):
|
for _signature in re.finditer(self.regex, result):
|
||||||
|
|
|
||||||
21
weboob/backends/youtube/pages/__init__.py
Normal file
21
weboob/backends/youtube/pages/__init__.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright(C) 2010 Christophe Benz
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, version 3 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .video import VideoPage
|
||||||
30
weboob/backends/youtube/pages/video.py
Normal file
30
weboob/backends/youtube/pages/video.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Copyright(C) 2010 Christophe Benz
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, version 3 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from weboob.tools.browser import BasePage
|
||||||
|
|
||||||
|
class VideoPage(BasePage):
|
||||||
|
def loaded(self):
|
||||||
|
found = self.document.getroot().cssselect('meta[name=title]')
|
||||||
|
if found:
|
||||||
|
content = found[0].attrib['content']
|
||||||
|
self.title = unicode(content).strip()
|
||||||
|
else:
|
||||||
|
self.title = None
|
||||||
|
|
@ -21,11 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
from .cap import ICap
|
from .cap import ICap
|
||||||
|
|
||||||
class ICapVideoProvider(ICap):
|
class ICapVideoProvider(ICap):
|
||||||
#def can_handle_url(self, url):
|
|
||||||
#raise NotImplementedError()
|
|
||||||
|
|
||||||
def iter_page_urls(self, mozaic_url):
|
def iter_page_urls(self, mozaic_url):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def get_video_title(self, page_url):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def get_video_url(self, page_url):
|
def get_video_url(self, page_url):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,12 @@ class Videoob(ConsoleApplication):
|
||||||
self.weboob.load_backends(ICapVideoProvider)
|
self.weboob.load_backends(ICapVideoProvider)
|
||||||
return self.process_command(*argv[1:])
|
return self.process_command(*argv[1:])
|
||||||
|
|
||||||
@ConsoleApplication.command('Get video URL from page URL')
|
@ConsoleApplication.command('Get video file URL from page URL')
|
||||||
def command_video_url(self, page_url):
|
def command_file_url(self, page_url):
|
||||||
self.weboob.load_backends(ICapVideoProvider)
|
for name, backend in self.weboob.iter_backends(ICapVideoProvider):
|
||||||
for name, backend in self.weboob.iter_backends():
|
|
||||||
print backend.get_video_url(page_url)
|
print backend.get_video_url(page_url)
|
||||||
|
|
||||||
|
@ConsoleApplication.command('Get video title from page URL')
|
||||||
|
def command_title(self, page_url):
|
||||||
|
for name, backend in self.weboob.iter_backends(ICapVideoProvider):
|
||||||
|
print backend.get_video_title(page_url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue