[weboob] [PATCH 3/3] [t411] get get_torrent_file() to work

Matthieu Weber mweber+weboob at free.fr
Wed Mar 9 18:02:26 CET 2016


Signed-off-by: Matthieu Weber <mweber+weboob at free.fr>
---
 modules/t411/browser.py        |  9 +++++----
 modules/t411/pages/index.py    |  2 --
 modules/t411/pages/torrents.py | 19 ++++++++++++-------
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/modules/t411/browser.py b/modules/t411/browser.py
index 918d594..92a827e 100644
--- a/modules/t411/browser.py
+++ b/modules/t411/browser.py
@@ -25,7 +25,7 @@ from weboob.browser.profiles import Wget
 from weboob.exceptions import BrowserIncorrectPassword
 
 from .pages.index import HomePage
-from .pages.torrents import TorrentPage, SearchPage
+from .pages.torrents import TorrentPage, SearchPage, DownloadPage
 
 
 __all__ = ['T411Browser']
@@ -39,13 +39,14 @@ class T411Browser(LoginBrowser):
     home = URL('$', HomePage)
     search = URL('torrents/search/\?search=(?P<pattern>.*)&order=seeders&type=desc',
                  SearchPage)
+    # Order matters here: 'torrents/[^&]*' would match '/torrents/download/\?id...' and
+    # TorrentPage would crash on the bencode data, so DownloadPage must be listed before
+    # TorrentPage
+    download = URL('/torrents/download/\?id=(?P<id>.*)', DownloadPage)
     torrent = URL('/torrents/details/\?id=(?P<id>.*)&r=1',
                   'torrents/[^&]*',
                   TorrentPage)
 
-    #def __init__(self, *args, **kwargs):
-    #    Browser.__init__(self, *args, **kwargs)
-
     def do_login(self):
         self.home.go()
         if not self.page.logged:
diff --git a/modules/t411/pages/index.py b/modules/t411/pages/index.py
index bce7701..ff38002 100644
--- a/modules/t411/pages/index.py
+++ b/modules/t411/pages/index.py
@@ -18,7 +18,6 @@
 # along with weboob. If not, see <http://www.gnu.org/licenses/>.
 
 
-#from .base import BasePage
 from weboob.browser.pages import HTMLPage
 
 
@@ -29,7 +28,6 @@ class HomePage(HTMLPage):
         form['password'] = password
         form.submit()
 
-
     @property
     def logged(self):
         return self.doc.xpath('//a[@class="logout"]')
diff --git a/modules/t411/pages/torrents.py b/modules/t411/pages/torrents.py
index 5965a68..51523de 100644
--- a/modules/t411/pages/torrents.py
+++ b/modules/t411/pages/torrents.py
@@ -25,7 +25,7 @@ from weboob.capabilities.torrent import Torrent
 from weboob.capabilities.base import NotLoaded, NotAvailable
 
 from weboob.browser.elements import ItemElement, ListElement, method
-from weboob.browser.pages import HTMLPage, LoggedPage
+from weboob.browser.pages import HTMLPage, LoggedPage, RawPage
 from weboob.browser.filters.standard import Regexp, CleanText, Type, Format
 from weboob.browser.filters.html import CleanHTML
 
@@ -45,19 +45,19 @@ class SearchPage(LoggedPage, HTMLPage):
             obj_leechers = CleanText('./td[9]') & Type(type=int)
             obj_description = NotLoaded
             obj_files = NotLoaded
-            obj_filename = Format('%s.torrent',CleanText('./td[2]/a/@title'))
+            obj_filename = Format('%s.torrent', CleanText('./td[2]/a/@title'))
             obj_magnet = NotAvailable
 
             def obj_url(self):
-                fullid = Regexp(CleanText('./td[3]/a/@href'),'/torrents/nfo/\?id=(.*)')(self)
-                downurl = 'https://www.t411.ch/torrents/download/?id=%s'%fullid
+                fullid = Regexp(CleanText('./td[3]/a/@href'), '/torrents/nfo/\?id=(.*)')(self)
+                downurl = 'https://www.t411.ch/torrents/download/?id=%s' % fullid
                 return downurl
 
             def obj_size(self):
                 rawsize = CleanText('./td[6]')(self)
                 nsize = float(rawsize.split()[0])
                 usize = rawsize.split()[-1].upper()
-                size = get_bytes_size(nsize,usize)
+                size = get_bytes_size(nsize, usize)
                 return size
 
 
@@ -78,15 +78,16 @@ class TorrentPage(LoggedPage, HTMLPage):
 
         def obj_url(self):
             fullid = CleanText('//input[@id="torrent-id"][1]/@value')(self)
-            downurl = 'https://www.t411.ch/torrents/download/?id=%s'%fullid
+            downurl = 'https://www.t411.ch/torrents/download/?id=%s' % fullid
             return downurl
 
         obj_filename = CleanText('//div[@class="accordion"]//tr[th="Torrent"]/td')
+
         def obj_size(self):
             rawsize = CleanText('//div[@class="accordion"]//tr[th="Taille totale"]/td')(self)
             nsize = float(rawsize.split()[0])
             usize = rawsize.split()[-1].upper()
-            size = get_bytes_size(nsize,usize)
+            size = get_bytes_size(nsize, usize)
             return size
 
         def obj_files(self):
@@ -99,3 +100,7 @@ class TorrentPage(LoggedPage, HTMLPage):
         obj_seeders = CleanText('//div[@class="details"]//td[@class="up"]') & Type(type=int)
         obj_leechers = CleanText('//div[@class="details"]//td[@class="down"]') & Type(type=int)
         obj_magnet = NotAvailable
+
+
+class DownloadPage(LoggedPage, RawPage):
+    pass
-- 
2.1.4




More information about the weboob mailing list