user input() to preview/modify episode playlist

main
Rob Canning 2024-01-23 02:24:05 +01:00
parent 9181ae9f2d
commit 1af505cef5
4 changed files with 81 additions and 90 deletions

Binary file not shown.

View File

@ -116,8 +116,8 @@
<!-- {% for track in episode_playlist[0:] %} --> <!-- {% for track in episode_playlist[0:] %} -->
<!-- <p><b> {{track}} </b> </p> --> <!-- <p><b> {{track}} </b> </p> -->
<!-- {% endfor %} --> <!-- {% endfor %} -->
<table class="table table-striped"> <table class="table table-striped">
<img src="{{episode_image}}" width="500"/>
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> --> <!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
<TD class="c0"><b>#</b></TD> <TD class="c0"><b>#</b></TD>
<TD class="c1"><b>TRACK</b></TD> <TD class="c1"><b>TRACK</b></TD>

View File

@ -81,9 +81,7 @@ def database_create_episodes_table(conn):
Column("comment", "VARCHAR(120)", nullable=False))\ Column("comment", "VARCHAR(120)", nullable=False))\
.unique("id") \ .unique("id") \
.primary_key("id") .primary_key("id")
#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");

View File

@ -53,46 +53,53 @@ def create_intro(episode_playlist):
intro = random.choice(os.listdir(intropath)) intro = random.choice(os.listdir(intropath))
episode_playlist.insert(0, str(os.path.abspath(intropath)) + "/" + str(intro)) episode_playlist.insert(0, str(os.path.abspath(intropath)) + "/" + str(intro))
# TODO make this go away....
#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): def check_archive(track_path):
global archive
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("SELECT * FROM EPISODES WHERE path = ?", (track,)) cursor.execute("SELECT * FROM EPISODES WHERE path = ?", (track_path,))
data=cursor.fetchone() data=cursor.fetchone()
if data is None: if data is None:
print('') return True # no previous play record found... the track can be added
#print('There is no component named ?', [track])
else: else:
print('Component ? found with rowid ? /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////', [track, data[0]]) print('Track has been played on a previous episode', [track_path, data[0]])
with open('playlists/track_playout_history.txt') as archive_file:
for line in archive_file:
archive.append(line)
if track not in archive:
#print("____ TRACK NOT YET PLAYED ... ADDING _____")
return True
else:
#print("____ TRACK ALREADY PLAYED _____")
return False return False
def check_album(track_album):
# check if album is played already on this episode - maybe last 2 episodes >= or similar
cursor = conn.cursor()
cursor.execute("SELECT * FROM EPISODES WHERE album = ? AND episode = ?", (track_album,episode_number))
data=cursor.fetchone()
if data is None:
return True # no previous play record found... the track can be added
else:
print('Album already featured on this episode ? ?', [track_album, data[0]])
return False
def check_artist(track_artist):
# check if artist is played already on this episode - maybe last 2 episodes >= or similar
cursor = conn.cursor()
cursor.execute("SELECT * FROM EPISODES WHERE artist = ? AND episode = ?", (track_artist,episode_number))
data=cursor.fetchone()
if data is None:
return True # no previous play record found... the artist can be added
else:
print('ARTIST already featured on this episode:', [track_artist, data[0]])
return False
def playlist_replace_track(conn, episode_playlist, episode_number, track_to_replace): def playlist_replace_track(conn, episode_playlist, episode_number, track_to_replace):
cursor = conn.cursor() 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 A NEW TRACK FROM THE DATABASE
print('new suggestion================================' + str(r)) print('new suggestion================================' + str(r))
# for t in r:
song = str(r[9]) song = str(r[9])
track_label = str(r[1]) track_label = str(r[1])
track_album = str(r[2]) track_album = str(r[2])
@ -157,8 +164,10 @@ def create_episode_playlist(conn, episode_playlist: list, episode_number):
# 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_path) is True:
if check_album(track_album) is True and check_artist(track_artist) is True:
if check_archive(track_path) is True:
if track_duration > min_track_dur * 60: if track_duration > min_track_dur * 60:
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
@ -194,20 +203,31 @@ def create_episode_playlist(conn, episode_playlist: list, episode_number):
#TODO am i happy with track selection? change an entry ? add a specific entry? to replace #TODO am i happy with track selection? change an entry ? add a specific entry? to replace
# preview and modify option -TODO move to its own function # preview and modify option -TODO move to its own function
modify_playlist(conn, episode_playlist, episode_number)
# TODO shuffle playlist order as an option
def modify_playlist(conn, episode_playlist, episode_number):
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number]) cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
preview = cursor.fetchall() preview = cursor.fetchall()
print("/////////////////////////////////////////////////")
for i in preview: for i in preview:
print('{0} : {1} {2} {3} {4}'.format(i[2], i[4], i[5], i[6], i[7],)) print('{0} : {1} {2} {3} {4} '.format(i[2], i[4], i[5], i[6], i[7],))
dj_is_unsure=True
dj_is_unsure=True
cursor = conn.cursor() cursor = conn.cursor()
if dj_is_unsure: if dj_is_unsure:
user_input = input("nice playlist? [y to proceed, anything else to suggest new] :") user_input = input('''nice playlist?
p = audio preview of a track + replace or not
y = generate a new playlist,
s = shuffle the existing playlist
r = replace an index with random OR specific
OR PRESS ENTER TO PROCEED....''')
if user_input == 'y': if user_input == 'y':
print("action") print("action")
@ -227,28 +247,19 @@ def create_episode_playlist(conn, episode_playlist: list, episode_number):
else: else:
input("do the db replace logic") input("do the db replace logic")
playlist_replace_track(conn, episode_playlist, episode_number, preview_track) playlist_replace_track(conn, episode_playlist, episode_number, preview_track)
elif user_input == 's':
print("the logic to shuffle the existing playlist order")
else: else:
print("Goodbye happy dj") print("Goodbye happy DJ")
return user_input return user_input
def modify_playlist(conn, episode_playlist, episode_number):
cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
preview = cursor.fetchall()
for i in preview:
print('{0} : {1} {2} {3} {4} \n'.format(i[2], i[4], i[5], i[6], i[7],))
# episode_duration = timedelta(seconds=round(episode_duration)) # episode_duration = timedelta(seconds=round(episode_duration))
# print("Total Tracks = {0} \nTotal Duration = {1}".format(track_count, episode_duration)) # print("Total Tracks = {0} \nTotal Duration = {1}".format(track_count, episode_duration))
def combine_images(columns, space, images, variants:int): def combine_images(columns, space, images, variants:int):
global show_cover global show_cover
@ -452,7 +463,7 @@ def create_podcast(episode_playlist: list):
### ------------------------------------------------------------ ### ------------------------------------------------------------
def create_html_homepage_from_template(episode_playlist): def create_html_homepage_from_template(episode_playlist):
# TODO "on this weeks show" varients fed to html from list here # TODO "on this weeks show" variants fed to html from list here
from jinja2 import Template, Environment, FileSystemLoader from jinja2 import Template, Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('html/templates')) env = Environment(loader=FileSystemLoader('html/templates'))
@ -461,16 +472,15 @@ def create_html_homepage_from_template(episode_playlist):
conn = sqlite3.connect("database/show.db") conn = sqlite3.connect("database/show.db")
cursor = conn.cursor() cursor = conn.cursor()
show_info = []
episode_artists = [] episode_artists = []
#TODO fix this - now it reports zero #TODO fix this - now it reports zero
# get number of episodes from DB # get number of episodes from DB
cursor.execute('SELECT MAX(episode) FROM EPISODES') cursor.execute('SELECT MAX(episode) FROM EPISODES')
num_eps = cursor.fetchone()[0] num_eps = cursor.fetchone()[0]
num_eps = num_eps+1 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])
@ -485,16 +495,17 @@ def create_html_homepage_from_template(episode_playlist):
episodes = [] episodes = []
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=str(episode_artists[i]).strip("[").strip("]").strip("\'"), 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[1:episode_number])
# reversed order to most recent episode appears first in list # reversed order to most recent episode appears first in list
episodes = reversed(episodes[1:episode_number])
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number]) cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number])
r = cursor.fetchall() r = cursor.fetchall()
@ -510,10 +521,6 @@ def create_html_homepage_from_template(episode_playlist):
track_genre = str(t[8]) track_genre = str(t[8])
track_year = str(t[9]) track_year = str(t[9])
detail = str(track_artist) + " | " + str(track_album) + \
" | " + str(track_title) + " | " + str(track_year) + \
" | " + str(timedelta(seconds=round(track_duration)))
show_info.append("" + detail)
#TODO remove single quptes not working in episode_artists #TODO remove single quptes not working in episode_artists
output_from_parsed_template = homepage_template.render(\ output_from_parsed_template = homepage_template.render(\
show_name=''.join(random.choice((str.upper,str.lower))(x) for x in show_name), \ show_name=''.join(random.choice((str.upper,str.lower))(x) for x in show_name), \
@ -521,11 +528,10 @@ def create_html_homepage_from_template(episode_playlist):
episode_duration=episode_duration, episode_number=episode_number, \ episode_duration=episode_duration, episode_number=episode_number, \
episode_artists=str(episode_artists[episode_number]).strip("[").strip("]").strip("\'").strip("'"), \ episode_artists=str(episode_artists[episode_number]).strip("[").strip("]").strip("\'").strip("'"), \
about_show=show_short_description, episode_playlist=episode_playlist, \ about_show=show_short_description, episode_playlist=episode_playlist, \
episode_image="episode/{0}/img/cover.png".format(episode_number)) episode_image="episode/{0}/img/cover0.png".format(episode_number))
with open("html/index.html".format(episode_number), "w") as episode_page: with open("html/index.html".format(episode_number), "w") as episode_page:
episode_page.write(output_from_parsed_template) episode_page.write(output_from_parsed_template)
def create_html_episode_from_template(episode_playlist, episode_number): def create_html_episode_from_template(episode_playlist, episode_number):
@ -534,7 +540,7 @@ def create_html_episode_from_template(episode_playlist, episode_number):
env = Environment(loader=FileSystemLoader('html/templates')) env = Environment(loader=FileSystemLoader('html/templates'))
episode_template = env.get_template('episode.jinja') episode_template = env.get_template('episode.jinja')
show_info = []
playlist_table = [] playlist_table = []
# maybe a jinja2 template loop here instead # maybe a jinja2 template loop here instead
@ -562,19 +568,21 @@ def create_html_episode_from_template(episode_playlist, episode_number):
track_label = str(t[11]) track_label = str(t[11])
track_comment = str(t[12]) track_comment = str(t[12])
detail = str(track_artist) + " | " + str(track_album) + \
" | " + str(track_title) + " | " + str(track_year) + \ playlist_entry = [track_number, track_title, track_artist,\
" | " + str(timedelta(seconds=round(track_duration))) track_album, track_year,\
playlist_entry = [track_number, track_title, track_artist, track_album, track_year, timedelta(seconds=round(track_duration)), track_label.upper() ] timedelta(seconds=round(track_duration)),\
track_label.upper() ]
playlist_table.append(playlist_entry) playlist_table.append(playlist_entry)
show_info.append("" + detail)
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_number=episode_number, 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=playlist_table, \ episode_playlist=playlist_table, \
episode_image="img/cover.png".format(episode_number)) episode_image="img/cover0.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:
episode_page.write(output_from_parsed_template) episode_page.write(output_from_parsed_template)
@ -591,29 +599,15 @@ def create_RSS_XML_from_template():
show_name=show_name, \ show_name=show_name, \
episode_number=int(episode_number), episode_author="Rob Canning",\ episode_number=int(episode_number), episode_author="Rob Canning",\
episode_duration=episode_duration, about_show=show_short_description, \ episode_duration=episode_duration, about_show=show_short_description, \
episode_image="img/cover.png".format(episode_number)) episode_image="img/cover0.png".format(episode_number))
with open("html/show_rss.xml".format(episode_number), "w") as rss_page: with open("html/show_rss.xml".format(episode_number), "w") as rss_page:
rss_page.write(output_from_parsed_template) rss_page.write(output_from_parsed_template)
def main(): def main():
set_episode_date(input_date) set_episode_date(input_date)
# while create_episode_playlist(conn, episode_playlist, episode_number) != 'y': # while create_episode_playlist(conn, episode_playlist, episode_number) != 'y':
# create_episode_playlist(conn, episode_playlist, episode_number) # create_episode_playlist(conn, episode_playlist, episode_number)
create_episode_playlist(conn, episode_playlist, episode_number) create_episode_playlist(conn, episode_playlist, episode_number)
# modify_playlist(conn, episode_playlist, episode_number)
create_show_coverart(episode_playlist, 4) #episode_duration = 100 create_show_coverart(episode_playlist, 4) #episode_duration = 100
#create_animated_gif() #create_animated_gif()
create_intro(episode_playlist) create_intro(episode_playlist)
@ -625,4 +619,3 @@ def main():
main() main()
#