From e4e961df7b2a7ffd50efdfd8b46cd4f8bff8b140 Mon Sep 17 00:00:00 2001 From: motophil Date: Mon, 23 Jan 2017 23:38:36 +0100 Subject: [PATCH] [FetLife] add new extractor - also extract duration and like_count --- youtube_dl/extractor/fetlife.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/youtube_dl/extractor/fetlife.py b/youtube_dl/extractor/fetlife.py index fa4d29c72..038ef5602 100644 --- a/youtube_dl/extractor/fetlife.py +++ b/youtube_dl/extractor/fetlife.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import time +import re from .jwplatform import JWPlatformBaseIE from ..utils import ( ExtractorError, @@ -28,6 +29,8 @@ class FetLifeIE(JWPlatformBaseIE): 'uploader_id': '1537262', 'age_limit': 18, 'upload_date': '20170110', + 'duration': 91, + }, 'params': { 'usenetrc': True, @@ -72,10 +75,21 @@ class FetLifeIE(JWPlatformBaseIE): title = self._search_regex(r']+id=\"video_caption\">[\s\S]+?]+class=\"description\">([^<]+)', webpage, 'title') uploader = self._search_regex(r']+class=\"member-info\">[\s\S]+?]+class=\"nickname\"[\s\S]+?>([^<]+)', webpage, 'uploader', default=None) uploader_id = self._search_regex(r']+class=\"member-info\">[\s\S]+?]+href=\"/users/([0-9]+)', webpage, 'uploader_id', default=None) + timestamp = self._search_regex(r']+id=\"video_caption\">[\s\S]+?]+>([^<]+)', webpage, 'timestamp', default=None) if timestamp: timestamp = int(time.mktime(time.strptime(timestamp, "%Y/%m/%d %H:%M:%S +0000"))) + mobj = re.search(r'clock<[^>]*>\s*(?P[0-9]+)m\s*(?P[0-9]+)s', webpage) + duration_minutes = mobj.groupdict().get('duration_minutes') + duration_seconds = mobj.groupdict().get('duration_seconds') + if (duration_minutes is not None) and (duration_seconds is not None): + duration = int(duration_minutes) * 60 + int(duration_seconds) + + like_count = self._search_regex(r'[0-9]+\s*Love\s*it', webpage, 'like_count', default=None) + if like_count: + like_count = int(like_count) + video_data.update({ 'id': video_id, 'title': title, @@ -83,6 +97,8 @@ class FetLifeIE(JWPlatformBaseIE): 'timestamp': timestamp, 'uploader_id': uploader_id, 'age_limit': 18, + 'duration': duration, + 'like_count': like_count, }) return video_data