def get_playlists_list_page(): page = '''<ul>\n''' list_item_template = Template(''' <li><a href="$url">$name</a></li>\n''') for name in get_playlist_names(): page += list_item_template.substitute(url = html.escape(util.URL_ORIGIN + '/playlists/' + name), name = html.escape(name)) page += '''</ul>\n''' return html_common.yt_basic_template.substitute( page_title = "Local playlists", header = html_common.get_header(), style = '', page = page, )
from youtube.template import Template from youtube import util, html_common import settings import os import json import html import gevent import urllib playlists_directory = os.path.join(settings.data_dir, "playlists") thumbnails_directory = os.path.join(settings.data_dir, "playlist_thumbnails") with open('yt_local_playlist_template.html', 'r', encoding='utf-8') as file: local_playlist_template = Template(file.read()) def video_ids_in_playlist(name): try: with open(os.path.join(playlists_directory, name + ".txt"), 'r', encoding='utf-8') as file: videos = file.read() return set(json.loads(video)['id'] for video in videos.splitlines()) except FileNotFoundError: return set() def add_to_playlist(name, video_info_list): if not os.path.exists(playlists_directory): os.makedirs(playlists_directory) ids = video_ids_in_playlist(name) missing_thumbnails = [] with open(os.path.join(playlists_directory, name + ".txt"), "a", encoding='utf-8') as file: for info in video_info_list:
# playlists: # id # title # url # author # author_url # thumbnail # description # updated # size # first_video_id with open('yt_basic_template.html', 'r', encoding='utf-8') as file: yt_basic_template = Template(file.read()) page_button_template = Template('''<a class="page-button" href="$href">$page</a>''') current_page_button_template = Template('''<div class="current-page-button">$page</a>''') medium_playlist_item_template = Template(''' <div class="medium-item-box"> <div class="medium-item"> <a class="playlist-thumbnail-box" href="$url" title="$title"> <img class="playlist-thumbnail-img" src="$thumbnail"> <div class="playlist-thumbnail-info"> <span>$size</span> </div>