]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/camwithher.py
a0b3749edfcf1bd2c795c256b4d2069bae640f75
[yt-dlp.git] / yt_dlp / extractor / camwithher.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 parse_duration,
7 unified_strdate,
8 )
9
10
11 class CamWithHerIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?camwithher\.tv/view_video\.php\?.*\bviewkey=(?P<id>\w+)'
13
14 _TESTS = [{
15 'url': 'http://camwithher.tv/view_video.php?viewkey=6e9a24e2c0e842e1f177&page=&viewtype=&category=',
16 'info_dict': {
17 'id': '5644',
18 'ext': 'flv',
19 'title': 'Periscope Tease',
20 'description': 'In the clouds teasing on periscope to my favorite song',
21 'duration': 240,
22 'view_count': int,
23 'comment_count': int,
24 'uploader': 'MileenaK',
25 'upload_date': '20160322',
26 'age_limit': 18,
27 },
28 'params': {
29 'skip_download': True,
30 }
31 }, {
32 'url': 'http://camwithher.tv/view_video.php?viewkey=6dfd8b7c97531a459937',
33 'only_matching': True,
34 }, {
35 'url': 'http://camwithher.tv/view_video.php?page=&viewkey=6e9a24e2c0e842e1f177&viewtype=&category=',
36 'only_matching': True,
37 }, {
38 'url': 'http://camwithher.tv/view_video.php?viewkey=b6c3b5bea9515d1a1fc4&page=&viewtype=&category=mv',
39 'only_matching': True,
40 }]
41
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44
45 webpage = self._download_webpage(url, video_id)
46
47 flv_id = self._html_search_regex(
48 r'<a[^>]+href=["\']/download/\?v=(\d+)', webpage, 'video id')
49
50 # Video URL construction algorithm is reverse-engineered from cwhplayer.swf
51 rtmp_url = 'rtmp://camwithher.tv/clipshare/%s' % (
52 ('mp4:%s.mp4' % flv_id) if int(flv_id) > 2010 else flv_id)
53
54 title = self._html_search_regex(
55 r'<div[^>]+style="float:left"[^>]*>\s*<h2>(.+?)</h2>', webpage, 'title')
56 description = self._html_search_regex(
57 r'>Description:</span>(.+?)</div>', webpage, 'description', default=None)
58
59 runtime = self._search_regex(
60 r'Runtime\s*:\s*(.+?) \|', webpage, 'duration', default=None)
61 if runtime:
62 runtime = re.sub(r'[\s-]', '', runtime)
63 duration = parse_duration(runtime)
64 view_count = int_or_none(self._search_regex(
65 r'Views\s*:\s*(\d+)', webpage, 'view count', default=None))
66 comment_count = int_or_none(self._search_regex(
67 r'Comments\s*:\s*(\d+)', webpage, 'comment count', default=None))
68
69 uploader = self._search_regex(
70 r'Added by\s*:\s*<a[^>]+>([^<]+)</a>', webpage, 'uploader', default=None)
71 upload_date = unified_strdate(self._search_regex(
72 r'Added on\s*:\s*([\d-]+)', webpage, 'upload date', default=None))
73
74 return {
75 'id': flv_id,
76 'url': rtmp_url,
77 'ext': 'flv',
78 'no_resume': True,
79 'title': title,
80 'description': description,
81 'duration': duration,
82 'view_count': view_count,
83 'comment_count': comment_count,
84 'uploader': uploader,
85 'upload_date': upload_date,
86 'age_limit': 18
87 }