Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# LATER: add debug logging for youtube response
if video_result == False:
return Result(
False,
meta_info=None,
message=video_result.message
)
elif len(video_result) == 0:
return Result(
False,
meta_info=None,
message=_('Invalid YouTube URL. This video does not exist or is private and can not be embedded.')
)
video_details = video_result[0]
iso8601_duration = video_details['contentDetails']['duration']
duration = aniso8601.parse_duration(iso8601_duration)
snippet = video_details['snippet']
best_thumbnail = self._find_biggest_thumbnail(snippet['thumbnails'])
meta_info = {
'unique_id': video_details['id'],
'duration': timedelta_to_seconds(duration),
'display_name': snippet['title'],
'description': snippet['description'],
'thumbnail': {
'width': best_thumbnail['width'],
'height': best_thumbnail['height'],
'url': best_thumbnail['url'],
},
'type': VIDEO,
}
return Result(True, meta_info=meta_info, message=None)
If a number is provided, it will be interpreted as the number of
seconds.
If a `dict` is provided, does `datetime.timedelta(**value)`.
:param value: something to convert
:type value: str | unicode | float | int | datetime.timedelta | dict
:return: the value after conversion
:rtype: datetime.timedelta
"""
if isinstance(value, basestring):
try:
return aniso8601.parse_duration(value)
except Exception as e:
msg = (
"Conversion to datetime.timedelta failed. Could not "
"parse the given string as an ISO 8601 duration: "
"%s\n\n"
"%s" %
(
repr(value),
e.message,
)
)
raise ValueError(msg)
try:
if isinstance(value, datetime.timedelta):
return value
def to_timedelta(amazon_duration):
return aniso8601.parse_duration(amazon_duration)
def get_timedelta(self, iso8601_time_duration_string):
""" A facade method for the iso8601.parse_duration method that reads a string,
containing an iso8601 time duration value, and returns a datetime.timedelta object.
:param iso8601_time_duration_string: a string containing an iso8601 time duration.
:return: datetime.timedelta
"""
time_delta = None
try:
time_delta = parse_duration(iso8601_time_duration_string)
except Exception as ex:
self.logger.error("Time Duration Unparseable: {td}".format(td=iso8601_time_duration_string))
self.logger.error(ex)
finally:
return time_delta or timedelta(seconds=0)