This repository has been archived on 2022-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
Yotter/youtube_data/utils.py

60 lines
1.3 KiB
Python
Raw Normal View History

2020-09-10 05:54:32 +05:30
import requests
import urllib.parse
import json
from bs4 import BeautifulSoup as bs
nested_renderer_dispatch = {
'singleColumnBrowseResultsRenderer',
'twoColumnBrowseResultsRenderer', # Channel renderer
'twoColumnSearchResultsRenderer',
}
# these renderers contain a list of renderers inside them
nested_renderer_list_dispatch = {
'sectionListRenderer',
'itemSectionRenderer',
'gridRenderer',
'playlistVideoListRenderer',
'singleColumnWatchNextResults',
}
_item_types = {
'movieRenderer',
'didYouMeanRenderer',
'showingResultsForRenderer',
'videoRenderer',
'compactVideoRenderer',
'compactAutoplayRenderer',
'videoWithContextRenderer',
'gridVideoRenderer',
'playlistVideoRenderer',
'playlistRenderer',
'compactPlaylistRenderer',
'gridPlaylistRenderer',
'radioRenderer',
'compactRadioRenderer',
'gridRadioRenderer',
'showRenderer',
'compactShowRenderer',
'gridShowRenderer',
'channelRenderer',
'compactChannelRenderer',
'gridChannelRenderer',
}
def getRenderers(data):
renderers = []
for renderer in nested_renderer_dispatch:
renderers.append(data['contents'][renderer])
return renderers
def getRenderedItems(renderer):
'''Given a renderer, return its items'''