- id = self._match_id(url)
- username, twid = re.match(r'([^/]+)/status/(\d+)', id).groups()
- name = username
- url = re.sub(r'https?://(m|mobile)\.', 'https://', url)
- webpage = self._download_webpage(url, 'tweet: ' + url)
- description = self._html_search_regex('<title>\s*(.+?)\s*</title>', webpage, 'title')
- title = description.replace('\n', ' ')
- splitdesc = re.match(r'^(.+?)\s*on Twitter:\s* "(.+?)"$', title)
- if splitdesc:
- name, title = splitdesc.groups()
- title = re.sub(r'\s*https?://[^ ]+', '', title) # strip 'https -_t.co_BJYgOjSeGA' junk from filenames
- card_id = self._search_regex(r'["\']/i/cards/tfw/v1/(\d+)', webpage, '/i/card/...')
+ mobj = re.match(self._VALID_URL, url)
+ user_id = mobj.group('user_id')
+ twid = mobj.group('id')
+
+ webpage = self._download_webpage(self._TEMPLATE_URL % (user_id, twid), twid)
+
+ username = remove_end(self._og_search_title(webpage), ' on Twitter')
+
+ title = self._og_search_description(webpage).strip('').replace('\n', ' ')
+
+ # strip 'https -_t.co_BJYgOjSeGA' junk from filenames
+ mobj = re.match(r'“(.*)\s+(http://[^ ]+)”', title)
+ title, short_url = mobj.groups()
+
+ card_id = self._search_regex(
+ r'["\']/i/cards/tfw/v1/(\d+)', webpage, 'twitter card url')