html playlist in table - updates to jinja

main
Rob Canning 2024-01-21 23:21:34 +01:00
parent 2394d9387d
commit de16269ad8
6 changed files with 93 additions and 80 deletions

Binary file not shown.

View File

@ -92,7 +92,7 @@
<div class="container"> <div class="container">
<div class="row align-items-center justify-content-center text-center"> <div class="row align-items-center justify-content-center text-center">
<div class="col-md-8" data-aos="fade-up" data-aos-delay="400"> <div class="col-md-8" data-aos="fade-up" data-aos-delay="400">
<h2 class="text-white font-weight-light mb-2 display-4">{{episode_title}}</h2> <h2 class="text-white font-weight-light mb-2 display-4">{{show_title}}</h2>
<div class="text-white mb-3"><span class="text-white-opacity-05"><small>{{episode_author}} <span class="sep">/</span> {{episode_date}} <span class="sep">/</span> {{episode_dur}}</small></span></div> <div class="text-white mb-3"><span class="text-white-opacity-05"><small>{{episode_author}} <span class="sep">/</span> {{episode_date}} <span class="sep">/</span> {{episode_dur}}</small></span></div>
</div> </div>
</div> </div>
@ -108,33 +108,41 @@
</div> </div>
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-7"> <div class="col-md-12">
<h4>This weeks playlist:</h4> <h2>{{show_name}} | Episode #{{episode_number}} | {{episode_date}}</h2>
{% for track in episode_playlist[0:] %} <em>Total playtime: {{episode_duration}} | Show presented by: {{show_author}}</em>
<p><b> {{track}} </b> </p>
{% endfor %}
<!-- <table> -->
<!-- {% for track in episode_playlist[0:] %} -->
<!-- <TR> -->
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> --> <!-- {% for track in episode_playlist[0:] %} -->
<!-- <TD class="c2">{{track[0]}}</TD> --> <!-- <p><b> {{track}} </b> </p> -->
<!-- <TD class="c3">{{track[1]}}</TD> --> <!-- {% endfor %} -->
<!-- <TD class="c4"><SPAN>{{track[2]}}</SPAN></TD> --> <table class="table table-striped">
<!-- <TD class="c5"><SPAN>{{track[3]}}</SPAN></TD> -->
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
<TD class="c1"><b>TRACK</b></TD>
<TD class="c2"><b>ARTIST</b></TD>
<TD class="c3"><b>ALBUM</b></TD>
<TD class="c4"><b>YEAR</b></TD>
<TD class="c5"><b>DURATION</b></TD>
<TD class="c5"><b>LABEL</b></TD>
<!-- <\!-- <Item> -\-> --> {% for track in episode_playlist[0:] %}
<!-- <\!-- <p>{{track}}</p> -\-> --> <TR>
<!-- <\!-- </item> -\-> -->
<!-- </TR> --> <!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
<!-- {% endfor %} --> <TD class="c1"><i>{{track[0]}}</i></TD>
<!-- </table> --> <TD class="c2">{{track[1]}}</TD>
<TD class="c3">{{track[2]}}</TD>
<TD class="c4">{{track[3]}}</TD>
<TD class="c5">{{track[4]}}</TD>
<TD class="c5">{{track[5]}}</T>
<!-- <Item> -->
<!-- <p>{{track}}</p> -->
<!-- </item> -->
</TR>
{% endfor %}
</table>
</div> </div>
</div> </div>

View File

