vgd.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import re
  2. from terroroftinytown.client import errors
  3. from terroroftinytown.services.isgd import IsgdService
  4. from terroroftinytown.services.rand import HashRandMixin
  5. from terroroftinytown.services.status import URLStatus
  6. from terroroftinytown.six.moves import html_parser
  7. class VgdService(IsgdService):
  8. def parse_blocked(self, response):
  9. try:
  10. return IsgdService.parse_blocked(self, response)
  11. except errors.UnexpectedNoResult:
  12. pass
  13. response.encoding = 'utf-8'
  14. match = re.search("<p>For reference and to help those fighting spam the original destination of this URL is given below \(we strongly recommend you don't visit it since it may damage your PC\): -<br />(.*)</p><h2>v\.gd</h2><p>v\.gd is a free service used to shorten long URLs\.", response.text)
  15. if not match:
  16. raise errors.UnexpectedNoResult("Could not find target URL in 'Link Disabled' page")
  17. url = match.group(1)
  18. url = html_parser.HTMLParser().unescape(url)
  19. if url == "":
  20. return (URLStatus.unavailable, None, None)
  21. return (URLStatus.ok, url, response.encoding)
  22. class Vgd6Service(HashRandMixin, VgdService):
  23. def get_shortcode_width(self):
  24. return 6