in plugins/consensual_youtube.py [0:0]
def replace_tag(input_path, output_path, soup, tag):
tag.name = 'div'
if not tag.has_attr('youtube_id'):
raise ValueError('Attribute "youtube_id" is mandatory for "youtube" tags')
yt_id = tag['youtube_id']
# If a preview file is present in the input content directory,
# use that and rely on Pelican to copy it to the output. If not,
# fetch it from YouTube at site generation time and place it
# straight into the output directory:
preview = f'/img/yt_preview_{yt_id}.jpg'
if not path.isfile(input_path + preview):
request.urlretrieve(f'https://img.youtube.com/vi/{yt_id}/0.jpg',
output_path + preview)
# Default YouTube player size is 360p:
player_width = 640
player_height = 360
if not tag.has_attr('id'):
tag['id'] = f'yt-container-{yt_id}'
tag['class'] = 'yt-container'
tag['style'] = f"background-image: url('{preview}'); width: {player_width}px; height: {player_height}px;"
warning = soup.new_tag('div')
warning['class'] = "yt-notice"
tag.append(warning)