user input() to preview/modify episode playlist
parent
9181ae9f2d
commit
1af505cef5
BIN
database/show.db
BIN
database/show.db
Binary file not shown.
|
@ -117,7 +117,7 @@
|
|||
<!-- <p><b> {{track}} </b> </p> -->
|
||||
<!-- {% endfor %} -->
|
||||
<table class="table table-striped">
|
||||
|
||||
<img src="{{episode_image}}" width="500"/>
|
||||
<!-- <TD class="c1"><IMG src="favicon.ico"></TD> -->
|
||||
<TD class="c0"><b>#</b></TD>
|
||||
<TD class="c1"><b>TRACK</b></TD>
|
||||
|
|
|
@ -82,8 +82,6 @@ def database_create_episodes_table(conn):
|
|||
.unique("id") \
|
||||
.primary_key("id")
|
||||
|
||||
|
||||
#TODO get the unique path back into action find bug
|
||||
conn.execute(str(q))
|
||||
print("EPISODES Table created successfully");
|
||||
|
||||
|
|
153
mk_show.py
153
mk_show.py
|
@ -53,46 +53,53 @@ def create_intro(episode_playlist):
|
|||
intro = random.choice(os.listdir(intropath))
|
||||
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.execute("SELECT * FROM EPISODES WHERE path = ?", (track,))
|
||||
cursor.execute("SELECT * FROM EPISODES WHERE path = ?", (track_path,))
|
||||
data=cursor.fetchone()
|
||||
|
||||
if data is None:
|
||||
print('')
|
||||
#print('There is no component named ?', [track])
|
||||
return True # no previous play record found... the track can be added
|
||||
else:
|
||||
print('Component ? found with rowid ? /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////', [track, 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 _____")
|
||||
print('Track has been played on a previous episode', [track_path, data[0]])
|
||||
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):
|
||||
cursor = conn.cursor()
|
||||
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))
|
||||
# for t in r:
|
||||
|
||||
song = str(r[9])
|
||||
track_label = str(r[1])
|
||||
track_album = str(r[2])
|
||||
|
@ -157,7 +164,9 @@ def create_episode_playlist(conn, episode_playlist: list, episode_number):
|
|||
# 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 track_artist not in artists_played:
|
||||
|
||||
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 int(track_duration) < max_track_dur * 60:
|
||||
|
@ -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
|
||||
# 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.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
|
||||
preview = cursor.fetchall()
|
||||
print("/////////////////////////////////////////////////")
|
||||
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
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
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':
|
||||
print("action")
|
||||
|
@ -227,28 +247,19 @@ def create_episode_playlist(conn, episode_playlist: list, episode_number):
|
|||
else:
|
||||
input("do the db replace logic")
|
||||
playlist_replace_track(conn, episode_playlist, episode_number, preview_track)
|
||||
elif user_input == 's':
|
||||
print("the logic to shuffle the existing playlist order")
|
||||
|
||||
|
||||
else:
|
||||
print("Goodbye happy dj")
|
||||
|
||||
print("Goodbye happy DJ")
|
||||
|
||||
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))
|
||||
# print("Total Tracks = {0} \nTotal Duration = {1}".format(track_count, episode_duration))
|
||||
|
||||
|
||||
def combine_images(columns, space, images, variants:int):
|
||||
global show_cover
|
||||
|
||||
|
@ -452,7 +463,7 @@ def create_podcast(episode_playlist: list):
|
|||
|
||||
### ------------------------------------------------------------
|
||||
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
|
||||
|
||||
env = Environment(loader=FileSystemLoader('html/templates'))
|
||||
|
@ -461,16 +472,15 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
conn = sqlite3.connect("database/show.db")
|
||||
cursor = conn.cursor()
|
||||
|
||||
show_info = []
|
||||
episode_artists = []
|
||||
|
||||
#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])
|
||||
|
@ -485,15 +495,16 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
|
||||
episodes = []
|
||||
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-", \
|
||||
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_duration=episode_duration)
|
||||
episodes.append(an_episode)
|
||||
episodes = reversed(episodes[1:episode_number])
|
||||
# reversed order to most recent episode appears first in list
|
||||
|
||||
episodes.append(an_episode)
|
||||
# reversed order to most recent episode appears first in list
|
||||
episodes = reversed(episodes[1:episode_number])
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number])
|
||||
|
@ -510,10 +521,6 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
track_genre = str(t[8])
|
||||
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
|
||||
output_from_parsed_template = homepage_template.render(\
|
||||
show_name=''.join(random.choice((str.upper,str.lower))(x) for x in show_name), \
|
||||
|
@ -521,12 +528,11 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
episode_duration=episode_duration, episode_number=episode_number, \
|
||||
episode_artists=str(episode_artists[episode_number]).strip("[").strip("]").strip("\'").strip("'"), \
|
||||
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:
|
||||
episode_page.write(output_from_parsed_template)
|
||||
|
||||
|
||||
def create_html_episode_from_template(episode_playlist, episode_number):
|
||||
|
||||
from jinja2 import Template, Environment, FileSystemLoader
|
||||
|
@ -534,7 +540,7 @@ def create_html_episode_from_template(episode_playlist, episode_number):
|
|||
env = Environment(loader=FileSystemLoader('html/templates'))
|
||||
episode_template = env.get_template('episode.jinja')
|
||||
|
||||
show_info = []
|
||||
|
||||
playlist_table = []
|
||||
|
||||
# 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_comment = str(t[12])
|
||||
|
||||
detail = str(track_artist) + " | " + str(track_album) + \
|
||||
" | " + str(track_title) + " | " + str(track_year) + \
|
||||
" | " + str(timedelta(seconds=round(track_duration)))
|
||||
playlist_entry = [track_number, track_title, track_artist, track_album, track_year, timedelta(seconds=round(track_duration)), track_label.upper() ]
|
||||
|
||||
playlist_entry = [track_number, 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)
|
||||
|
||||
|
||||
output_from_parsed_template = episode_template.render(\
|
||||
show_name=show_name, episode_author="Rob Canning",\
|
||||
episode_number=episode_number, episode_duration=episode_duration, \
|
||||
episode_date=episode_date, about_show=show_short_description, \
|
||||
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:
|
||||
episode_page.write(output_from_parsed_template)
|
||||
|
@ -591,29 +599,15 @@ def create_RSS_XML_from_template():
|
|||
show_name=show_name, \
|
||||
episode_number=int(episode_number), episode_author="Rob Canning",\
|
||||
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:
|
||||
rss_page.write(output_from_parsed_template)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
set_episode_date(input_date)
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# modify_playlist(conn, episode_playlist, episode_number)
|
||||
|
||||
|
||||
create_show_coverart(episode_playlist, 4) #episode_duration = 100
|
||||
#create_animated_gif()
|
||||
create_intro(episode_playlist)
|
||||
|
@ -625,4 +619,3 @@ def main():
|
|||
|
||||
main()
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue