# coding: utf-8
from __future__ import unicode_literals
from collections import OrderedDict
from datetime import datetime, timedelta
import re
import subprocess as sp
import time
from .common import InfoExtractor
from ..utils import compat_str, int_or_none
class PewTubeIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?pewtube\.com/user/[^/]+/(?P[^/]+)'
_TEST = {
'url': 'https://pew.tube/user/MrBond/4jLJf06',
'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)',
'info_dict': {
'id': '4jLJf06',
'ext': 'mp4',
'title': 'Mr. Bond - Good Old Nationalist',
'thumbnail': r're:^https?://.*\.jpg$',
# TODO more properties, either as:
# * A value
# * MD5 checksum; start the string with md5:
# * A regular expression; start the string with re:
# * Any Python type (for example int or float)
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id, tries=5, timeout=15)
title = self._html_search_regex(r']+>([^<]+)
', webpage, 'title')
thumbnail = self._html_search_regex(r'
'.format(like_class), webpage, '{} count'))
dislike_count = 0
for dislike_class in ('dislike', 'sad', 'discount',):
dislike_count += int(self._html_search_regex(r'(\d+)
'.format(like_class), webpage, '{} count'))
like_count = None if not like_count else like_count
dislike_count = None if not dislike_count else dislike_count
if not thumbnail:
thumbnail = self._og_search_thumbnail(webpage)
if not description:
description = self._og_search_description(webpage)
upload_date_s = ou = self._html_search_regex(r'Uploaded ([^<]+)
', webpage, 'upload date')
today = datetime.today()
upload_date_s = re.sub(r'(?:\s+)ago\s+\ ?$', '', upload_date_s)
n, unit = re.search('^(?P(?:\d+|a))\s(?:\s+)?(?P.*)', upload_date_s).groups()
if n == 'a':
n = 1
else:
n = int(n)
unit = unit.lower().encode('utf-8')
total_seconds = 0
if not unit.endswith('s'):
unit += 's'
if unit == 'months':
unit = 'weeks'
n *= 4
elif unit == 'years':
unit = 'weeks'
n *= 52
kwargs = dict()
kwargs[unit] = n
td = timedelta(**kwargs)
upload_date = (today - td).strftime('%Y%m%d')
return {
'id': video_id,
'title': title,
'description': description,
'uploader': uploader,
'creator': uploader,
'uploader_url': '/'.join(url.split('/')[:-1]),
'thumbnail': thumbnail,
'view_count': int_or_none(view_count),
'like_count': like_count,
'dislike_count': dislike_count,
'upload_date': upload_date,
'url': video_url,
}