sqlite deals now with playlist generation etc
parent
cc1c3a8507
commit
2715358487
BIN
database/show.db
BIN
database/show.db
Binary file not shown.
|
@ -12,12 +12,12 @@ conn = ''
|
|||
music_library_path = "/home/rob/antena/music/"
|
||||
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):
|
||||
|
||||
# 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,
|
||||
|
@ -28,19 +28,21 @@ def database_create(conn):
|
|||
TRACKDUR TEXT ,
|
||||
YEAR TEXT,
|
||||
URL TEXT,
|
||||
PATH TEXT ,
|
||||
PATH TEXT UNIQUE,
|
||||
LASTPLAY TEXT,
|
||||
COMMENT TEXT
|
||||
);''')
|
||||
|
||||
print("Table created successfully");
|
||||
|
||||
|
||||
#######################################################
|
||||
|
||||
def mk_db_entry(conn):
|
||||
|
||||
import os
|
||||
|
||||
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
|
||||
|
@ -50,7 +52,7 @@ def mk_db_entry(conn):
|
|||
track = TinyTag.get(os.path.join(subdir, file))# get metadata from file
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("INSERT INTO MUSICLIB (\
|
||||
cursor.execute("INSERT OR IGNORE INTO MUSICLIB (\
|
||||
ID, LABEL, ALBUM, TRACK, ARTIST,\
|
||||
GENRE, TRACKDUR, YEAR, URL, PATH, LASTPLAY, COMMENT) \
|
||||
VALUES (NULL, ?, ?, ?, ?,?, ?,?,?,?,?,? )",\
|
||||
|
|
130
mk_show.py
130
mk_show.py
|
@ -60,7 +60,8 @@ def database_create():
|
|||
ALBUM TEXT ,
|
||||
TRACK TEXT NOT NULL,
|
||||
ARTIST TEXT NOT NULL,
|
||||
TRACKDUR INT NOT NULL,
|
||||
TRACKDUR FLOAT NOT NULL,
|
||||
GENRE TEXT NOT NULL,
|
||||
YEAR TEXT NOT NULL,
|
||||
PATH TEXT NOT NULL
|
||||
);''')
|
||||
|
@ -88,19 +89,7 @@ def check_archive(track):
|
|||
print("____ TRACK ALREADY PLAYED _____")
|
||||
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):
|
||||
load_all_music()
|
||||
|
||||
global episode_duration
|
||||
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
|
||||
while episode_duration < 60 * 60 and track_count < 12 :
|
||||
|
||||
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
|
||||
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])
|
||||
|
||||
track_path = '/'.join(song.split('/')[0:-1])
|
||||
if track.artist not in artists_played:
|
||||
if check_archive(track.title) is True:
|
||||
if int(track.duration) > min_track_dur * 60:
|
||||
if int(track.duration) < max_track_dur * 60:
|
||||
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)
|
||||
art = string=re.sub("\(.*?\)","",track_artist)
|
||||
# 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)
|
||||
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
|
||||
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
|
||||
|
||||
if not track_year: # where missing metadata give a dummy value
|
||||
track_year = 0000
|
||||
|
||||
if not track.year: # where missing metadata give a dummy value
|
||||
track.year = 0000
|
||||
|
||||
cursor = conn.cursor()
|
||||
#long_string = json.dumps(["' SomeWord"])
|
||||
|
||||
print([episode_number, episode_date, \
|
||||
track.album, track.title, track.artist, \
|
||||
track.duration, track.year, track_path])
|
||||
track_album, track_title, track_artist, \
|
||||
track_duration, 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]);
|
||||
track_album, track_title, track_artist, \
|
||||
track_duration, track_year, track_path]);
|
||||
conn.commit()
|
||||
print("DB Record created successfully");
|
||||
print("sqlite: Episode track successfully inserted into SHOW table");
|
||||
|
||||
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 LONG..........." )
|
||||
else: print("SONG PLAYED IN PREVIOUS EPISODE" )
|
||||
else: print("ARTIST ALREADY IN PODCAST")
|
||||
|
||||
conn.close()
|
||||
#
|
||||
|
||||
episode_duration = timedelta(seconds=round(episode_duration))
|
||||
|
||||
|
@ -266,10 +264,8 @@ def create_show_coverart(episode_playlist, variants):
|
|||
for i in range(variants):
|
||||
x = show_cover_jpgs[:12]
|
||||
combine_images(columns=4, space=10, images=random.sample(x,len(x)),variants=i)
|
||||
|
||||
return show_cover
|
||||
|
||||
|
||||
def create_animated_gif():
|
||||
import contextlib
|
||||
from PIL import Image
|
||||
|
@ -377,15 +373,15 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
homepage_template = env.get_template('homepage.jinja')
|
||||
|
||||
conn = sqlite3.connect("database/show.db")
|
||||
cur = conn.cursor()
|
||||
cursor = conn.cursor()
|
||||
|
||||
show_info = []
|
||||
|
||||
episode_artists = []
|
||||
for i in range(10):
|
||||
artists = []
|
||||
cur.execute("SELECT ARTIST FROM SHOW WHERE EPISODE=?", [i])
|
||||
rows = cur.fetchall()
|
||||
cursor.execute("SELECT ARTIST FROM SHOW WHERE EPISODE=?", [i])
|
||||
rows = cursor.fetchall()
|
||||
|
||||
for artist in rows:
|
||||
art = string=re.sub("\(.*?\)","", artist[0])
|
||||
|
@ -404,17 +400,22 @@ def create_html_homepage_from_template(episode_playlist):
|
|||
episodes.append(an_episode)
|
||||
episodes = reversed(episodes) # reversed order to most recent episode appears first in list
|
||||
|
||||
#TODO get database sorted - music table with metadata, bandcamp, label info
|
||||
cur.execute('SELECT * FROM SHOW WHERE EPISODE=?', [episode_number])
|
||||
# database query instead of the below
|
||||
# maybe a jinja2 template loop here instead
|
||||
for i in episode_playlist: # liar od files
|
||||
#for i in cur: # liar od files
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM SHOW 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_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) + \
|
||||
" | " + str(track.title) + " | " + str(track.year) + \
|
||||
" | " + str(timedelta(seconds=round(track.duration)))
|
||||
detail = str(track_artist) + " | " + str(track_album) + \
|
||||
" | " + str(track_title) + " | " + str(track_year) + \
|
||||
" | " + str(timedelta(seconds=round(track_duration)))
|
||||
show_info.append("" + detail)
|
||||
|
||||
output_from_parsed_template = homepage_template.render(\
|
||||
|
@ -439,11 +440,26 @@ def create_html_episode_from_template(episode_playlist):
|
|||
show_info = []
|
||||
|
||||
# maybe a jinja2 template loop here instead
|
||||
for i in episode_playlist:
|
||||
track = TinyTag.get(i)
|
||||
detail = str(track.artist) + " | " + str(track.album) + \
|
||||
" | " + str(track.title) + " | " + str(track.year) + \
|
||||
" | " + str(timedelta(seconds=round(track.duration)))
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT * FROM SHOW 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_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)
|
||||
|
||||
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_pls_file()
|
||||
|
||||
create_html_episode_from_template(episode_playlist)
|
||||
create_html_homepage_from_template(episode_playlist)
|
||||
create_html_episode_from_template(episode_playlist)
|
||||
|
||||
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
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
|
||||
Speshlafer
|
||||
Tomaž Grom - Sam, za... - 09 N.N.
|
||||
YuWrong
|
||||
Vertex
|
||||
Carve4
|
||||
Dromon
|
||||
Blue Waters Turn Black (P.C.M. remix)
|
||||
Cifre (feat. Eno)
|
||||
Lynch - Oro zatvorenih očiju
|
||||
KIURIKI - Killem All
|
||||
postcell (Tetsuo remix)
|
||||
Stampede
|
||||
一点一滴
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue