Skip to content

Commit

Permalink
metadata using builtin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Noor Mostafa committed Dec 8, 2023
1 parent 09ccfd7 commit b57090b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions yt_dlp/extractor/cnbc.py
Expand Up @@ -3,6 +3,7 @@
import json
import re
from datetime import datetime
from ..utils import unified_timestamp, variadic


class CNBCIE(InfoExtractor):
Expand Down Expand Up @@ -78,22 +79,29 @@ def _real_extract(self, url):
if not matched:
raise ValueError("JSON data not found")
metadata = json.loads(matched.group(1))
# assert(isinstance(json, str))
url = metadata["page"]["page"]["layout"][1]["columns"][0]["modules"][0]["data"]["encodings"][0]["url"]

date_format = "%Y-%m-%dT%H:%M:%S%z"
upload_date_string = metadata['page']['page']['layout'][1]['columns'][0]['modules'][0]['data']['uploadDate']
dt_object = datetime.strptime(upload_date_string, date_format)
timestamp = int(dt_object.timestamp())
# print("test test ", timestamp)
# upload_date_string = metadata['page']['page']['layout'][1]['columns'][0]['modules'][0]['data']['uploadDate']
# dt_object = datetime.strptime(upload_date_string, date_format)
# timestamp = unified_timestamp(upload_date_string)

# returns = self._json_ld(json.dumps(metadata), str(video_id))
# json_ld = self._yield_json_ld(cleaned, str(video_id))
info = self._search_json_ld(webpage, str(video_id), default={})
info["formats"] = self._extract_akamai_formats(url, str(video_id))
info["id"] = str(video_id)



# import pdb
# pdb.set_trace()
# info = self._search_json_ld(cleaned, str(video_id), default={})

return {
"id": str(video_id),
"formats": self._extract_akamai_formats(url, str(video_id)),
"thumbnail" : metadata['page']['page']['layout'][1]['columns'][1]['modules'][0]['data']['thumbnail'],
"timestamp" : timestamp,
"description" : metadata['page']['page']['layout'][1]['columns'][0]['modules'][0]['data']['description']
}

# json_ld = json.dumps(metadata)

# returns = self._json_ld(json_ld, str(video_id))
# print(timestamp)

return info
2 changes: 1 addition & 1 deletion yt_dlp/extractor/common.py
Expand Up @@ -1675,7 +1675,7 @@ def traverse_json_ld(json_ld, at_top_level=True):
continue
else:
break

traverse_json_ld(json_ld)
return filter_dict(info)

Expand Down

0 comments on commit b57090b

Please sign in to comment.