logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

learningonscreen.py (2774B)


  1. import functools
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. clean_html,
  7. extract_attributes,
  8. join_nonempty,
  9. parse_duration,
  10. unified_timestamp,
  11. )
  12. from ..utils.traversal import find_element, traverse_obj
  13. class LearningOnScreenIE(InfoExtractor):
  14. _VALID_URL = r'https?://learningonscreen\.ac\.uk/ondemand/index\.php/prog/(?P<id>\w+)'
  15. _TESTS = [{
  16. 'url': 'https://learningonscreen.ac.uk/ondemand/index.php/prog/005D81B2?bcast=22757013',
  17. 'info_dict': {
  18. 'id': '005D81B2',
  19. 'ext': 'mp4',
  20. 'title': 'Planet Earth',
  21. 'duration': 3600.0,
  22. 'timestamp': 1164567600.0,
  23. 'upload_date': '20061126',
  24. 'thumbnail': 'https://stream.learningonscreen.ac.uk/trilt-cover-images/005D81B2-Planet-Earth-2006-11-26T190000Z-BBC4.jpg',
  25. },
  26. }]
  27. def _real_initialize(self):
  28. if not self._get_cookies('https://learningonscreen.ac.uk/').get('PHPSESSID-BOB-LIVE'):
  29. self.raise_login_required(method='session_cookies')
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. details = traverse_obj(webpage, (
  34. {find_element(id='programme-details', html=True)}, {
  35. 'title': ({find_element(tag='h2')}, {clean_html}),
  36. 'timestamp': (
  37. {find_element(cls='broadcast-date')},
  38. {functools.partial(re.match, r'([^<]+)')}, 1, {unified_timestamp}),
  39. 'duration': (
  40. {find_element(cls='prog-running-time')}, {clean_html}, {parse_duration}),
  41. }))
  42. title = details.pop('title', None) or traverse_obj(webpage, (
  43. {find_element(id='add-to-existing-playlist', html=True)},
  44. {extract_attributes}, 'data-record-title', {clean_html}))
  45. entries = self._parse_html5_media_entries(
  46. 'https://stream.learningonscreen.ac.uk', webpage, video_id, m3u8_id='hls', mpd_id='dash',
  47. _headers={'Origin': 'https://learningonscreen.ac.uk', 'Referer': 'https://learningonscreen.ac.uk/'})
  48. if not entries:
  49. raise ExtractorError('No video found')
  50. if len(entries) > 1:
  51. duration = details.pop('duration', None)
  52. for idx, entry in enumerate(entries, start=1):
  53. entry.update(details)
  54. entry['id'] = join_nonempty(video_id, idx)
  55. entry['title'] = join_nonempty(title, idx)
  56. return self.playlist_result(entries, video_id, title, duration=duration)
  57. return {
  58. **entries[0],
  59. **details,
  60. 'id': video_id,
  61. 'title': title,
  62. }