diff --git a/create_show.py b/create_show.py index 69aedb8..0059365 100755 --- a/create_show.py +++ b/create_show.py @@ -1,5 +1,4 @@ #!/usr/bin/python3 - import os, random, time from tinytag import TinyTag import datetime @@ -8,107 +7,116 @@ from datetime import timedelta from random import shuffle DATE = datetime.datetime.now().strftime("%Y-%m-%d") - -kamizdat_playlist = [] -sploh_playlist = [] -trf_playlist = [] -complete_playlist = [] - +total_show_duration = 0 show_array = [] -show_info = [] +show_cover = "---" +archive = [] -# open master playlist - -with open('music/kamizdat_flac.pls') as playlist_file: - for line in playlist_file: - kamizdat_playlist.append(line) - -with open('music/terraformer_research_facilities.pls') as playlist_file: - for line in playlist_file: - trf_playlist.append(line) - -with open('music/complete.pls') as playlist_file: - for line in playlist_file: - complete_playlist.append(line) - # ///////////////////////////////////////////////// -intropath = "/home/rob/antena/texts/clips/u_have_been" -intro = random.choice(os.listdir(intropath)) -show_array.append(str(os.path.abspath(intropath)) + "/" + str(intro)) +def create_intro(): + intropath = "/home/rob/antena/texts/clips/u_have_been" + intro = random.choice(os.listdir(intropath)) + show_array.append(str(os.path.abspath(intropath)) + "/" + str(intro)) -# //// =================================== +def add_to_tracks_played(add_to_played: str): + #global complete_tracks_played + with open('music/tracks_played.pls', "a") as tracks_played_file: + tracks_played_file.write(add_to_played + "\n") -# selector of non-long tracks by various artists - no artist duplication +def check_archive(): + global archive + with open('music/tracks_played.pls') as archive_file: + for line in archive_file: + archive.append(line) + return archive + +def create_playlist(show_array: list): + global total_show_duration + global archive + complete_playlist = [] -total_show_duration = 0 -track_count = 0 -artist_played = [] -maxTrackDur = 12 - -while total_show_duration < 60 * 60: - - song = random.choice(random.sample(complete_playlist, len(complete_playlist) )).rstrip() # pick a song - track = TinyTag.get(song) # get its metadata + track_count = 0 + artist_played = [] + max_track_dur = 12 - # check if the artist not in the played list and the song is less than 8mins + with open('music/complete.pls') as playlist_file: + for line in playlist_file: + complete_playlist.append(line) + + while total_show_duration < 60 * 58: + song = random.choice(random.sample(complete_playlist, len(complete_playlist) )).rstrip() # pick a song + track = TinyTag.get(song) # get its metadata + # check if the artist not in the played list and the song is less than 8mins + check_archive() - if track.artist not in artist_played and int(track.duration) < maxTrackDur*60: + if track.artist not in artist_played \ + and track.title not in archive \ + and int(track.duration) < max_track_dur * 60: show_array.append(song.rstrip()) # if 'not in' is true then add the song artist_played.append(track.artist) # and add the artist to the played list + add_to_tracks_played(track.title) # and write entry to archive file + track_count += 1 total_show_duration = total_show_duration + track.duration - print(track_count) - -print(artist_played) - - -#for i in random.sample(trf_playlist, 8): -# show_array.append(i.rstrip()) - -print(show_array) - -# remove any duplicates -show_array = list(set(show_array)) - -# ///////////////////////////////////////////////// -# create a markdown file containing show information + else: print("inclusion conditions not met...................... " + str(track)) + total_show_duration = timedelta(seconds=round(total_show_duration)) + show_array = list(set(show_array)) + print("total tracks = " + str(track_count)) + print("total duration = " + str(total_show_duration)) + return show_array, total_show_duration -for i in show_array: - track = TinyTag.get(i) - detail = str(track.artist) + " | " + str(track.album) + \ - " | " + str(track.title) + " | " + str(track.year) + " | " + str(timedelta(seconds=round(track.duration))) - show_info.append("" + detail) +def find_show_coverart(show_array:list): + global show_cover + cover = random.choice(show_array) + cover = '/'.join(cover.split('/')[:-1]) + show_cover = str(cover + "/cover.jpg") + print("cover is ...." + show_cover) + return show_cover -total_show_duration = timedelta(seconds=round(total_show_duration)) +def create_web_page(show_array:list): + show_info = [] + find_show_coverart(show_array) + global total_show_duration + print(show_array) -with open("shows/antena_showinfo_" + DATE + ".html","w") as file: - - file.write(''' - -
-" + x + "
" +" \n " ) - - file.writelines("") - -file.close() + # create a HTML file containing show information + for i in show_array: + track = TinyTag.get(i) + detail = str(track.artist) + " | " + str(track.album) + \ + " | " + str(track.title) + " | " + str(track.year) + \ + " | " + str(timedelta(seconds=round(track.duration))) + show_info.append("" + detail) + print(show_info) + #total_show_duration = 100 + + with open("shows/antena_showinfo_" + DATE + ".html","w") as file: + file.write(''' + + +" + x + "
" +" \n " ) + file.writelines("") + file.close() +def create_pls(): # write the selection as a playlist file -with open("shows/antena_playlist_" + DATE + ".pls","w") as file: - file.writelines(" \n ".join(show_array)) - + with open("shows/antena_playlist_" + DATE + ".pls","w") as file: + file.writelines(" \n ".join(show_array)) + +create_playlist(show_array) +create_web_page(show_array)