[weboob] [PATCH 1/1] modified: weboob/backends/bp/browser.py new file: weboob/backends/canalplus/__init__.py new file: weboob/backends/canalplus/backend.py new file: weboob/backends/canalplus/browser.py new file: weboob/backends/canalplus/pages/__init__.py new file: weboob/backends/canalplus/pages/initpage.py new file: weboob/backends/canalplus/pages/searchresultpage.py new file: weboob/backends/canalplus/pages/video.py new file: weboob/backends/canalplus/pages/videopage.py modified: weboob/tools/application/media_player.py modified: weboob/tools/parsers/lxmlparser.py

Nicolas Duhamel nicolas at jombi.fr
Mon Nov 8 22:51:45 CET 2010


 * bp de nouveau utilisable mais n'utilise pas encore BaseBrowser
 * Nouveau backend canalplus

 * J'ai du modifier media_player pour lire les videos avec mplayer mais je ne sais pas si ma modification
   pose des problemes avec d'autres lecteurs videos

Signed-off-by: Nicolas Duhamel <nicolas at jombi.fr>
---
 weboob/backends/bp/browser.py                      |    6 +-
 weboob/backends/canalplus/__init__.py              |   20 ++++++
 weboob/backends/canalplus/backend.py               |   55 +++++++++++++++
 weboob/backends/canalplus/browser.py               |   72 ++++++++++++++++++++
 weboob/backends/canalplus/pages/__init__.py        |   23 ++++++
 weboob/backends/canalplus/pages/initpage.py        |   40 +++++++++++
 .../backends/canalplus/pages/searchresultpage.py   |   33 +++++++++
 weboob/backends/canalplus/pages/video.py           |   28 ++++++++
 weboob/backends/canalplus/pages/videopage.py       |   42 +++++++++++
 weboob/tools/application/media_player.py           |    3 +-
 weboob/tools/parsers/lxmlparser.py                 |    2 +-
 11 files changed, 319 insertions(+), 5 deletions(-)
 create mode 100644 weboob/backends/canalplus/__init__.py
 create mode 100644 weboob/backends/canalplus/backend.py
 create mode 100644 weboob/backends/canalplus/browser.py
 create mode 100644 weboob/backends/canalplus/pages/__init__.py
 create mode 100644 weboob/backends/canalplus/pages/initpage.py
 create mode 100644 weboob/backends/canalplus/pages/searchresultpage.py
 create mode 100644 weboob/backends/canalplus/pages/video.py
 create mode 100644 weboob/backends/canalplus/pages/videopage.py

diff --git a/weboob/backends/bp/browser.py b/weboob/backends/bp/browser.py
index 433b1e9..6d85c50 100644
--- a/weboob/backends/bp/browser.py
+++ b/weboob/backends/bp/browser.py
@@ -45,7 +45,7 @@ ENCODING = 'utf-8'
 class BPbrowser(object):
 
 
-    def __init__(self, login, pwd):
+    def __init__(self, login, pwd, logger):
 
         self.is_logged = False
 
@@ -117,7 +117,7 @@ class BPbrowser(object):
             account.label = tp.text
             account.link_id = tp.get("href")
             account.id = compte.xpath("./td")[1].text
-            account.balance = ''.join( compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() )
+            account.balance = float(''.join( compte.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() ))
             self.Account_List.append(account)
 
         #Parse epargne
@@ -130,7 +130,7 @@ class BPbrowser(object):
             account.label = tp.text
             account.link_id = tp.get("href")
             account.id = epargne.xpath("./td")[1].text
-            account.balance = ''.join( epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() )
+            account.balance = float(''.join( epargne.xpath("./td/span")[0].text.replace('.','').replace(',','.').split() ) )
             self.Account_List.append(account)
 
         return self.Account_List
