min20.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class Min20IE(InfoExtractor):
  6. _VALID_URL = r'http://www\.20min\.ch/(videotv/\?vid=(?P<video_id>[0-9]+)|.+?-(?P<page_id>[0-9]+)$)'
  7. _TESTS = [{
  8. 'url': 'http://www.20min.ch/schweiz/news/story/-Wir-muessen-mutig-nach-vorne-schauen--22050469',
  9. 'md5': 'cd4cbb99b94130cff423e967cd275e5e',
  10. 'info_dict': {
  11. 'id': '22050469',
  12. 'ext': 'flv',
  13. 'title': '«Wir müssen mutig nach vorne schauen»',
  14. 'description': 'Kein Land sei innovativer als die Schweiz, sagte Johann Schneider-Ammann in seiner Neujahrsansprache. Das Land müsse aber seine Hausaufgaben machen.',
  15. 'thumbnail': 'http://www.20min.ch/images/content/2/2/0/22050469/10/teaserbreit.jpg'
  16. }
  17. }, {
  18. 'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
  19. 'md5': 'b52d6bc6ea6398e6a38f12cfd418149c',
  20. 'info_dict': {
  21. 'id': '469148',
  22. 'ext': 'flv',
  23. 'title': '85 000 Franken für 15 perfekte Minuten',
  24. 'description': 'Was die Besucher vom Silvesterzauber erwarten können. (Video: Alice Grosjean/Murat Temel)',
  25. 'thumbnail': 'http://thumbnails.20min-tv.ch/server063/469148/frame-72-469148.jpg'
  26. }
  27. }]
  28. # location of the flv videos, can't be extracted from the web page
  29. _BASE_URL = "http://flv-rr.20min-tv.ch/videos/"
  30. def _real_extract(self, url):
  31. mobj = re.match(self._VALID_URL, url)
  32. video_id = mobj.group('page_id')
  33. if video_id is None:
  34. # URL from the videoportal
  35. video_id = mobj.group('video_id')
  36. webpage = self._download_webpage(url, video_id)
  37. title = self._html_search_regex(r'<h1>.*<span>(.+?)</span></h1>', webpage, 'title')
  38. flash_id = self._search_regex(r"so\.addVariable\(\"file1\",\"([0-9]+)\"\)", webpage, 'flash_id')
  39. description = self._html_search_regex(r'<meta name="description" content="(.+?)" />', webpage, 'description')
  40. thumbnail = self._html_search_regex(r'<meta property="og:image" content="(.+?)" />', webpage, 'thumbnail')
  41. url = self._BASE_URL + flash_id + "m.flv"
  42. return {
  43. 'id': video_id,
  44. 'url': url,
  45. 'title': title,
  46. 'description': description,
  47. 'thumbnail': thumbnail
  48. }