add video title command

This commit is contained in:
Christophe Benz 2010-04-13 15:58:40 +02:00
commit 4d82163b41
6 changed files with 80 additions and 8 deletions

View file

@ -45,6 +45,10 @@ class YoutubeBackend(Backend, ICapVideoProvider):
def iter_page_urls(self, mozaic_url):
raise NotImplementedError()
@need_browser
def get_video_title(self, page_url):
return self.browser.get_video_title(page_url)
@need_browser
def get_video_url(self, page_url):
return self.browser.get_video_url(page_url)

View file

@ -1,7 +1,7 @@
# -*- 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
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
from weboob.tools.browser import Browser
from weboob.tools.parser import LxmlHtmlParser
from .pages import VideoPage
class YoutubeBrowser(Browser):
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):
result = self.openurl(page_url).read()
for _signature in re.finditer(self.regex, result):

View 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

View 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

View file

@ -21,11 +21,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from .cap import ICap
class ICapVideoProvider(ICap):
#def can_handle_url(self, url):
#raise NotImplementedError()
def iter_page_urls(self, mozaic_url):
raise NotImplementedError()
def get_video_title(self, page_url):
raise NotImplementedError()
def get_video_url(self, page_url):
raise NotImplementedError()

View file

@ -29,8 +29,12 @@ class Videoob(ConsoleApplication):
self.weboob.load_backends(ICapVideoProvider)
return self.process_command(*argv[1:])
@ConsoleApplication.command('Get video URL from page URL')
def command_video_url(self, page_url):
self.weboob.load_backends(ICapVideoProvider)
for name, backend in self.weboob.iter_backends():
@ConsoleApplication.command('Get video file URL from page URL')
def command_file_url(self, page_url):
for name, backend in self.weboob.iter_backends(ICapVideoProvider):
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)