diff --git a/weboob/backends/canalplus/__init__.py b/weboob/backends/canalplus/__init__.py
new file mode 100644
index 0000000..f003981
--- /dev/null
+++ b/weboob/backends/canalplus/__init__.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Romain Bignon
+#
+# 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 .backend import CanalplusBackend
+
+__all__ = ['CanalplusBackend']
diff --git a/weboob/backends/canalplus/backend.py b/weboob/backends/canalplus/backend.py
new file mode 100644
index 0000000..d97de1b
--- /dev/null
+++ b/weboob/backends/canalplus/backend.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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 __future__ import with_statement
+
+from weboob.capabilities.video import ICapVideo
+from weboob.tools.backend import BaseBackend
+from weboob.tools.value import ValuesDict, Value
+
+from .browser import CanalplusBrowser
+from .pages import CanalplusVideo
+
+__all__ = ['CanalplusBackend']
+
+
+class CanalplusBackend(BaseBackend, ICapVideo):
+    NAME = 'canalplus'
+    MAINTAINER = 'Nicolas Duhamel'
+    EMAIL = 'nicolas at jombi.fr'
+    VERSION = '0.1'
+    DESCRIPTION = 'Canal plus french TV'
+    LICENSE = 'GPLv3'
+    CONFIG = ValuesDict(Value('quality', label='Quality of videos', choices=['hd', 'sd'], default='hd'))
+    BROWSER = CanalplusBrowser
+
+    def create_default_browser(self):
+        return self.create_browser(quality=self.config['quality'])
+
+    def iter_search_results(self, pattern=None, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False, max_results=None):
+        with self.browser:
+            return self.browser.iter_search_results(pattern)
+            
+    def get_video(self, _id):
+        with self.browser:
+            return self.browser.get_video(_id)
+            
+    def fill_video(self, video, fields):
+        return self.browser.get_video(CanalplusVideo.id2url(video.id))
+            
+    OBJECTS = {CanalplusVideo: fill_video}
diff --git a/weboob/backends/canalplus/browser.py b/weboob/backends/canalplus/browser.py
new file mode 100644
index 0000000..1d12dde
--- /dev/null
+++ b/weboob/backends/canalplus/browser.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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.
+
+import urllib
+
+from weboob.tools.browser import BaseBrowser
+from weboob.tools.browser.decorators import id2url
+
+from .pages import InitPage, SearchResultPage, CanalplusVideo, VideoPage
+
+import lxml.etree
+
+class XMLParser:
+     def parse(self, data, encoding=None):
+        if encoding is None:
+            parser = None
+        else:
+            parser = lxml.etree.XMLParser(encoding=encoding, strip_cdata=False)
+        return lxml.etree.XML(data.get_data(), parser)
+
+
+__all__ = ['CanalplusBrowser']
+
+
+class CanalplusBrowser(BaseBrowser):
+    DOMAIN = u'service.canal-plus.com'
+    ENCODING = 'utf-8'
+    PAGES = {r"http://service.canal-plus.com/video/rest/initPlayer/cplus/": InitPage,
+             r"http://service.canal-plus.com/video/rest/search/cplus/.*": SearchResultPage,
+             r"http://service.canal-plus.com/video/rest/getVideosLiees/cplus/(?P<id>.+)": VideoPage,
+    }
+
+    #We need lxml.etree.XMLParser for read CDATA
+    PARSER = XMLParser()
+    FORMATS = { 'sd': 'BAS_DEBIT',
+                'hd': 'HD'
+                }
+    
+    def __init__(self, quality, *args, **kwargs):
+        BaseBrowser.__init__(self, parser= self.PARSER, *args, **kwargs)
+        if quality in self.FORMATS:
+            self.quality = self.FORMATS[quality]
+        else:
+			self.quality = 'HD'
+
+    def home(self):
+        self.location("http://service.canal-plus.com/video/rest/initPlayer/cplus/")
+        
+    def iter_search_results(self, pattern):
+        self.location("http://service.canal-plus.com/video/rest/search/cplus/" + urllib.quote_plus(pattern) )
+        return self.page.iter_results()
+    
+    @id2url(CanalplusVideo.id2url)
+    def get_video(self, url, video=None):
+        self.location(url)
+        return self.page.get_video(video, self.quality)
+    
+
diff --git a/weboob/backends/canalplus/pages/__init__.py b/weboob/backends/canalplus/pages/__init__.py
new file mode 100644
index 0000000..7c1ad00
--- /dev/null
+++ b/weboob/backends/canalplus/pages/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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 .initpage import InitPage
+from .searchresultpage import SearchResultPage
+from .video import CanalplusVideo
+from .videopage import VideoPage
+
+__all__ = ['InitPage', 'SearchResultPage', 'VideoPage',  'CanalplusVideo']
diff --git a/weboob/backends/canalplus/pages/initpage.py b/weboob/backends/canalplus/pages/initpage.py
new file mode 100644
index 0000000..847fb25
--- /dev/null
+++ b/weboob/backends/canalplus/pages/initpage.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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
+
+__all__ = ['InitPage']
+
+class InitPage(BasePage):
+	def on_loaded(self):
+		channels = []
+		### Parse liste des channels
+		for elem in self.document[2].getchildren():
+			channel = {}
+			for e in elem.getchildren():
+				subchannels = []
+				if e.tag == "NOM":
+					channel['nom'] = e.text
+				elif e.tag == "SELECTIONS":
+			
+					for select in e:
+						subchannel = {}
+						subchannel['id'] = select[0].text
+						subchannel['nom'] = select[1].text
+						subchannels.append(subchannel)
+			channel['subchannels'] = subchannels
+			channels.append(channel)
diff --git a/weboob/backends/canalplus/pages/searchresultpage.py b/weboob/backends/canalplus/pages/searchresultpage.py
new file mode 100644
index 0000000..374ff57
--- /dev/null
+++ b/weboob/backends/canalplus/pages/searchresultpage.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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
+from .video import CanalplusVideo
+
+
+__all__ = ['SearchResultPage']
+
+class SearchResultPage(BasePage):
+	def iter_results(self):
+		for vid in self.document.getchildren():
+			#id
+			_id = vid[0].text
+			#Titre
+			titre = vid[2][9][0].text
+			#Sous titre
+			titre = titre + " " + vid[2][9][1].text
+			yield CanalplusVideo(_id, title=titre)
diff --git a/weboob/backends/canalplus/pages/video.py b/weboob/backends/canalplus/pages/video.py
new file mode 100644
index 0000000..4f54fce
--- /dev/null
+++ b/weboob/backends/canalplus/pages/video.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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.capabilities.video import BaseVideo
+
+
+__all__ = ['CanalplusVideo']
+
+
+class CanalplusVideo(BaseVideo):
+    @classmethod
+    def id2url(cls, _id):
+        return 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s' % _id
diff --git a/weboob/backends/canalplus/pages/videopage.py b/weboob/backends/canalplus/pages/videopage.py
new file mode 100644
index 0000000..d45cec3
--- /dev/null
+++ b/weboob/backends/canalplus/pages/videopage.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+
+# Copyright(C) 2010  Nicolas Duhamel
+#
+# 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
+from .video import CanalplusVideo
+__all__ = ['VideoPage']
+
+class VideoPage(BasePage):
+    def on_loaded(self):
+        pass
+        
+    def get_video(self, video, quality):
+        if not video:
+            video = CanalplusVideo(self.group_dict['id'])
+        print quality
+        print video.id
+        for vid in self.document.getchildren():
+            url = None
+            lastest = None
+            for format in vid[5][1].getchildren():
+                if format.tag == quality:
+                   url = format.text
+                if format.text:
+                    lastest = format
+            if url == None:
+                url = lastest.text
+            video.url = url
+            return video
diff --git a/weboob/tools/application/media_player.py b/weboob/tools/application/media_player.py
index d095b3c..9f2ac97 100644
--- a/weboob/tools/application/media_player.py
+++ b/weboob/tools/application/media_player.py
@@ -90,7 +90,8 @@ class MediaPlayer():
             logging.warning('Your media object does not have a "swf_player" attribute. SWF verification will be '
                             'disabled and may prevent correct media playback.')
 
-            rtmp = 'rtmpdump -r %s' % media_url
+            #rtmp = 'rtmpdump -r %s' % media_url
+            return self._play_default(media)
 
         rtmp += ' --quiet'
 
diff --git a/weboob/tools/parsers/lxmlparser.py b/weboob/tools/parsers/lxmlparser.py
index 34ffaee..484395c 100644
--- a/weboob/tools/parsers/lxmlparser.py
+++ b/weboob/tools/parsers/lxmlparser.py
@@ -76,7 +76,7 @@ class LxmlHtmlParser(IParser):
         if encoding is None:
             parser = None
         else:
-            parser = lxml.html.HTMLParser(encoding=encoding)
+            parser = lxml.html.HTMLParser(encoding=encoding, strip_cdata=False)
         return lxml.html.parse(data, parser)
 
     def tostring(self, element):
-- 
1.7.1




More information about the weboob mailing list