youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

storyfire.py (5497B)


      1 # coding: utf-8
      2 from __future__ import unicode_literals
      3 
      4 import functools
      5 
      6 from .common import InfoExtractor
      7 from ..utils import (
      8     # HEADRequest,
      9     int_or_none,
     10     OnDemandPagedList,
     11     smuggle_url,
     12 )
     13 
     14 
     15 class StoryFireBaseIE(InfoExtractor):
     16     _VALID_URL_BASE = r'https?://(?:www\.)?storyfire\.com/'
     17 
     18     def _call_api(self, path, video_id, resource, query=None):
     19         return self._download_json(
     20             'https://storyfire.com/app/%s/%s' % (path, video_id), video_id,
     21             'Downloading %s JSON metadata' % resource, query=query)
     22 
     23     def _parse_video(self, video):
     24         title = video['title']
     25         vimeo_id = self._search_regex(
     26             r'https?://player\.vimeo\.com/external/(\d+)',
     27             video['vimeoVideoURL'], 'vimeo id')
     28 
     29         # video_url = self._request_webpage(
     30         #    HEADRequest(video['vimeoVideoURL']), video_id).geturl()
     31         # formats = []
     32         # for v_url, suffix in [(video_url, '_sep'), (video_url.replace('/sep/video/', '/video/'), '')]:
     33         #    formats.extend(self._extract_m3u8_formats(
     34         #        v_url, video_id, 'mp4', 'm3u8_native',
     35         #        m3u8_id='hls' + suffix, fatal=False))
     36         #    formats.extend(self._extract_mpd_formats(
     37         #        v_url.replace('.m3u8', '.mpd'), video_id,
     38         #        mpd_id='dash' + suffix, fatal=False))
     39         # self._sort_formats(formats)
     40 
     41         uploader_id = video.get('hostID')
     42 
     43         return {
     44             '_type': 'url_transparent',
     45             'id': vimeo_id,
     46             'title': title,
     47             'description': video.get('description'),
     48             'url': smuggle_url(
     49                 'https://player.vimeo.com/video/' + vimeo_id, {
     50                     'http_headers': {
     51                         'Referer': 'https://storyfire.com/',
     52                     }
     53                 }),
     54             # 'formats': formats,
     55             'thumbnail': video.get('storyImage'),
     56             'view_count': int_or_none(video.get('views')),
     57             'like_count': int_or_none(video.get('likesCount')),
     58             'comment_count': int_or_none(video.get('commentsCount')),
     59             'duration': int_or_none(video.get('videoDuration')),
     60             'timestamp': int_or_none(video.get('publishDate')),
     61             'uploader': video.get('username'),
     62             'uploader_id': uploader_id,
     63             'uploader_url': 'https://storyfire.com/user/%s/video' % uploader_id if uploader_id else None,
     64             'episode_number': int_or_none(video.get('episodeNumber') or video.get('episode_number')),
     65         }
     66 
     67 
     68 class StoryFireIE(StoryFireBaseIE):
     69     _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'video-details/(?P<id>[0-9a-f]{24})'
     70     _TEST = {
     71         'url': 'https://storyfire.com/video-details/5df1d132b6378700117f9181',
     72         'md5': 'caec54b9e4621186d6079c7ec100c1eb',
     73         'info_dict': {
     74             'id': '378954662',
     75             'ext': 'mp4',
     76             'title': 'Buzzfeed Teaches You About Memes',
     77             'uploader_id': 'ntZAJFECERSgqHSxzonV5K2E89s1',
     78             'timestamp': 1576129028,
     79             'description': 'md5:0b4e28021548e144bed69bb7539e62ea',
     80             'uploader': 'whang!',
     81             'upload_date': '20191212',
     82             'duration': 418,
     83             'view_count': int,
     84             'like_count': int,
     85             'comment_count': int,
     86         },
     87         'params': {
     88             'skip_download': True,
     89         },
     90         'expected_warnings': ['Unable to download JSON metadata']
     91     }
     92 
     93     def _real_extract(self, url):
     94         video_id = self._match_id(url)
     95         video = self._call_api(
     96             'generic/video-detail', video_id, 'video')['video']
     97         return self._parse_video(video)
     98 
     99 
    100 class StoryFireUserIE(StoryFireBaseIE):
    101     _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'user/(?P<id>[^/]+)/video'
    102     _TEST = {
    103         'url': 'https://storyfire.com/user/UQ986nFxmAWIgnkZQ0ftVhq4nOk2/video',
    104         'info_dict': {
    105             'id': 'UQ986nFxmAWIgnkZQ0ftVhq4nOk2',
    106         },
    107         'playlist_mincount': 151,
    108     }
    109     _PAGE_SIZE = 20
    110 
    111     def _fetch_page(self, user_id, page):
    112         videos = self._call_api(
    113             'publicVideos', user_id, 'page %d' % (page + 1), {
    114                 'skip': page * self._PAGE_SIZE,
    115             })['videos']
    116         for video in videos:
    117             yield self._parse_video(video)
    118 
    119     def _real_extract(self, url):
    120         user_id = self._match_id(url)
    121         entries = OnDemandPagedList(functools.partial(
    122             self._fetch_page, user_id), self._PAGE_SIZE)
    123         return self.playlist_result(entries, user_id)
    124 
    125 
    126 class StoryFireSeriesIE(StoryFireBaseIE):
    127     _VALID_URL = StoryFireBaseIE._VALID_URL_BASE + r'write/series/stories/(?P<id>[^/?&#]+)'
    128     _TESTS = [{
    129         'url': 'https://storyfire.com/write/series/stories/-Lq6MsuIHLODO6d2dDkr/',
    130         'info_dict': {
    131             'id': '-Lq6MsuIHLODO6d2dDkr',
    132         },
    133         'playlist_mincount': 13,
    134     }, {
    135         'url': 'https://storyfire.com/write/series/stories/the_mortal_one/',
    136         'info_dict': {
    137             'id': 'the_mortal_one',
    138         },
    139         'playlist_count': 0,
    140     }]
    141 
    142     def _extract_videos(self, stories):
    143         for story in stories.values():
    144             if story.get('hasVideo'):
    145                 yield self._parse_video(story)
    146 
    147     def _real_extract(self, url):
    148         series_id = self._match_id(url)
    149         stories = self._call_api(
    150             'seriesStories', series_id, 'series stories')
    151         return self.playlist_result(self._extract_videos(stories), series_id)