~gwendal-lebihan-dev/torrent-search/2.0

« back to all changes in this revision

Viewing changes to plugins/000004_thepiratebay/plugin.py

  • Committer: glebihan
  • Date: 2012-07-30 17:45:23 UTC
  • Revision ID: svn-v4:9c901db2-479f-42dd-a8be-ba8dac6fe2ae::48
Moved back to python2
Added option to debug plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# along with Torrent Search.  If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
from TorrentSearch.SearchPlugin import SearchPlugin
22
 
import urllib.parse, time, datetime
 
22
import urllib, time, datetime
23
23
 
24
24
class ThePirateBaySearchPlugin(SearchPlugin):
25
25
    def _process_search(self, pattern, page_url = ""):
26
26
        if page_url == "":
27
 
            page_url = "http://thepiratebay.se/search/" + urllib.parse.quote_plus(pattern)
 
27
            page_url = "http://thepiratebay.se/search/" + urllib.quote_plus(pattern)
28
28
        
29
29
        resp, content = self._http_request(page_url)
30
30
        tree = self._parse_html(content)
51
51
        try:
52
52
            next_page_link = tree.lookup_children("div", id = "main-content")[0].next.lookup_children("img", alt = "Next")[0].getparent()
53
53
            page = next_page_link.href.split("/")[3]
54
 
            next_page_url = "http://thepiratebay.se/search/" + urllib.parse.quote_plus(pattern) + "/" + page
 
54
            next_page_url = "http://thepiratebay.se/search/" + urllib.quote_plus(pattern) + "/" + page
55
55
            if next_page_url != page_url:
56
56
                self._process_search(pattern, next_page_url)
57
57
        except:
123
123
 
124
124
        title_link = main_cell.lookup_children("a", **{"class": "detLink"})[0]
125
125
        title = title_link.getContent()
126
 
        details_page_url = urllib.parse.urljoin(page_url, title_link.href)
 
126
        details_page_url = urllib.basejoin(page_url, title_link.href)
127
127
 
128
128
        magnet_link = main_cell.lookup_children("a", 1)[1]
129
129
        magnet_url = magnet_link.href