Friendlier paths in canalplus

Lowercase, replace some separators.
This shows the point of having a path and a title!
Also try to fix the title if it is all uppercase.
This commit is contained in:
Laurent Bachelier 2012-03-10 23:40:16 +01:00
commit 5578618b06
2 changed files with 14 additions and 6 deletions

View file

@ -18,6 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime from datetime import datetime
import re
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
from weboob.capabilities.collection import Collection from weboob.capabilities.collection import Collection
@ -38,16 +39,23 @@ class ChannelsPage(BasePage):
for elem in self.document[2].getchildren(): for elem in self.document[2].getchildren():
for e in elem.getchildren(): for e in elem.getchildren():
if e.tag == "NOM": if e.tag == "NOM":
name = unicode(e.text.strip()) fid, name = self._clean_name(e.text)
channels.append(Collection([name])) channels.append(Collection([fid], name))
elif e.tag == "SELECTIONS": elif e.tag == "SELECTIONS":
for select in e: for select in e:
subname = unicode(select[1].text.strip()) sub_fid, subname = self._clean_name(select[1].text)
sub = Collection([name, subname]) sub = Collection([fid, sub_fid], subname)
sub._link_id = select[0].text sub._link_id = select[0].text
channels.append(sub) channels.append(sub)
return channels return channels
def _clean_name(self, name):
name = unicode(name.strip())
if name == name.upper():
name = name.capitalize()
friendly_id = re.sub(ur"['/_ \(\)\-\+]+", u'-', name).strip(u'-').lower()
return friendly_id, name
class VideoPage(BasePage): class VideoPage(BasePage):
def parse_video(self, el, video=None, quality=None): def parse_video(self, el, video=None, quality=None):

View file

@ -25,7 +25,7 @@ class CanalPlusTest(BackendTest):
BACKEND = 'canalplus' BACKEND = 'canalplus'
def test_canalplus(self): def test_canalplus(self):
l = list(self.backend.search_videos('guignol')) l = list(self.backend.search_videos(u'guignol'))
self.assertTrue(len(l) > 0) self.assertTrue(len(l) > 0)
v = l[0] v = l[0]
self.backend.fillobj(v, ('url',)) self.backend.fillobj(v, ('url',))
@ -35,5 +35,5 @@ class CanalPlusTest(BackendTest):
l = list(self.backend.iter_resources((BaseVideo, ), [])) l = list(self.backend.iter_resources((BaseVideo, ), []))
self.assertTrue(len(l) > 0) self.assertTrue(len(l) > 0)
l = list(self.backend.iter_resources((BaseVideo, ), ['SPORT'])) l = list(self.backend.iter_resources((BaseVideo, ), [u'sport']))
self.assertTrue(len(l) > 0) self.assertTrue(len(l) > 0)