]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/xtube.py
c3bb9b2cfb916ad37febd435bc2c67916627edf7
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class XTubeIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?(?P<url>xtube\.com/watch\.php\?v=(?P<videoid>[^/?&]+))'
17 'url': 'http://www.xtube.com/watch.php?v=kVTUy_G222_',
18 'md5': '092fbdd3cbe292c920ef6fc6a8a9cdab',
22 'title': 'strange erotica',
23 'description': 'http://www.xtube.com an ET kind of thing',
24 'uploader': 'greenshowers',
30 def _real_extract(self
, url
):
31 mobj
= re
.match(self
._VALID
_URL
, url
)
32 video_id
= mobj
.group('videoid')
33 url
= 'http://www.' + mobj
.group('url')
35 req
= compat_urllib_request
.Request(url
)
36 req
.add_header('Cookie', 'age_verified=1')
37 webpage
= self
._download
_webpage
(req
, video_id
)
39 video_title
= self
._html
_search
_regex
(r
'<p class="title">([^<]+)', webpage
, 'title')
40 video_uploader
= self
._html
_search
_regex
(
41 r
'so_s\.addVariable\("owner_u", "([^"]+)', webpage
, 'uploader', fatal
=False)
42 video_description
= self
._html
_search
_regex
(
43 r
'<p class="fieldsDesc">([^<]+)', webpage
, 'description', fatal
=False)
44 duration
= parse_duration(self
._html
_search
_regex
(
45 r
'<span class="bold">Runtime:</span> ([^<]+)</p>', webpage
, 'duration', fatal
=False))
46 view_count
= self
._html
_search
_regex
(
47 r
'<span class="bold">Views:</span> ([\d,\.]+)</p>', webpage
, 'view count', fatal
=False)
49 view_count
= str_to_int(view_count
)
50 comment_count
= self
._html
_search
_regex
(
51 r
'<div id="commentBar">([\d,\.]+) Comments</div>', webpage
, 'comment count', fatal
=False)
53 comment_count
= str_to_int(comment_count
)
55 player_quality_option
= json
.loads(self
._html
_search
_regex
(
56 r
'playerQualityOption = ({.+?});', webpage
, 'player quality option'))
58 QUALITIES
= ['3gp', 'mp4_normal', 'mp4_high', 'flv', 'mp4_ultra', 'mp4_720', 'mp4_1080']
62 'format_id': format_id
,
63 'preference': QUALITIES
.index(format_id
) if format_id
in QUALITIES
else -1,
64 } for format_id
, furl
in player_quality_option
.items()
66 self
._sort
_formats
(formats
)
71 'uploader': video_uploader
,
72 'description': video_description
,
74 'view_count': view_count
,
75 'comment_count': comment_count
,
81 class XTubeUserIE(InfoExtractor
):
82 IE_DESC
= 'XTube user profile'
83 _VALID_URL
= r
'https?://(?:www\.)?xtube\.com/community/profile\.php\?(.*?)user=(?P<username>[^&#]+)(?:$|[&#])'
85 'url': 'http://www.xtube.com/community/profile.php?user=greenshowers',
89 'playlist_mincount': 155,
92 def _real_extract(self
, url
):
93 mobj
= re
.match(self
._VALID
_URL
, url
)
94 username
= mobj
.group('username')
96 profile_page
= self
._download
_webpage
(
97 url
, username
, note
='Retrieving profile page')
99 video_count
= int(self
._search
_regex
(
100 r
'<strong>%s\'s Videos \
(([0-9]+)\
)</strong
>'%username, profile_page,
105 page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
106 for n in range(1, page_count + 1):
107 lpage_url = 'http
://www
.xtube
.com
/user_videos
.php?page
=%d&u
=%s' % (n, username)
108 lpage = self._download_webpage(
110 note='Downloading page
%d/%d' % (n, page_count))
112 re.findall(r'addthis
:url
="([^"]+)"', lpage))