diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-09-08 18:42:08 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-09-08 18:42:08 -0700 |
commit | 89e5761f8d9ae4221c4a97eca3c0fce3405a5bc4 (patch) | |
tree | 02aa1b329ca5800992e077f988c19b14165cf5a0 /youtube/yt_data_extract.py | |
parent | c362a5e834d88524c154cb010be9dc909dcbe25d (diff) | |
download | yt-local-89e5761f8d9ae4221c4a97eca3c0fce3405a5bc4.tar.lz yt-local-89e5761f8d9ae4221c4a97eca3c0fce3405a5bc4.tar.xz yt-local-89e5761f8d9ae4221c4a97eca3c0fce3405a5bc4.zip |
Extraction: Move playlist extraction to yt_data_extract
Diffstat (limited to 'youtube/yt_data_extract.py')
-rw-r--r-- | youtube/yt_data_extract.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/youtube/yt_data_extract.py b/youtube/yt_data_extract.py index 95c68bc..e7a2f1e 100644 --- a/youtube/yt_data_extract.py +++ b/youtube/yt_data_extract.py @@ -449,3 +449,30 @@ def extract_search_info(polymer_json): return info + +def extract_playlist_metadata(polymer_json): + metadata = renderer_info(polymer_json['response']['header']) + + if 'description' not in metadata: + metadata['description'] = '' + + metadata['size'] = int(metadata['size'].replace(',', '')) + + return metadata + +def extract_playlist_info(polymer_json): + info = {} + try: # first page + video_list = polymer_json['response']['contents']['singleColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['playlistVideoListRenderer']['contents'] + first_page = True + except KeyError: # other pages + video_list = polymer_json['response']['continuationContents']['playlistVideoListContinuation']['contents'] + first_page = False + + info['items'] = [renderer_info(renderer) for renderer in video_list] + + if first_page: + info['metadata'] = extract_playlist_metadata(polymer_json) + + return info + |