From 60100061f5473774a9b3ed752a8364f901fc2695 Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Sat, 28 Apr 2018 03:11:57 -0400 Subject: [PATCH] [PewTube] Adjust upload date calculation --- youtube_dl/extractor/pewtube.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/youtube_dl/extractor/pewtube.py b/youtube_dl/extractor/pewtube.py index e017fc182..e429da21a 100644 --- a/youtube_dl/extractor/pewtube.py +++ b/youtube_dl/extractor/pewtube.py @@ -7,7 +7,7 @@ import subprocess as sp import time from .common import InfoExtractor -from ..utils import int_or_none +from ..utils import compat_str, int_or_none class PewTubeIE(InfoExtractor): @@ -62,22 +62,25 @@ class PewTubeIE(InfoExtractor): 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+)\s(?:\s+)?(?P.*)', upload_date_s).groups() - n = int(n) - unit = unit.lower() + 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': - total_seconds = n * 86400 * 30 - elif unit == 'weeks': - total_seconds = n * 86400 * 7 - elif unit in ('days', 'hours', 'minutes', 'seconds'): - if unit == 'days' and n >= 1: - total_seconds = n * 86400 - else: - raise ValueError('Unhandled string: "{}" from "{}"'.format(unit, ou)) - upload_date = (today - timedelta(seconds=total_seconds)).strftime('%Y%m%d') + 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,