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 27, 2023
1 parent bdc72ee commit a27e0aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion 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 @@ -41,15 +42,23 @@ def metadata(self) -> Dict[str, Any]:
-------
Dict
Video metadata in a dict format containing keys: title, id, views, duration, author_id,
upload_date, url, thumbnails, tags, description
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\":(.*?)}}")
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\":', ''))
scheduled_starttime = (
datetime.utcfromtimestamp(
int(scheduled_starttime_pattern.search(self._video_data).group(1))
).isoformat()
if metadata["isLiveContent"]
else None
)
data = {
'title': metadata['title'],
'id': metadata['videoId'],
Expand All @@ -58,6 +67,7 @@ def metadata(self) -> Dict[str, Any]:
'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 a27e0aa

Please sign in to comment.