diff --git a/database/show.db b/database/show.db index 0bcd59e..6b52de3 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 c7c9132..93471b1 100644 --- a/html/templates/episode.jinja +++ b/html/templates/episode.jinja @@ -107,14 +107,35 @@ + + + + + +

This weeks playlist:

- {% for track in episode_playlist[1:] %} - -

{{track}}

-
+ {% for track in episode_playlist[0:] %} +

{{track}}

{% endfor %} + + + + + + + + + + + + + + + + +
diff --git a/mk_music_library_db.py b/mk_music_library_db.py index a01235a..7a9300d 100755 --- a/mk_music_library_db.py +++ b/mk_music_library_db.py @@ -7,6 +7,9 @@ from tinytag import TinyTag from random import shuffle import sqlite3, json import uuid +#import pypika # sql query builder +from pypika import Query, Table, Field, Column + conn = '' music_library_path = "/home/rob/antena/music/" @@ -15,35 +18,37 @@ conn = sqlite3.connect("database/show.db") #TODO fix getting bandcamp urls into db labelnames = [("sploh", "https://sploh.bandcamp.com"), ("terraformer"), ("pharamafabric") ] +# todo find album with no album name +mus_lib = Query \ + .create_table("MUSIC_LIBRARY") \ + .columns( + Column("id", "INT", nullable=True), + Column("label", "VARCHAR(100)", nullable=True), + Column("album", "VARCHAR(100)", nullable=True), + Column("track", "VARCHAR(200)", nullable=True), + Column("artist", "VARCHAR(120)", nullable=True), + Column("genre", "VARCHAR(120)", nullable=True), + Column("trackdur", "FLOAT", nullable=True), + Column("year", "INT", nullable=True), + Column("url", "VARCHAR(120)", nullable=True), + Column("path", "VARCHAR(120)", nullable=False), + Column("lastplay", "DATETINE", nullable=True), + Column("comment", "VARCHAR(120)", nullable=True))\ + .unique("path") \ + .primary_key("path") + def database_create(conn): # the MUSIC LIBRARY TABLE #TODO UNIQUE constraint prevents duplicats but what if tracks are in another locaton?fixme - conn.execute('''CREATE TABLE IF NOT EXISTS MUSICLIB( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - LABEL TEXT NOT NULL, - ALBUM TEXT , - TRACK TEXT , - ARTIST TEXT , - GENRE TEXT , - TRACKDUR TEXT , - YEAR TEXT, - URL TEXT, - PATH TEXT UNIQUE, - LASTPLAY TEXT, - COMMENT TEXT - );''') - - print("Table created successfully"); - -####################################################### + conn.execute(str(mus_lib)) + print('''MUSIC LIBRARY Table created successfully'''); def mk_db_entry(conn): - - import os - + print("ADDING TRACKS TO DATABASE > > > one moment please! "); label_url = "https://fixme.bandcamp.com/" - + for subdir, dirs, files in os.walk(music_library_path): + for file in files: for m in [".flac", ".FLAC", ".mp3"]: # get audio files if m in file: @@ -51,26 +56,32 @@ def mk_db_entry(conn): label = filepath.parts[5] # get LABEL etc name from path track = TinyTag.get(os.path.join(subdir, file))# get metadata from file cursor = conn.cursor() - - cursor.execute("INSERT OR IGNORE INTO MUSICLIB (\ - ID, LABEL, ALBUM, TRACK, ARTIST,\ - GENRE, TRACKDUR, YEAR, URL, PATH, LASTPLAY, COMMENT) \ - VALUES (NULL, ?, ?, ?, ?,?, ?,?,?,?,?,? )",\ - [label, track.album, track.title, track.artist, \ - track.genre, track.duration, track.year, label_url, str(filepath), "last_played", track.comment]); + + 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) + cursor.execute(str(q)); conn.commit() - # print("DB Record created successfully"); - - # 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 insert_track(conn, track): + +def count_tracks(conn): + query = f"SELECT COUNT(*) FROM MUSIC_LIBRARY" + cursor = conn.cursor() + cursor.execute(query) + result = cursor.fetchone() + row_count = result[0] + print(f'''\n WHOOP! THE MUSIC LIBRARY CONTAINS {row_count} TRACKS!! +--------------------------------------------''') - -database_create(conn) -mk_db_entry(conn) +def main(): + + database_create(conn) + mk_db_entry(conn) + count_tracks(conn) + +if __name__ == "__main__": + main() + + diff --git a/mk_show.py b/mk_show.py index 82a101d..e85c889 100755 --- a/mk_show.py +++ b/mk_show.py @@ -7,6 +7,7 @@ from tinytag import TinyTag from random import shuffle import sqlite3, json import uuid +from pypika import Query, Table, Field, Column #from mk_web import * @@ -44,29 +45,47 @@ def set_episode_date(input_date): print(episode_date) conn = '' -def database_create(): +def database_create_episodes_table(): # the show database global conn conn = sqlite3.connect("database/show.db") - #cursor = conn.cursor() - #cursor.execute("DROP TABLE SHOW") - #conn.commit() + q = Query \ + .create_table("EPISODES") \ + .columns( + Column("id", "INT", nullable=True), + Column("episode", "INT", nullable=True), + Column("date", 'DATETIME', nullable=True), + Column("album", "VARCHAR(200)", nullable=True), + Column("track", "VARCHAR(120)", nullable=True), + Column("artist", "VARCHAR(120)", nullable=True), + Column("trackdur", "FLOAT", nullable=True), + Column("genre", "VARCHAR(120)", nullable=True), + Column("year", 'DATETIME', nullable=True), + Column("path", "VARCHAR(120)", nullable=False))\ + .primary_key("path") + #.unique("path") \ + #TODO get the unique path back into action find bug + conn.execute(str(q)) + + + + + print("EPISODES Table created successfully"); + + + + + + + + + + + + - conn.execute('''CREATE TABLE IF NOT EXISTS SHOW( - ID INTEGER PRIMARY KEY AUTOINCREMENT, - EPISODE INT NOT NULL, - DATE TEXT NOT NULL, - ALBUM TEXT , - TRACK TEXT NOT NULL, - ARTIST TEXT NOT NULL, - TRACKDUR FLOAT NOT NULL, - GENRE TEXT NOT NULL, - YEAR TEXT NOT NULL, - PATH TEXT NOT NULL - );''') - print("Table created successfully"); def create_intro(episode_playlist): intropath = path + "audio/texts/clips/this_is" @@ -104,25 +123,31 @@ def create_episode_playlist(episode_playlist: list, complete_playlist:list): while episode_duration < 60 * 60 and track_count < 12 : cursor = conn.cursor() - cursor.execute("SELECT * FROM MUSICLIB ORDER BY RANDOM() LIMIT 1 ;") - r = cursor.fetchall() - for t in r: - song = str(t[9]) - track_label = str(t[1]) - track_album = str(t[2]) - track_title = str(t[3]) - track_artist = str(t[4]) - track_duration = float(t[6]) - track_genre = str(t[5]) - track_year = str(t[7]) - + cursor.execute("SELECT * FROM MUSIC_LIBRARY ORDER BY RANDOM() LIMIT 1 ;") + r = cursor.fetchone() # FETCH ONE RANDOM TRACK FROM THE DATABASE + print(str(r)+"ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss") + # for t in r: + song = str(r[9]) + track_label = str(r[1]) + track_album = str(r[2]) + track_title = str(r[3]) + track_artist = str(r[4]) + track_duration = float(r[6]) + track_genre = str(r[5]) + track_year = str(r[7]) track_path = '/'.join(song.split('/')[0:-1]) + + # 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: 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 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) @@ -133,17 +158,16 @@ def create_episode_playlist(episode_playlist: list, complete_playlist:list): track_year = 0000 - #long_string = json.dumps(["' SomeWord"]) - - print([episode_number, episode_date, \ - track_album, track_title, track_artist, \ - track_duration, track_year, track_path]) + 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) - cursor.execute("INSERT INTO SHOW (\ - ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \ - VALUES (NULL, ?, ?, ?, ?, ?,?,?,? )", [episode_number, episode_date, \ - track_album, track_title, track_artist, \ - track_duration, track_year, track_path]); + cursor.execute(str(q)) + # ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \ + # VALUES (NULL, ?, ?, ?, ?, ?,?,?,? )", [episode_number, episode_date, \ + # track_album, track_title, track_artist, \ + # track_duration, track_year, track_path]); conn.commit() print("sqlite: Episode track successfully inserted into SHOW table"); @@ -219,7 +243,7 @@ def combine_images(columns, space, images, variants:int): [len(s) for s in [''.join(artist_abreviated[6:9])]][0] > str_length_thresh or \ [len(s) for s in [''.join(artist_abreviated[9:12])]][0] > str_length_thresh: print('''one of the lines is longer than fits the page... - ...................shuffling the list for a better look''') + ...................shuffling the list for a better look: {0}'''.format(artist_abreviated)) random.shuffle(artist_abreviated) @@ -353,13 +377,14 @@ def create_podcast(episode_playlist: list): # get length of final show / podcast playlist_length = len(playlist) / (1000*60) - # save the entire poidcast + # save the entire poidcast as FLAC # with open("html/episode/{0}/show.flac".format(episode_number), 'wb') as out_f: # print("FLAC output file opened...writing to file...") # playlist.export(out_f, format='flac') # print("FLAC audio file exported...") - + + # save the entire poidcast as MP3 with open("html/episode/{0}/show.mp3".format(episode_number), 'wb') as out_f: print("MP3 output file opened...writing to file...") playlist.export(out_f, format='mp3') @@ -381,7 +406,7 @@ def create_html_homepage_from_template(episode_playlist): episode_artists = [] for i in range(10): artists = [] - cursor.execute("SELECT ARTIST FROM SHOW WHERE EPISODE=?", [i]) + cursor.execute("SELECT artist FROM EPISODES WHERE episode=?", [i]) rows = cursor.fetchall() for artist in rows: @@ -402,17 +427,18 @@ def create_html_homepage_from_template(episode_playlist): episodes = reversed(episodes) # reversed order to most recent episode appears first in list cursor = conn.cursor() - cursor.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number]) + cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number]) r = cursor.fetchall() + for t in r: song = str(t[0]) - track_label = str(t[1]) + #track_label = str(t[1]) track_album = str(t[2]) track_title = str(t[3]) track_artist = str(t[4]) track_duration = float(t[6]) - track_genre = str(t[5]) - track_year = str(t[7]) + track_genre = str(t[7]) + track_year = str(t[8]) detail = str(track_artist) + " | " + str(track_album) + \ " | " + str(track_title) + " | " + str(track_year) + \ @@ -442,27 +468,33 @@ def create_html_episode_from_template(episode_playlist): # maybe a jinja2 template loop here instead cursor = conn.cursor() - cursor.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number]) + + e = Table('EPISODES') + q = Query.from_(e).select( + e.episode + ).where( + e.episode == episode_number) +# raw 'SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number] + cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number]) + r = cursor.fetchall() for t in r: song = str(t[0]) - track_label = str(t[1]) - track_album = str(t[2]) - track_title = str(t[3]) - track_artist = str(t[4]) + #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[5]) - track_year = str(t[7]) + track_genre = str(t[7]) + track_year = str(t[8]) - # for i in episode_playlist: # liar od files - #for i in cur: # liar od files - - #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) + #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, \ @@ -490,25 +522,29 @@ def create_RSS_XML_from_template(): +def main(): -database_create() - -set_episode_date(input_date) -create_episode_playlist(episode_playlist, complete_playlist) -create_show_coverart(episode_playlist, 1) #episode_duration = 100 -#create_animated_gif() + database_create_episodes_table() + set_episode_date(input_date) + create_episode_playlist(episode_playlist, complete_playlist) + 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_homepage_from_template(episode_playlist) + create_RSS_XML_from_template() + conn.close() + create_podcast(episode_playlist) -create_intro(episode_playlist) -create_pls_file() -create_html_homepage_from_template(episode_playlist) -create_html_episode_from_template(episode_playlist) -create_RSS_XML_from_template() -conn.close() -create_podcast(episode_playlist) +main() + + + #convert -delay 100 -loop 0 html/episode/2/img/show_cover_2024-01-12* animatedGIF.gif diff --git a/playlists/track_playout_history.txt b/playlists/track_playout_history.txt index 3735aff..d4290f3 100644 --- a/playlists/track_playout_history.txt +++ b/playlists/track_playout_history.txt @@ -1,13 +1,13 @@ +Stampede +Vrtnice +zvoki iz dnevne sobe +jez +The Left Eye +NeoPogo - FeS2 +BE CREEP - Burnt Dreams +Zlatko Kaučič, Tomaž Grom - Torn Memories Of Folklore - Raztrgana folklora spomina - 08 Almost The Same +The Mother (Act VII) 一点一滴 -BE CREEP - LIVE -Todestriebe -The Great White Buffalo -Liqweed -Keep An Eye On That Ice Cream -Kaverna -Jošt Drašler - The Balloon Catcher - 03 Water Balloon -Magie de la Pleine Lune -Domen Gnezda - Misnomer II - 16 Misnomer 38 -All is silent, All is dead -Exit Lover +Jean-Luc Guionnet & Samo Kutin - Kopaš - 02 02 +Vertex diff --git a/runme.sh b/runme.sh index a0963e2..bf41a03 100755 --- a/runme.sh +++ b/runme.sh @@ -8,7 +8,7 @@ rm html/index.html show_dates=(2024-03-03 2024-03-10 2024-03-17 2024-03-24 2024-03-31 2024-03-31 2024-03-31 2024-03-31 2024-03-31 ) -counter= # set this as input argument to set what episode to start creating from... +counter=0 # set this as input argument to set what episode to start creating from... episodes=12 # set this as another input argument for how many episodes to produce