From b7b365067f492e00166ef7ee0ebebcc53b4b6b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Fri, 5 Feb 2016 23:32:22 +0600 Subject: [PATCH] [vidme:user] Add extractor (Closes #8416) --- youtube_dl/extractor/__init__.py | 5 +++- youtube_dl/extractor/vidme.py | 48 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 8d2fa604b..bedd2397c 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -822,7 +822,10 @@ from .videomore import ( ) from .videopremium import VideoPremiumIE from .videott import VideoTtIE -from .vidme import VidmeIE +from .vidme import ( + VidmeIE, + VidmeUserIE, +) from .vidzi import VidziIE from .vier import VierIE, VierVideosIE from .viewster import ViewsterIE diff --git a/youtube_dl/extractor/vidme.py b/youtube_dl/extractor/vidme.py index 3d63ed4f0..91c8349c2 100644 --- a/youtube_dl/extractor/vidme.py +++ b/youtube_dl/extractor/vidme.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +import itertools + from .common import InfoExtractor from ..compat import compat_HTTPError from ..utils import ( @@ -11,7 +13,7 @@ from ..utils import ( class VidmeIE(InfoExtractor): - _VALID_URL = r'https?://vid\.me/(?:e/)?(?P[\da-zA-Z]+)' + _VALID_URL = r'https?://vid\.me/(?:e/)?(?P[\da-zA-Z]{,5})(?:[^\da-zA-Z]|$)' _TESTS = [{ 'url': 'https://vid.me/QNB', 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', @@ -202,3 +204,47 @@ class VidmeIE(InfoExtractor): 'comment_count': comment_count, 'formats': formats, } + + +class VidmeUserIE(InfoExtractor): + _VALID_URL = r'https?://vid\.me/(?:e/)?(?P[\da-zA-Z]{6,})' + _TEST = { + 'url': 'https://vid.me/EFARCHIVE', + 'info_dict': { + 'id': '3834632', + 'title': 'EFARCHIVE', + }, + 'playlist_mincount': 238, + } + + # Max possible limit according to https://docs.vid.me/#api-Videos-List + _LIMIT = 100 + + def _entries(self, user_id, user_name): + for page_num in itertools.count(1): + page = self._download_json( + 'https://api.vid.me/videos/list?user=%s&limit=%d&offset=%d' + % (user_id, self._LIMIT, (page_num - 1) * self._LIMIT), user_name, + 'Downloading user page %d' % page_num) + + videos = page.get('videos', []) + if not videos: + break + + for video in videos: + video_url = video.get('full_url') or video.get('embed_url') + if video_url: + yield self.url_result(video_url, VidmeIE.ie_key()) + + total = int_or_none(page.get('page', {}).get('total')) + if total and self._LIMIT * page_num >= total: + break + + def _real_extract(self, url): + user_name = self._match_id(url) + + user_id = self._download_json( + 'https://api.vid.me/userByUsername?username=%s' % user_name, + user_name)['user']['user_id'] + + return self.playlist_result(self._entries(user_id, user_name), user_id, user_name)