html playlist in table - updates to jinja
parent
2394d9387d
commit
de16269ad8
BIN
database/show.db
BIN
database/show.db
Binary file not shown.
|
@ -92,7 +92,7 @@
|
|||
<div class="container">
|
||||
<div class="row align-items-center justify-content-center text-center">
|
||||
<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>
|
||||
</div>
|
||||
|
@ -108,33 +108,41 @@
|
|||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-7">
|
||||
<h4>This weeks playlist:</h4>
|
||||
{% for track in episode_playlist[0:] %}
|
||||
<p><b> {{track}} </b> </p>
|
||||
{% endfor %}
|
||||
<!-- <table> -->
|
||||
<!-- {% for track in episode_playlist[0:] %} -->
|
||||
<!-- <TR> -->
|
||||
<div class="col-md-12">
|
||||
<h2>{{show_name}} | Episode #{{episode_number}} | {{episode_date}}</h2>
|
||||
<em>Total playtime: {{episode_duration}} | Show presented by: {{show_author}}</em>
|
||||
|
||||
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
|
||||
<!-- <TD class="c2">{{track[0]}}</TD> -->
|
||||
<!-- <TD class="c3">{{track[1]}}</TD> -->
|
||||
<!-- <TD class="c4"><SPAN>{{track[2]}}</SPAN></TD> -->
|
||||
<!-- <TD class="c5"><SPAN>{{track[3]}}</SPAN></TD> -->
|
||||
<!-- {% for track in episode_playlist[0:] %} -->
|
||||
<!-- <p><b> {{track}} </b> </p> -->
|
||||
<!-- {% endfor %} -->
|
||||
<table class="table table-striped">
|
||||
|
||||
<!-- <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> -\-> -->
|
||||
<!-- <\!-- <p>{{track}}</p> -\-> -->
|
||||
<!-- <\!-- </item> -\-> -->
|
||||
<!-- </TR> -->
|
||||
<!-- {% endfor %} -->
|
||||
<!-- </table> -->
|
||||
{% for track in episode_playlist[0:] %}
|
||||
<TR>
|
||||
|
||||
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
|
||||
<TD class="c1"><i>{{track[0]}}</i></TD>
|
||||
<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>
|
||||
|
|
|
@ -117,7 +117,8 @@
|
|||
<h2 class="font-weight-bold text-black">Previous Episodes</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{% for episode in episodes %}
|
||||
<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>
|
||||
|
@ -126,7 +127,7 @@
|
|||
<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">
|
||||
<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>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# CREATE MUSIC DATABASE ------------------------------------------
|
||||
# CREATE MUSIC DATABASE AND EPISODE TABLES --------------------------
|
||||
|
||||
import sys, os, datetime, fnmatch, glob, random, time, pathlib, re
|
||||
from datetime import timedelta
|
||||
|
@ -12,8 +12,6 @@ import uuid
|
|||
#import pypika # sql query builder
|
||||
from pypika import Query, Table, Field, Column
|
||||
|
||||
conn = ''
|
||||
|
||||
music_library_path = "/home/rob/antena/music/"
|
||||
conn = sqlite3.connect("database/show.db")
|
||||
|
||||
|
@ -45,15 +43,9 @@ def database_create(conn):
|
|||
conn.execute(str(mus_lib))
|
||||
print('''MUSIC LIBRARY Table created successfully''');
|
||||
|
||||
|
||||
#conn = ''
|
||||
|
||||
def database_create_episodes_table(conn):
|
||||
# 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 \
|
||||
.create_table("EPISODES") \
|
||||
.columns(
|
||||
|
@ -63,19 +55,17 @@ def database_create_episodes_table(conn):
|
|||
Column("album", "VARCHAR(200)", nullable=True),
|
||||
Column("track", "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("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") \
|
||||
.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))
|
||||
|
||||
|
||||
|
||||
|
||||
print("EPISODES Table created successfully");
|
||||
|
||||
def mk_db_entry(conn):
|
||||
|
@ -88,14 +78,15 @@ def mk_db_entry(conn):
|
|||
for m in [".flac", ".FLAC", ".mp3"]: # get audio files
|
||||
if m in 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
|
||||
cursor = conn.cursor()
|
||||
|
||||
mus_lib = Table('MUSIC_LIBRARY')
|
||||
q = mus_lib.insert(1, label, track.album, track.title, track.artist, \
|
||||
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));
|
||||
conn.commit()
|
||||
|
||||
|
|
59
mk_show.py
59
mk_show.py
|
@ -23,7 +23,6 @@ episode_number = int(sys.argv[1])
|
|||
input_date = sys.argv[2]
|
||||
episode_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
episode_duration = 0
|
||||
complete_playlist = []
|
||||
episode_playlist = []
|
||||
show_cover = ""
|
||||
archive = []
|
||||
|
@ -35,7 +34,7 @@ web_path = "/home/rob/antena/html/episode/{0}/img".format(episode_number)
|
|||
conn = sqlite3.connect("database/show.db")
|
||||
|
||||
if os.path.exists(web_path):
|
||||
print("path_exists_doing_nothing")
|
||||
print("web path already exists .... doing_nothing")
|
||||
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:
|
||||
tracks_played_file.write(str(add_to_played) + "\n") # newline \n needed here?
|
||||
|
||||
#TODO replace the below with database stuff
|
||||
def check_archive(track):
|
||||
global archive
|
||||
with open('playlists/track_playout_history.txt') as archive_file:
|
||||
|
@ -69,7 +69,7 @@ def check_archive(track):
|
|||
print("____ TRACK ALREADY PLAYED _____")
|
||||
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 archive
|
||||
|
@ -79,14 +79,17 @@ def create_episode_playlist(conn, episode_playlist: list, complete_playlist:list
|
|||
max_track_dur = 9
|
||||
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
|
||||
# what will
|
||||
|
||||
while episode_duration < 60 * 60 and track_count < 12 :
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM MUSIC_LIBRARY ORDER BY RANDOM() LIMIT 1 ;")
|
||||
r = cursor.fetchone() # FETCH ONE RANDOM TRACK FROM THE DATABASE
|
||||
|
||||
|
||||
# for t in r:
|
||||
song = str(r[9])
|
||||
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_year = str(r[7])
|
||||
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
|
||||
|
||||
|
||||
|
||||
# TODO here we need to append to DB not the static file
|
||||
if track_artist not in artists_played:
|
||||
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:
|
||||
episode_playlist.append(song.rstrip()) # if 'not in' is true then add the song
|
||||
art = string=re.sub("\(.*?\)","",track_artist)
|
||||
print(art + "?????????????????????????????????????????????????????????????????????????????????????")
|
||||
|
||||
# shorten verbose artist names such as trojnik Trojnik (Cene Resnik, Tomaž Grom, Vid Drašler)
|
||||
art = string=re.sub("and","&",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
|
||||
track_year = 0000
|
||||
|
||||
|
||||
e = Table('EPISODES')
|
||||
q = e.insert(1, episode_number, episode_date, \
|
||||
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))
|
||||
# ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \
|
||||
|
@ -276,7 +278,7 @@ def create_animated_gif():
|
|||
|
||||
def create_pls_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))
|
||||
|
||||
def create_podcast(episode_playlist: list):
|
||||
|
@ -363,11 +365,15 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
cursor = conn.cursor()
|
||||
|
||||
show_info = []
|
||||
|
||||
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):
|
||||
artists = []
|
||||
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
|
||||
print(episode_artists[i])
|
||||
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_duration=episode_duration)
|
||||
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.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)
|
||||
|
||||
|
||||
def create_html_episode_from_template(episode_playlist):
|
||||
def create_html_episode_from_template(episode_playlist, episode_number):
|
||||
|
||||
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')
|
||||
|
||||
show_info = []
|
||||
playlist_table = []
|
||||
|
||||
# maybe a jinja2 template loop here instead
|
||||
cursor = conn.cursor()
|
||||
|
@ -444,26 +452,29 @@ def create_html_episode_from_template(episode_playlist):
|
|||
r = cursor.fetchall()
|
||||
for t in r:
|
||||
song = str(t[0])
|
||||
#track_label = str(t[1])
|
||||
track_album = str(t[3])
|
||||
track_title = str(t[4])
|
||||
track_artist = str(t[5]).upper()
|
||||
track_duration = float(t[6])
|
||||
track_genre = str(t[7])
|
||||
track_year = str(t[8])
|
||||
track_label = str(t[10])
|
||||
track_comment = str(t[11])
|
||||
|
||||
detail = str(track_artist) + " | " + str(track_album) + \
|
||||
" | " + str(track_title) + " | " + str(track_year) + \
|
||||
" | " + 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)
|
||||
|
||||
#TODO FIX THIS UP TO SEND COLUMNS FROM LIST TO JINJA
|
||||
|
||||
output_from_parsed_template = episode_template.render(\
|
||||
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_playlist=show_info, \
|
||||
episode_playlist=playlist_table, \
|
||||
episode_image="img/cover.png".format(episode_number))
|
||||
|
||||
with open("html/episode/{0}/index.html".format(episode_number), "w") as episode_page:
|
||||
|
@ -490,12 +501,12 @@ def main():
|
|||
|
||||
# database_create_episodes_table()
|
||||
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_animated_gif()
|
||||
create_intro(episode_playlist)
|
||||
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_RSS_XML_from_template()
|
||||
conn.close()
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
|
||||
Some Spatter Left
|
||||
The Mother (Act VII)
|
||||
Tilt - Tilt - 03 Alicante 3
|
||||
Hunahpu & Xbalanque
|
||||
Maskardh - Thrills Of Deconstruction
|
||||
Heretics Fork
|
||||
94
|
||||
Zlatko Kaučič, Tomaž Grom - The Ear Is The Shadow Of The Eye - 12 Battling For A Title - Za naslov se boriva
|
||||
Crossing The Rubicon
|
||||
šopscum solata
|
||||
YuWrong
|
||||
Action XIV
|
||||
things i decided against
|
||||
Domen Gnezda - Misnomer II - 02 Misnomer 24
|
||||
Crushing Trauma
|
||||
Nicholas Cage
|
||||
The Great White Buffalo
|
||||
Integral [Excerpt]
|
||||
Slika 4
|
||||
Tomaž Grom - Sam, za... - 05 G.V.
|
||||
Styröfoam - Moonmiles
|
||||
The Oppressed 1 (Outtake)
|
||||
|
|
Loading…
Reference in New Issue