sqlite deals now with playlist generation etc

main
Rob Canning 2024-01-18 14:07:57 +01:00
parent cc1c3a8507
commit 2715358487
4 changed files with 97 additions and 77 deletions

Binary file not shown.

View File

@ -12,12 +12,12 @@ conn = ''
music_library_path = "/home/rob/antena/music/" music_library_path = "/home/rob/antena/music/"
conn = sqlite3.connect("database/show.db") conn = sqlite3.connect("database/show.db")
labelnames = ["sploh", "terraformer", "pharamafabric" ] #TODO fix getting bandcamp urls into db
labelnames = [("sploh", "https://sploh.bandcamp.com"), ("terraformer"), ("pharamafabric") ]
def database_create(conn): def database_create(conn):
# the MUSIC LIBRARY TABLE # 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( conn.execute('''CREATE TABLE IF NOT EXISTS MUSICLIB(
ID INTEGER PRIMARY KEY AUTOINCREMENT, ID INTEGER PRIMARY KEY AUTOINCREMENT,
LABEL TEXT NOT NULL, LABEL TEXT NOT NULL,
@ -28,19 +28,21 @@ def database_create(conn):
TRACKDUR TEXT , TRACKDUR TEXT ,
YEAR TEXT, YEAR TEXT,
URL TEXT, URL TEXT,
PATH TEXT , PATH TEXT UNIQUE,
LASTPLAY TEXT, LASTPLAY TEXT,
COMMENT TEXT COMMENT TEXT
);''') );''')
print("Table created successfully"); print("Table created successfully");
####################################################### #######################################################
def mk_db_entry(conn): def mk_db_entry(conn):
import os import os
label_url = "https://fixme.bandcamp.com/" label_url = "https://fixme.bandcamp.com/"
for subdir, dirs, files in os.walk(music_library_path): for subdir, dirs, files in os.walk(music_library_path):
for file in files: for file in files:
for m in [".flac", ".FLAC", ".mp3"]: # get audio files for m in [".flac", ".FLAC", ".mp3"]: # get audio files
@ -50,7 +52,7 @@ def mk_db_entry(conn):
track = TinyTag.get(os.path.join(subdir, file))# get metadata from file track = TinyTag.get(os.path.join(subdir, file))# get metadata from file
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("INSERT INTO MUSICLIB (\ cursor.execute("INSERT OR IGNORE INTO MUSICLIB (\
ID, LABEL, ALBUM, TRACK, ARTIST,\ ID, LABEL, ALBUM, TRACK, ARTIST,\
GENRE, TRACKDUR, YEAR, URL, PATH, LASTPLAY, COMMENT) \ GENRE, TRACKDUR, YEAR, URL, PATH, LASTPLAY, COMMENT) \
VALUES (NULL, ?, ?, ?, ?,?, ?,?,?,?,?,? )",\ VALUES (NULL, ?, ?, ?, ?,?, ?,?,?,?,?,? )",\

View File

