]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[flipagram] Add extractor
authorDéstin Reed <trox1972@users.noreply.github.com>
Sat, 25 Jun 2016 17:01:47 +0000 (19:01 +0200)
committerSergey M․ <dstftw@gmail.com>
Fri, 8 Jul 2016 20:23:32 +0000 (03:23 +0700)
youtube_dl/extractor/common.py
youtube_dl/extractor/extractors.py
youtube_dl/extractor/flipagram.py [new file with mode: 0644]

index be2b6ff6678d6accf8ddbeafbc1436f3913b1061..b5fce5de21972f75253c0ae4c3352e4f0775da1f 100644 (file)
@@ -837,6 +837,13 @@ class InfoExtractor(object):
                     'title': unescapeHTML(json_ld.get('headline')),
                     'description': unescapeHTML(json_ld.get('articleBody')),
                 })
+            elif item_type == 'VideoObject':
+                info.update({
+                    'title': unescapeHTML(json_ld.get('name')),
+                    'description': unescapeHTML(json_ld.get('description')),
+                    'upload_date': unified_strdate(json_ld.get('upload_date')),
+                    'url': unescapeHTML(json_ld.get('contentUrl')),
+                })
         return dict((k, v) for k, v in info.items() if v is not None)
 
     @staticmethod
index 12cc1b5f7e9ce90109f9d950aeaa06ea6930368b..9f70ce75265d02e4cd2a6f2bb4b6b1ce8231d1f6 100644 (file)
@@ -256,6 +256,7 @@ from .fivemin import FiveMinIE
 from .fivetv import FiveTVIE
 from .fktv import FKTVIE
 from .flickr import FlickrIE
+from .flipagram import FlipagramIE
 from .folketinget import FolketingetIE
 from .footyroom import FootyRoomIE
 from .formula1 import Formula1IE
diff --git a/youtube_dl/extractor/flipagram.py b/youtube_dl/extractor/flipagram.py
new file mode 100644 (file)
index 0000000..7143126
--- /dev/null
@@ -0,0 +1,103 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+from .common import InfoExtractor
+
+from ..utils import (
+    int_or_none,
+    parse_iso8601,
+    unified_strdate,
+    unified_timestamp,
+)
+
+
+class FlipagramIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?flipagram\.com/f/(?P<id>[^/?_]+)'
+    _TESTS = [{
+        'url': 'https://flipagram.com/f/myrWjW9RJw',
+        'md5': '541988fb6c4c7c375215ea22a4a21841',
+        'info_dict': {
+            'id': 'myrWjW9RJw',
+            'title': 'Flipagram by crystaldolce featuring King and Lionheart by Of Monsters and Men',
+            'description': 'Herbie\'s first bannana🍌🐢🍌.  #animals #pets #reptile #tortoise #sulcata #tort #justatreat #snacktime #bannanas #rescuepets  #ofmonstersandmen  @animals',
+            'ext': 'mp4',
+            'uploader': 'Crystal Dolce',
+            'creator': 'Crystal Dolce',
+            'uploader_id': 'crystaldolce',
+        }
+    }, {
+        'url': 'https://flipagram.com/f/nyvTSJMKId',
+        'only_matching': True,
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+        webpage = self._download_webpage(url, video_id)
+
+        self.report_extraction(video_id)
+        user_data = self._parse_json(self._search_regex(r'window.reactH2O\s*=\s*({.+});', webpage, 'user data'), video_id)
+        content_data = self._search_json_ld(webpage, video_id)
+
+        flipagram = user_data.get('flipagram', {})
+        counts = flipagram.get('counts', {})
+        user = flipagram.get('user', {})
+        video = flipagram.get('video', {})
+
+        thumbnails = []
+        for cover in flipagram.get('covers', []):
+            if not cover.get('url'):
+                continue
+            thumbnails.append({
+                'url': self._proto_relative_url(cover.get('url')),
+                'width': int_or_none(cover.get('width')),
+                'height': int_or_none(cover.get('height')),
+            })
+
+        # Note that this only retrieves comments that are initally loaded.
+        # For videos with large amounts of comments, most won't be retrieved.
+        comments = []
+        for comment in user_data.get('comments', {}).get(video_id, {}).get('items', []):
+            text = comment.get('comment', [])
+            comments.append({
+                'author': comment.get('user', {}).get('name'),
+                'author_id': comment.get('user', {}).get('username'),
+                'id': comment.get('id'),
+                'text': text[0] if text else '',
+                'timestamp': unified_timestamp(comment.get('created', '')),
+            })
+
+        tags = [tag for item in flipagram['story'][1:] for tag in item]
+
+        formats = []
+        if flipagram.get('music', {}).get('track', {}).get('previewUrl', {}):
+            formats.append({
+                'url': flipagram.get('music').get('track').get('previewUrl'),
+                'ext': 'm4a',
+                'vcodec': 'none',
+            })
+
+        formats.append({
+            'url': video.get('url'),
+            'ext': 'mp4',
+            'width': int_or_none(video.get('width')),
+            'height': int_or_none(video.get('height')),
+            'filesize': int_or_none(video.get('size')),
+        })
+
+        return {
+            'id': video_id,
+            'title': content_data['title'],
+            'formats': formats,
+            'thumbnails': thumbnails,
+            'description': content_data.get('description'),
+            'uploader': user.get('name'),
+            'creator': user.get('name'),
+            'timestamp': parse_iso8601(flipagram.get('iso801Created')),
+            'upload_date': unified_strdate(flipagram.get('created')),
+            'uploader_id': user.get('username'),
+            'view_count': int_or_none(counts.get('plays')),
+            'repost_count': int_or_none(counts.get('reflips')),
+            'comment_count': int_or_none(counts.get('comments')),
+            'comments': comments,
+            'tags': tags,
+        }