Skip to content

Commit

Permalink
feat: Add scheduled_starttime to video metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynn620 committed Dec 29, 2023
1 parent bdc72ee commit 564b837
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions aiotube/video.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import re
import json
from .https import video_data
Expand Down Expand Up @@ -40,24 +41,42 @@ def metadata(self) -> Dict[str, Any]:
Returns
-------
Dict
Video metadata in a dict format containing keys: title, id, views, duration, author_id,
upload_date, url, thumbnails, tags, description
Video metadata in a dict format containing keys: title, id, views, streamed, live_now, duration, author_id,
upload_date, scheduled_starttime, url, thumbnails, tags, description
"""
details_pattern = re.compile('videoDetails\":(.*?)\"isLiveContent\":.*?}')
upload_date_pattern = re.compile("<meta itemprop=\"uploadDate\" content=\"(.*?)\">")
genre_pattern = re.compile("<meta itemprop=\"genre\" content=\"(.*?)\">")
like_count_pattern = re.compile("iconType\":\"LIKE\"},\"defaultText\":(.*?)}}")
live_boardcast_detials_pattern = re.compile("liveBroadcastDetails\":\{(.*?)\}")
scheduled_starttime_pattern = re.compile("scheduledStartTime\":\"(.*?)\"")
raw_details = details_pattern.search(self._video_data).group(0)
upload_date = upload_date_pattern.search(self._video_data).group(1)
metadata = json.loads(raw_details.replace('videoDetails\":', ''))
live_boardcast_detials = (
json.loads(
f"{{{live_boardcast_detials_pattern.search(self._video_data).group(1)}}}"
)
if metadata["isLiveContent"]
else None
)
scheduled_starttime = (
datetime.utcfromtimestamp(
int(scheduled_starttime_pattern.search(self._video_data).group(1))
).isoformat()
if metadata["isLiveContent"] and not live_boardcast_detials["isLiveNow"]
else None
)
data = {
'title': metadata['title'],
'id': metadata['videoId'],
'views': metadata.get('viewCount'),
'streamed': metadata['isLiveContent'],
'live_now': live_boardcast_detials["isLiveNow"] if metadata["isLiveContent"] else None,
'duration': metadata['lengthSeconds'],
'author_id': metadata['channelId'],
'upload_date': upload_date,
"scheduled_starttime": scheduled_starttime,
'url': f"https://www.youtube.com/watch?v={metadata['videoId']}",
'thumbnails': metadata.get('thumbnail', {}).get('thumbnails'),
'tags': metadata.get('keywords'),
Expand Down

0 comments on commit 564b837

Please sign in to comment.