[PewTube] Adjust upload date calculation
This commit is contained in:
parent
d56e384309
commit
60100061f5
@ -7,7 +7,7 @@ import subprocess as sp
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import int_or_none
|
from ..utils import compat_str, int_or_none
|
||||||
|
|
||||||
|
|
||||||
class PewTubeIE(InfoExtractor):
|
class PewTubeIE(InfoExtractor):
|
||||||
@ -62,22 +62,25 @@ class PewTubeIE(InfoExtractor):
|
|||||||
upload_date_s = ou = self._html_search_regex(r'<h4>Uploaded ([^<]+)</h4>', webpage, 'upload date')
|
upload_date_s = ou = self._html_search_regex(r'<h4>Uploaded ([^<]+)</h4>', webpage, 'upload date')
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
upload_date_s = re.sub(r'(?:\s+)ago\s+\ ?$', '', upload_date_s)
|
upload_date_s = re.sub(r'(?:\s+)ago\s+\ ?$', '', upload_date_s)
|
||||||
n, unit = re.search('^(?P<n>\d+)\s(?:\s+)?(?P<unit>.*)', upload_date_s).groups()
|
n, unit = re.search('^(?P<n>(?:\d+|a))\s(?:\s+)?(?P<unit>.*)', upload_date_s).groups()
|
||||||
n = int(n)
|
if n == 'a':
|
||||||
unit = unit.lower()
|
n = 1
|
||||||
|
else:
|
||||||
|
n = int(n)
|
||||||
|
unit = unit.lower().encode('utf-8')
|
||||||
total_seconds = 0
|
total_seconds = 0
|
||||||
if not unit.endswith('s'):
|
if not unit.endswith('s'):
|
||||||
unit += 's'
|
unit += 's'
|
||||||
if unit == 'months':
|
if unit == 'months':
|
||||||
total_seconds = n * 86400 * 30
|
unit = 'weeks'
|
||||||
elif unit == 'weeks':
|
n *= 4
|
||||||
total_seconds = n * 86400 * 7
|
elif unit == 'years':
|
||||||
elif unit in ('days', 'hours', 'minutes', 'seconds'):
|
unit = 'weeks'
|
||||||
if unit == 'days' and n >= 1:
|
n *= 52
|
||||||
total_seconds = n * 86400
|
kwargs = dict()
|
||||||
else:
|
kwargs[unit] = n
|
||||||
raise ValueError('Unhandled string: "{}" from "{}"'.format(unit, ou))
|
td = timedelta(**kwargs)
|
||||||
upload_date = (today - timedelta(seconds=total_seconds)).strftime('%Y%m%d')
|
upload_date = (today - td).strftime('%Y%m%d')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user