mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-29 05:32:00 +00:00
Refactor return
This commit is contained in:
parent
129cfb174c
commit
2d82e8a958
1 changed files with 15 additions and 17 deletions
|
@ -25,28 +25,26 @@ class LivestreamfailsIE(InfoExtractor):
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
result = {}
|
id = self._match_id(url)
|
||||||
result['id'] = self._match_id(url)
|
|
||||||
|
|
||||||
# https://livestreamfails.com/clip/id uses https://api.livestreamfails.com/clip/ to fetch the video metadata
|
# https://livestreamfails.com/clip/id uses https://api.livestreamfails.com/clip/ to fetch the video metadata
|
||||||
# Use the same endpoint here to avoid loading and parsing the provided page (which requires JS)
|
# Use the same endpoint here to avoid loading and parsing the provided page (which requires JS)
|
||||||
apiResponse = json.loads(self._download_webpage('https://api.livestreamfails.com/clip/' + result['id'], result['id']))
|
apiResponse = json.loads(self._download_webpage('https://api.livestreamfails.com/clip/' + id, id))
|
||||||
|
|
||||||
# Twitch ID of clip
|
|
||||||
result['display_id'] = apiResponse.get('sourceId')
|
|
||||||
|
|
||||||
# Get the input timestamp (test case gives 2022-06-26T19:29:45.515Z)
|
# Get the input timestamp (test case gives 2022-06-26T19:29:45.515Z)
|
||||||
result['timestamp'] = apiResponse.get('createdAt')
|
timestamp = apiResponse.get('createdAt')
|
||||||
if(result.get('timestamp')):
|
if(timestamp):
|
||||||
# Parse it into a struct_time
|
# Parse it into a struct_time
|
||||||
result['timestamp'] = time.strptime(result['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
timestamp = time.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
# Convert the struct_time to a UNIX timestamp while ignoring the local timezone attached by time.strptime()
|
# Convert the struct_time to a UNIX timestamp while ignoring the local timezone attached by time.strptime()
|
||||||
result['timestamp'] = calendar.timegm(result['timestamp'])
|
timestamp = calendar.timegm(timestamp)
|
||||||
|
|
||||||
# Other fields
|
return {
|
||||||
result['url'] = 'https://livestreamfails-video-prod.b-cdn.net/video/' + apiResponse.get('videoId')
|
'id': id,
|
||||||
result['title'] = apiResponse.get('label')
|
'display_id': apiResponse.get('sourceId'), # Twitch ID of clip
|
||||||
result['creator'] = apiResponse.get('streamer', {}).get('label')
|
'timestamp': timestamp,
|
||||||
result['thumbnail'] = 'https://livestreamfails-image-prod.b-cdn.net/image/' + apiResponse.get('imageId')
|
'url': 'https://livestreamfails-video-prod.b-cdn.net/video/' + apiResponse.get('videoId'),
|
||||||
|
'title': apiResponse.get('label'),
|
||||||
return result
|
'creator': apiResponse.get('streamer', {}).get('label'),
|
||||||
|
'thumbnail': 'https://livestreamfails-image-prod.b-cdn.net/image/' + apiResponse.get('imageId'),
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue