diff --git a/database/show.db b/database/show.db index a48a537..4d6f5a9 100644 Binary files a/database/show.db and b/database/show.db differ diff --git a/html/templates/episode.jinja b/html/templates/episode.jinja index 992d040..6bb195d 100644 --- a/html/templates/episode.jinja +++ b/html/templates/episode.jinja @@ -116,8 +116,8 @@ -
# | TRACK | diff --git a/mk_music_library_db.py b/mk_music_library_db.py index eb514e2..371cbe3 100755 --- a/mk_music_library_db.py +++ b/mk_music_library_db.py @@ -81,9 +81,7 @@ def database_create_episodes_table(conn): Column("comment", "VARCHAR(120)", nullable=False))\ .unique("id") \ .primary_key("id") - - #TODO get the unique path back into action find bug conn.execute(str(q)) print("EPISODES Table created successfully"); diff --git a/mk_show.py b/mk_show.py index bd7fd11..d8a0141 100755 --- a/mk_show.py +++ b/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): - - global archive +def check_archive(track_path): + 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 - print('new suggestion================================' + str(r)) - # for t in r: + r = cursor.fetchone() # FETCH A NEW TRACK FROM THE DATABASE + print('new suggestion================================' + str(r)) + song = str(r[9]) track_label = str(r[1]) 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 # TODO here we need to append to DB not the static file - if track_artist not in artists_played: - if check_archive(track_path) is True: + # 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: 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 # 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],)) - - dj_is_unsure=True + 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,16 +495,17 @@ 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 = reversed(episodes[1:episode_number]) + cursor = conn.cursor() cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number]) r = cursor.fetchall() @@ -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,11 +528,10 @@ 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): @@ -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() -#