@ -117,7 +117,8 @@
<h2 class="font-weight-bold text-black">Previous Episodes</h2> <h2 class="font-weight-bold text-black">Previous Episodes</h2>
</div> </div>
</div> </div>
{% for episode in episodes %} {% for episode in episodes %}
<div class="d-block d-md-flex podcast-entry bg-white mb-5" data-aos="fade-up"> <div class="d-block d-md-flex podcast-entry bg-white mb-5" data-aos="fade-up">
<div class="image" style="background-image: url('episode/{{episode.episode_number}}/img/cover.png');"></div> <div class="image" style="background-image: url('episode/{{episode.episode_number}}/img/cover.png');"></div>
@ -126,7 +127,7 @@
<h3 class="font-weight-light"><a href="episode/{{episode.episode_number}}/index.html">Episode: # {{episode.episode_number}} </a></h3> <h3 class="font-weight-light"><a href="episode/{{episode.episode_number}}/index.html">Episode: # {{episode.episode_number}} </a></h3>
<div class="text-white mb-3"><span class="text-black-opacity-05"> <div class="text-white mb-3"><span class="text-black-opacity-05">
<small>Presented by Rob Canning <span class="sep">/</span> {{episode.episode_date}} <span class="sep">/</span> {{episode.episode_duration}}</small></span></div> <small>Presented by Rob Canning <span class="sep">/</span> {{episode.episode_date}} <span class="sep">/</span> {{episode.episode_duration}}</small></span></div>
<p class="mb-4">On this weeks show music from: {{episode.episode_artists}}</p> <p class="mb-4">On this weeks show music from: {{episode.episode_artists}} </p>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# CREATE MUSIC DATABASE ------------------------------------------ # CREATE MUSIC DATABASE AND EPISODE TABLES --------------------------
import sys, os, datetime, fnmatch, glob, random, time, pathlib, re import sys, os, datetime, fnmatch, glob, random, time, pathlib, re
from datetime import timedelta from datetime import timedelta
@ -12,8 +12,6 @@ import uuid
#import pypika # sql query builder #import pypika # sql query builder
from pypika import Query, Table, Field, Column from pypika import Query, Table, Field, Column
conn = ''
music_library_path = "/home/rob/antena/music/" music_library_path = "/home/rob/antena/music/"
conn = sqlite3.connect("database/show.db") conn = sqlite3.connect("database/show.db")
@ -45,15 +43,9 @@ def database_create(conn):
conn.execute(str(mus_lib)) conn.execute(str(mus_lib))
print('''MUSIC LIBRARY Table created successfully'''); print('''MUSIC LIBRARY Table created successfully''');
#conn = ''
def database_create_episodes_table(conn): def database_create_episodes_table(conn):
# the show database # the show database
# conn = sqlite3.connect("database/show.db")
#TODO put the below back as a raw quiry to make if not exists possible
q = Query \ q = Query \
.create_table("EPISODES") \ .create_table("EPISODES") \
.columns( .columns(
@ -63,19 +55,17 @@ def database_create_episodes_table(conn):
Column("album", "VARCHAR(200)", nullable=True), Column("album", "VARCHAR(200)", nullable=True),
Column("track", "VARCHAR(120)", nullable=True), Column("track", "VARCHAR(120)", nullable=True),
Column("artist", "VARCHAR(120)", nullable=True), Column("artist", "VARCHAR(120)", nullable=True),
Column("trackdur", "FLOAT", nullable=True), Column("trackdur", "REAL", nullable=True),
Column("genre", "VARCHAR(120)", nullable=True), Column("genre", "VARCHAR(120)", nullable=True),
Column("year", 'DATETIME', nullable=True), Column("year", 'DATETIME', nullable=True),
Column("path", "VARCHAR(120)", nullable=False))\ Column("path", "VARCHAR(120)", nullable=False),
Column("label", "VARCHAR(120)", nullable=False),
Column("comment", "VARCHAR(120)", nullable=False))\
.unique("path") \ .unique("path") \
.primary_key("path") .primary_key("path")
#TODO get the unique path back into action find bug #TODO get the unique path back into action find bug
conn.execute(str(q)) conn.execute(str(q))
print("EPISODES Table created successfully"); print("EPISODES Table created successfully");
def mk_db_entry(conn): def mk_db_entry(conn):
@ -88,14 +78,15 @@ def mk_db_entry(conn):
for m in [".flac", ".FLAC", ".mp3"]: # get audio files for m in [".flac", ".FLAC", ".mp3"]: # get audio files
if m in file: if m in file:
filepath = pathlib.Path(subdir + "/" +file) filepath = pathlib.Path(subdir + "/" +file)
label = filepath.parts[5] # get LABEL etc name from path label = filepath.parts[5]
# get LABEL etc name from path
# TODO THIS will break when path changes - make relative to cwd
track = TinyTag.get(os.path.join(subdir, file))# get metadata from file track = TinyTag.get(os.path.join(subdir, file))# get metadata from file
cursor = conn.cursor() cursor = conn.cursor()
mus_lib = Table('MUSIC_LIBRARY') mus_lib = Table('MUSIC_LIBRARY')
q = mus_lib.insert(1, label, track.album, track.title, track.artist, \ q = mus_lib.insert(1, label, track.album, track.title, track.artist, \
track.genre, track.duration, track.year, \ track.genre, track.duration, track.year, \
label_url, str(filepath), "last_played", track.comment) label_url, str(filepath), 1970-1-1, track.comment)
cursor.execute(str(q)); cursor.execute(str(q));
conn.commit() conn.commit()

View File

@ -23,7 +23,6 @@ episode_number = int(sys.argv[1])
input_date = sys.argv[2] input_date = sys.argv[2]
episode_date = datetime.datetime.now().strftime("%Y-%m-%d") episode_date = datetime.datetime.now().strftime("%Y-%m-%d")
episode_duration = 0 episode_duration = 0
complete_playlist = []
episode_playlist = [] episode_playlist = []
show_cover = "" show_cover = ""
archive = [] archive = []
@ -35,7 +34,7 @@ web_path = "/home/rob/antena/html/episode/{0}/img".format(episode_number)
conn = sqlite3.connect("database/show.db") conn = sqlite3.connect("database/show.db")
if os.path.exists(web_path): if os.path.exists(web_path):
print("path_exists_doing_nothing") print("web path already exists .... doing_nothing")
else: os.makedirs(web_path) else: os.makedirs(web_path)
# ///////////////////////////////////////////////// # /////////////////////////////////////////////////
@ -57,6 +56,7 @@ def add_to_tracks_played(add_to_played: str):
with open('playlists/track_playout_history.txt', "a") as tracks_played_file: with open('playlists/track_playout_history.txt', "a") as tracks_played_file:
tracks_played_file.write(str(add_to_played) + "\n") # newline \n needed here? tracks_played_file.write(str(add_to_played) + "\n") # newline \n needed here?
#TODO replace the below with database stuff
def check_archive(track): def check_archive(track):
global archive global archive
with open('playlists/track_playout_history.txt') as archive_file: with open('playlists/track_playout_history.txt') as archive_file:
@ -69,7 +69,7 @@ def check_archive(track):
print("____ TRACK ALREADY PLAYED _____") print("____ TRACK ALREADY PLAYED _____")
return False return False
def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list): def create_episode_playlist(conn, episode_playlist: list, episode_number):
global episode_duration global episode_duration
global archive global archive
@ -79,14 +79,17 @@ def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list
max_track_dur = 9 max_track_dur = 9
min_track_dur = 2 min_track_dur = 2
# first clear the sqlite table rows for the episode
cursor = conn.cursor()
cursor.execute('DELETE FROM episodes WHERE episode = {0}'.format(episode_number))
# TODO what is most important 12 tracks or 60 minutes # TODO what is most important 12 tracks or 60 minutes
# what will
while episode_duration < 60 * 60 and track_count < 12 : while episode_duration < 60 * 60 and track_count < 12 :
cursor = conn.cursor()
cursor.execute("SELECT * FROM MUSIC_LIBRARY ORDER BY RANDOM() LIMIT 1 ;") cursor.execute("SELECT * FROM MUSIC_LIBRARY ORDER BY RANDOM() LIMIT 1 ;")
r = cursor.fetchone() # FETCH ONE RANDOM TRACK FROM THE DATABASE r = cursor.fetchone() # FETCH ONE RANDOM TRACK FROM THE DATABASE
# for t in r: # for t in r:
song = str(r[9]) song = str(r[9])
track_label = str(r[1]) track_label = str(r[1])
@ -97,10 +100,9 @@ def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list
track_genre = str(r[5]) track_genre = str(r[5])
track_year = str(r[7]) track_year = str(r[7])
track_path = song #'/'.join(song.split('/')[0:-1]) track_path = song #'/'.join(song.split('/')[0:-1])
#print(str(song)+"ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss") track_comment = str(r[11])
# SOME LOGIC TO SEE IF WE ALLOW THAT TRACK OR NOT # SOME LOGIC TO SEE IF WE ALLOW THAT TRACK OR NOT
# TODO here we need to append to DB not the static file # TODO here we need to append to DB not the static file
if track_artist not in artists_played: if track_artist not in artists_played:
if check_archive(track_title) is True: if check_archive(track_title) is True:
@ -108,7 +110,7 @@ def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list
if int(track_duration) < max_track_dur * 60: if int(track_duration) < max_track_dur * 60:
episode_playlist.append(song.rstrip()) # if 'not in' is true then add the song episode_playlist.append(song.rstrip()) # if 'not in' is true then add the song
art = string=re.sub("\(.*?\)","",track_artist) art = string=re.sub("\(.*?\)","",track_artist)
print(art + "?????????????????????????????????????????????????????????????????????????????????????")
# shorten verbose artist names such as trojnik Trojnik (Cene Resnik, Tomaž Grom, Vid Drašler) # shorten verbose artist names such as trojnik Trojnik (Cene Resnik, Tomaž Grom, Vid Drašler)
art = string=re.sub("and","&",art) art = string=re.sub("and","&",art)
artist_abreviated.append(art) artist_abreviated.append(art)
@ -118,11 +120,11 @@ def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list
if not track_year: # where missing metadata give a dummy value if not track_year: # where missing metadata give a dummy value
track_year = 0000 track_year = 0000
e = Table('EPISODES') e = Table('EPISODES')
q = e.insert(1, episode_number, episode_date, \ q = e.insert(1, episode_number, episode_date, \
track_album, track_title, track_artist, \ track_album, track_title, track_artist, \
track_duration,track_genre, track_year, track_path) track_duration,track_genre, track_year, \
track_path, track_label, track_comment)
cursor.execute(str(q)) cursor.execute(str(q))
# ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \ # ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \
@ -276,7 +278,7 @@ def create_animated_gif():
def create_pls_file(): def create_pls_file():
# write the selection as a playlist file # write the selection as a playlist file
with open("shows/antena_playlist_" + episode_date + ".pls","w") as file: with open("shows/antena_playlist_" + episode_date + ".pls","w") as file:
file.writelines("\n".join(episode_playlist)) file.writelines("\n".join(episode_playlist))
def create_podcast(episode_playlist: list): def create_podcast(episode_playlist: list):
@ -363,11 +365,15 @@ def create_html_homepage_from_template(episode_playlist):
cursor = conn.cursor() cursor = conn.cursor()
show_info = [] show_info = []
episode_artists = [] episode_artists = []
num_eps = 4 #TODO fix this - now it reports zero
# get number of episodes from DB
cursor.execute('SELECT MAX(episode) FROM EPISODES')
num_eps = cursor.fetchone()[0]
num_eps = num_eps+1
for i in range(num_eps): for i in range(num_eps):
artists = [] artists = []
cursor.execute("SELECT artist FROM EPISODES WHERE episode=?", [i]) cursor.execute("SELECT artist FROM EPISODES WHERE episode=?", [i])
@ -384,11 +390,12 @@ def create_html_homepage_from_template(episode_playlist):
for i in range(num_eps): # get this from new table EPISODE_STATS number of tracks in DB for i in range(num_eps): # get this from new table EPISODE_STATS number of tracks in DB
print(episode_artists[i]) print(episode_artists[i])
an_episode = dict(date="2012-02-", \ an_episode = dict(date="2012-02-", \
episode_artists=episode_artists[i], episode_number=i, \ episode_artists=str(episode_artists[i]).strip("[").strip("]").strip("\'"), episode_number=i, \
episode_date=episode_date, \ episode_date=episode_date, \
episode_duration=episode_duration) episode_duration=episode_duration)
episodes.append(an_episode) episodes.append(an_episode)
episodes = reversed(episodes) # reversed order to most recent episode appears first in list episodes = reversed(episodes[1:episode_number])
# reversed order to most recent episode appears first in list
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number]) cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number])
@ -421,7 +428,7 @@ def create_html_homepage_from_template(episode_playlist):
episode_page.write(output_from_parsed_template) episode_page.write(output_from_parsed_template)
def create_html_episode_from_template(episode_playlist): def create_html_episode_from_template(episode_playlist, episode_number):
from jinja2 import Template, Environment, FileSystemLoader from jinja2 import Template, Environment, FileSystemLoader
@ -429,6 +436,7 @@ def create_html_episode_from_template(episode_playlist):
episode_template = env.get_template('episode.jinja') episode_template = env.get_template('episode.jinja')
show_info = [] show_info = []
playlist_table = []
# maybe a jinja2 template loop here instead # maybe a jinja2 template loop here instead
cursor = conn.cursor() cursor = conn.cursor()
@ -444,26 +452,29 @@ def create_html_episode_from_template(episode_playlist):
r = cursor.fetchall() r = cursor.fetchall()
for t in r: for t in r:
song = str(t[0]) song = str(t[0])
#track_label = str(t[1])
track_album = str(t[3]) track_album = str(t[3])
track_title = str(t[4]) track_title = str(t[4])
track_artist = str(t[5]).upper() track_artist = str(t[5]).upper()
track_duration = float(t[6]) track_duration = float(t[6])
track_genre = str(t[7]) track_genre = str(t[7])
track_year = str(t[8]) track_year = str(t[8])
track_label = str(t[10])
track_comment = str(t[11])
detail = str(track_artist) + " | " + str(track_album) + \ detail = str(track_artist) + " | " + str(track_album) + \
" | " + str(track_title) + " | " + str(track_year) + \ " | " + str(track_title) + " | " + str(track_year) + \
" | " + str(timedelta(seconds=round(track_duration))) " | " + str(timedelta(seconds=round(track_duration)))
playlist_entry = [track_title, track_artist, track_album, track_year, timedelta(seconds=round(track_duration)), track_label.upper() ]
playlist_table.append(playlist_entry)
show_info.append("" + detail) show_info.append("" + detail)
#TODO FIX THIS UP TO SEND COLUMNS FROM LIST TO JINJA #TODO FIX THIS UP TO SEND COLUMNS FROM LIST TO JINJA
output_from_parsed_template = episode_template.render(\ output_from_parsed_template = episode_template.render(\
show_name=show_name, episode_author="Rob Canning",\ show_name=show_name, episode_author="Rob Canning",\
episode_duration=episode_duration, \ episode_number=episode_number, episode_duration=episode_duration, \
episode_date=episode_date, about_show=show_short_description, \ episode_date=episode_date, about_show=show_short_description, \
episode_playlist=show_info, \ episode_playlist=playlist_table, \
episode_image="img/cover.png".format(episode_number)) episode_image="img/cover.png".format(episode_number))
with open("html/episode/{0}/index.html".format(episode_number), "w") as episode_page: with open("html/episode/{0}/index.html".format(episode_number), "w") as episode_page:
@ -490,12 +501,12 @@ def main():
# database_create_episodes_table() # database_create_episodes_table()
set_episode_date(input_date) set_episode_date(input_date)
create_episode_playlist(conn, episode_playlist, complete_playlist) create_episode_playlist(conn, episode_playlist, episode_number)
create_show_coverart(episode_playlist, 1) #episode_duration = 100 create_show_coverart(episode_playlist, 1) #episode_duration = 100
#create_animated_gif() #create_animated_gif()
create_intro(episode_playlist) create_intro(episode_playlist)
create_pls_file() create_pls_file()
create_html_episode_from_template(episode_playlist) create_html_episode_from_template(episode_playlist, episode_number)
create_html_homepage_from_template(episode_playlist) create_html_homepage_from_template(episode_playlist)
create_RSS_XML_from_template() create_RSS_XML_from_template()
conn.close() conn.close()

View File

@ -1,11 +1,13 @@
Some Spatter Left YuWrong
The Mother (Act VII) Action XIV
Tilt - Tilt - 03 Alicante 3 things i decided against
Hunahpu & Xbalanque Domen Gnezda - Misnomer II - 02 Misnomer 24
Maskardh - Thrills Of Deconstruction Crushing Trauma
Heretics Fork Nicholas Cage
94 The Great White Buffalo
Zlatko Kaučič, Tomaž Grom - The Ear Is The Shadow Of The Eye - 12 Battling For A Title - Za naslov se boriva Integral [Excerpt]
Crossing The Rubicon Slika 4
šopscum solata Tomaž Grom - Sam, za... - 05 G.V.
Styröfoam - Moonmiles
The Oppressed 1 (Outtake)