@ -60,7 +60,8 @@ def database_create():
ALBUM TEXT , ALBUM TEXT ,
TRACK TEXT NOT NULL, TRACK TEXT NOT NULL,
ARTIST TEXT NOT NULL, ARTIST TEXT NOT NULL,
TRACKDUR INT NOT NULL, TRACKDUR FLOAT NOT NULL,
GENRE TEXT NOT NULL,
YEAR TEXT NOT NULL, YEAR TEXT NOT NULL,
PATH TEXT NOT NULL PATH TEXT NOT NULL
);''') );''')
@ -88,19 +89,7 @@ def check_archive(track):
print("____ TRACK ALREADY PLAYED _____") print("____ TRACK ALREADY PLAYED _____")
return False return False
def load_all_music():
with open('playlists/complete_music_archive.pls') as playlist_file:
for line in playlist_file:
complete_playlist.append(line)
print('''
-------------------------------
loaded {0} tracks from playlist
-------------------------------
'''.format(str(len(complete_playlist))))
return complete_playlist
def create_episode_playlist(episode_playlist: list, complete_playlist:list): def create_episode_playlist(episode_playlist: list, complete_playlist:list):
load_all_music()
global episode_duration global episode_duration
global archive global archive
@ -113,49 +102,58 @@ def create_episode_playlist(episode_playlist: list, complete_playlist:list):
# TODO what is most important 12 tracks or 60 minutes # TODO what is most important 12 tracks or 60 minutes
while episode_duration < 60 * 60 and track_count < 12 : while episode_duration < 60 * 60 and track_count < 12 :
song = random.choice(random.sample(\ cursor = conn.cursor()
complete_playlist, len(complete_playlist) )).rstrip() # pick a song cursor.execute("SELECT * FROM MUSICLIB ORDER BY RANDOM() LIMIT 1 ;")
track = TinyTag.get(song) # get its metadata r = cursor.fetchall()
# check if the artist not in the played list and the song is less than 8mins 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])
track_path = '/'.join(song.split('/')[0:-1]) track_path = '/'.join(song.split('/')[0:-1])
if track.artist not in artists_played: if track_artist not in artists_played:
if check_archive(track.title) is True: if check_archive(track_title) is True:
if int(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
art = string=re.sub("\(.*?\)","",track.artist) art = string=re.sub("\(.*?\)","",track_artist)
# shorten verbose artist names such as trojnik Trojnik (Cene Resnik, Tomaž Grom, Vid Drašler) # shorten verbose artist names such as trojnik Trojnik (Cene Resnik, Tomaž Grom, Vid Drašler)
art = string=re.sub("and","&",art) art = string=re.sub("and","&",art)
artist_abreviated.append(art) artist_abreviated.append(art)
artists_played.append(track.artist) # and add the artist to the played list artists_played.append(track_artist) # and add the artist to the played list
add_to_tracks_played(track.title) # and write entry to archive file add_to_tracks_played(track_title) # and write entry to archive file
if not track.year: # where missing metadata give a dummy value if not track_year: # where missing metadata give a dummy value
track.year = 0000 track_year = 0000
cursor = conn.cursor()
#long_string = json.dumps(["' SomeWord"]) #long_string = json.dumps(["' SomeWord"])
print([episode_number, episode_date, \ print([episode_number, episode_date, \
track.album, track.title, track.artist, \ track_album, track_title, track_artist, \
track.duration, track.year, track_path]) track_duration, track_year, track_path])
cursor.execute("INSERT INTO SHOW (\ cursor.execute("INSERT INTO SHOW (\
ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \ ID, EPISODE, DATE, ALBUM, TRACK, ARTIST, TRACKDUR, YEAR, PATH) \
VALUES (NULL, ?, ?, ?, ?, ?,?,?,? )", [episode_number, episode_date, \ VALUES (NULL, ?, ?, ?, ?, ?,?,?,? )", [episode_number, episode_date, \
track.album, track.title, track.artist, \ track_album, track_title, track_artist, \
track.duration, track.year, track_path]); track_duration, track_year, track_path]);
conn.commit() conn.commit()
print("DB Record created successfully"); print("sqlite: Episode track successfully inserted into SHOW table");
track_count += 1; print(track_count) track_count += 1; print(track_count)
episode_duration = episode_duration + track.duration episode_duration = episode_duration + track_duration
else: print("TRACK TOO SHORT..........." ) else: print("TRACK TOO SHORT..........." )
else: print("TRACK TOO LONG..........." ) else: print("TRACK TOO LONG..........." )
else: print("SONG PLAYED IN PREVIOUS EPISODE" ) else: print("SONG PLAYED IN PREVIOUS EPISODE" )
else: print("ARTIST ALREADY IN PODCAST") else: print("ARTIST ALREADY IN PODCAST")
conn.close() #
episode_duration = timedelta(seconds=round(episode_duration)) episode_duration = timedelta(seconds=round(episode_duration))
@ -265,11 +263,9 @@ def create_show_coverart(episode_playlist, variants):
# if len(show_cover_jpgs) > 0: # duplicate this for variations of geometry # if len(show_cover_jpgs) > 0: # duplicate this for variations of geometry
for i in range(variants): for i in range(variants):
x = show_cover_jpgs[:12] x = show_cover_jpgs[:12]
combine_images(columns=4, space=10, images=random.sample(x,len(x)),variants=i) combine_images(columns=4, space=10, images=random.sample(x,len(x)),variants=i)
return show_cover return show_cover
def create_animated_gif(): def create_animated_gif():
import contextlib import contextlib
from PIL import Image from PIL import Image
@ -377,15 +373,15 @@ def create_html_homepage_from_template(episode_playlist):
homepage_template = env.get_template('homepage.jinja') homepage_template = env.get_template('homepage.jinja')
conn = sqlite3.connect("database/show.db") conn = sqlite3.connect("database/show.db")
cur = conn.cursor() cursor = conn.cursor()
show_info = [] show_info = []
episode_artists = [] episode_artists = []
for i in range(10): for i in range(10):
artists = [] artists = []
cur.execute("SELECT ARTIST FROM SHOW WHERE EPISODE=?", [i]) cursor.execute("SELECT ARTIST FROM SHOW WHERE EPISODE=?", [i])
rows = cur.fetchall() rows = cursor.fetchall()
for artist in rows: for artist in rows:
art = string=re.sub("\(.*?\)","", artist[0]) art = string=re.sub("\(.*?\)","", artist[0])
@ -404,19 +400,24 @@ def create_html_homepage_from_template(episode_playlist):
episodes.append(an_episode) episodes.append(an_episode)
episodes = reversed(episodes) # reversed order to most recent episode appears first in list episodes = reversed(episodes) # reversed order to most recent episode appears first in list
#TODO get database sorted - music table with metadata, bandcamp, label info cursor = conn.cursor()
cur.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number]) cursor.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number])
# database query instead of the below r = cursor.fetchall()
# maybe a jinja2 template loop here instead for t in r:
for i in episode_playlist: # liar od files song = str(t[0])
#for i in cur: # liar od files 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 = TinyTag.get(i) detail = str(track_artist) + " | " + str(track_album) + \
detail = str(track.artist) + " | " + str(track.album) + \ " | " + str(track_title) + " | " + str(track_year) + \
" | " + str(track.title) + " | " + str(track.year) + \ " | " + str(timedelta(seconds=round(track_duration)))
" | " + str(timedelta(seconds=round(track.duration)))
show_info.append("" + detail) show_info.append("" + detail)
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), \
episodes=episodes, episode_author="Rob Canning",\ episodes=episodes, episode_author="Rob Canning",\
@ -439,11 +440,26 @@ def create_html_episode_from_template(episode_playlist):
show_info = [] show_info = []
# maybe a jinja2 template loop here instead # maybe a jinja2 template loop here instead
for i in episode_playlist: cursor = conn.cursor()
track = TinyTag.get(i) cursor.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number])
detail = str(track.artist) + " | " + str(track.album) + \ r = cursor.fetchall()
" | " + str(track.title) + " | " + str(track.year) + \ for t in r:
" | " + str(timedelta(seconds=round(track.duration))) 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_duration = float(t[6])
track_genre = str(t[5])
track_year = str(t[7])
# 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) show_info.append("" + detail)
output_from_parsed_template = episode_template.render(\ output_from_parsed_template = episode_template.render(\
@ -485,11 +501,13 @@ create_show_coverart(episode_playlist, 1) #episode_duration = 100
create_intro(episode_playlist) create_intro(episode_playlist)
create_pls_file() create_pls_file()
create_html_episode_from_template(episode_playlist)
create_html_homepage_from_template(episode_playlist) create_html_homepage_from_template(episode_playlist)
create_html_episode_from_template(episode_playlist)
create_RSS_XML_from_template() create_RSS_XML_from_template()
#create_podcast(episode_playlist) conn.close()
create_podcast(episode_playlist)
#convert -delay 100 -loop 0 html/episode/2/img/show_cover_2024-01-12* animatedGIF.gif #convert -delay 100 -loop 0 html/episode/2/img/show_cover_2024-01-12* animatedGIF.gif

View File

@ -1,13 +1,13 @@
Speshlafer 一点一滴
Tomaž Grom - Sam, za... - 09 N.N. BE CREEP - LIVE
YuWrong Todestriebe
Vertex The Great White Buffalo
Carve4 Liqweed
Dromon Keep An Eye On That Ice Cream
Blue Waters Turn Black (P.C.M. remix) Kaverna
Cifre (feat. Eno) Jošt Drašler - The Balloon Catcher - 03 Water Balloon
Lynch - Oro zatvorenih očiju Magie de la Pleine Lune
KIURIKI - Killem All Domen Gnezda - Misnomer II - 16 Misnomer 38
postcell (Tetsuo remix) All is silent, All is dead
Stampede Exit Lover