UI upgrades

main
Rob Canning 2024-01-29 01:16:49 +01:00
parent 2f133bba5b
commit ab18a61499
6 changed files with 363 additions and 208 deletions

View File

@ -39,6 +39,12 @@ source .venv/bin/activate
pip install tinytag scikit-image popen
sudo apt install portaudio mp3info
pip install pyaudio playsound pynput
recorder?
## run the script
// fresh start

Binary file not shown.

View File

@ -92,8 +92,8 @@
<div class="container">
<div class="row align-items-center justify-content-center text-center">
<div class="col-md-8" data-aos="fade-up" data-aos-delay="400">
<h2 class="text-white font-weight-light mb-2 display-4">{{show_name}} | Episode #{{episode_number}} </h2>
<div class="text-white mb-3"><span class="text-white-opacity-05"> Hosted by: {{episode_author}} | First broadcast:{{episode_date}} | Total running time: {{episode_duration}}</small></span></div>
<h2 style="background-color: black;" class="text-white font-weight-light mb-2 display-4">{{show_name}} | Episode #{{episode_number}} </h2>
<div class="text-white mb-3"><span class="text-white" style="color: white; background-color: black;" > Hosted by: {{episode_author}} | First broadcast: {{episode_date}} | <br> Total running time: {{episode_duration}}</small></span></div>
</div>
</div>
</div>
@ -101,7 +101,7 @@
<div class="container site-section">
<div class="text-white mb-4"><span class="text-white">Presented by: {{episode_author}} / Zavod Rizoma | {{episode_date}}</span>
<div class="text-white mb-4"><span class="text-white">Presented by: {{episode_author}} / Zavod Rizoma | {{episode_date}}</span>
</div>
@ -163,15 +163,52 @@
</div>
<footer class="site-footer border-top">
<footer class="site-footer">
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="mb-5">
<h3 class="footer-heading mb-4">About {{show_name}}</h3>
<h3 class="footer-heading mb-4">About The {{show_name}} Podcast</h3>
<p>{{about_show}}</p>
</div>
<!-- <div class="mb-5"> -->
<!-- <h3 class="footer-heading mb-4">Previous Podcast</h3> -->
<!-- <div class="block-25"> -->
<!-- <ul class="list-unstyled"> -->
<!-- <li class="mb-3"> -->
<!-- <a href="#" class="d-flex"> -->
<!-- <figure class="image mr-4"> -->
<!-- <img src="images/img_1.jpg" alt="" class="img-fluid"> -->
<!-- </figure> -->
<!-- <div class="text"> -->
<!-- <h3 class="heading font-weight-light">Lorem ipsum dolor sit amet consectetur elit</h3> -->
<!-- </div> -->
<!-- </a> -->
<!-- </li> -->
<!-- <li class="mb-3"> -->
<!-- <a href="#" class="d-flex"> -->
<!-- <figure class="image mr-4"> -->
<!-- <img src="images/img_1.jpg" alt="" class="img-fluid"> -->
<!-- </figure> -->
<!-- <div class="text"> -->
<!-- <h3 class="heading font-weight-light">Lorem ipsum dolor sit amet consectetur elit</h3> -->
<!-- </div> -->
<!-- </a> -->
<!-- </li> -->
<!-- <li class="mb-3"> -->
<!-- <a href="#" class="d-flex"> -->
<!-- <figure class="image mr-4"> -->
<!-- <img src="images/img_1.jpg" alt="" class="img-fluid"> -->
<!-- </figure> -->
<!-- <div class="text"> -->
<!-- <h3 class="heading font-weight-light">Lorem ipsum dolor sit amet consectetur elit</h3> -->
<!-- </div> -->
<!-- </a> -->
<!-- </li> -->
<!-- </ul> -->
<!-- </div> -->
<!-- </div> -->
</div>
<div class="col-lg-4 mb-5 mb-lg-0">
@ -182,46 +219,76 @@
<div class="col-md-6 col-lg-6">
<ul class="list-unstyled">
<li><a href="#">Home</a></li>
<li><a href="#">News</a></li>
<li><a href="#">News</a></li>
</ul>
</div>
<div class="col-md-6 col-lg-6">
<ul class="list-unstyled">
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 class="footer-heading mb-4">Follow {{show_name}}</h3>
<h3 class="footer-heading mb-4">Follow Us on Social Media</h3>
We are on most of the social media platforms, please follow us and tell your friends about the podcast!
<div>
<a href="#" class="pl-0 pr-3"><span class="icon-facebook"></span></a>
<a href="#" class="pl-3 pr-3"><span class="icon-twitter"></span></a>
<a href="#" class="pl-3 pr-3"><span class="icon-instagram"></span></a>
<a href="#" class="pl-3 pr-3"><span class="icon-linkedin"></span></a>
<a href="https://www.facebook.com/profile.php?id=61555936138715" class="pl-0 pr-3"><span class="icon-facebook"></span></a>
<a href="https://twitter.com/uho_podcast" class="pl-3 pr-3"><span class="icon-twitter"></span></a>
<a href="https://www.instagram.com/uho.podcast" class="pl-3 pr-3"><span class="icon-instagram"></span></a>
<a href="https://www.youtube.com/@uho.podcast" class="pl-3 pr-3"><span class="icon-youtube"></span></a>
<a href="https://soundcloud.com/uho-podcast" class="pl-3 pr-3"><span class="icon-soundcloud"></span></a>
</div>
</div>
<p></p>
<p></p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 class="footer-heading mb-4">Support us on Patreon</h3>
<div>
<a href="https://www.patreon.com/bePatron?u=116340955">Become a Patreon member! Support the show financially, for as little as 5 euros/dollars/pounds a month </a>
</div>
</div>
</div>
</div>
<div class="col-lg-4 mb-5 mb-lg-0">
<div class="mb-5">
<h3 class="footer-heading mb-4">Subscribe to Podcast RSS Feed</h3>
<div class="block-16">
<figure>
<a href="{{show_url}}/{{show_rss}}">
<img src="episode/1/img/cover0.png" alt="podcast" class="img-fluid rounded">
</a>
</figure>
<a href="{{show_url}}/{{show_rss}}">{{show_url}}/{{show_rss}}</a>
</div>
You can also subscribe to our RSS feed via Soundcloud <a href="https://soundcloud.com/uho-podcast" class="pl-3 pr-3"><span class="icon-soundcloud"></span></a> or Youtube <a href="https://www.youtube.com/@uho.podcast" class="pl-3 pr-3"><span class="icon-youtube"></span></a>
</div>
<!-- <div class="mb-5"> -->
<!-- <h3 class="footer-heading mb-2">Subscribe Newsletter</h3> -->
<!-- <p>Contact us at: uho.podcast@gmail.com.</p> -->
<!-- <\!-- <form action="#" method="post"> -\-> -->
<!-- <\!-- <div class="input-group mb-3"> -\-> -->
<!-- <\!-- <input type="text" class="form-control border-secondary text-white bg-transparent" placeholder="Enter Email" aria-label="Enter Email" aria-describedby="button-addon2"> -\-> -->
<!-- <\!-- <div class="input-group-append"> -\-> -->
<!-- <\!-- <button class="btn btn-primary" type="button" id="button-addon2">Send</button> -\-> -->
<!-- <\!-- </div> -\-> -->
<!-- <\!-- </div> -\-> -->
<!-- <\!-- </form> -\-> -->
<!-- <form action="#" method="post"> -->
<!-- <div class="input-group mb-3"> -->
<!-- <input type="text" class="form-control border-secondary text-white bg-transparent" placeholder="Enter Email" aria-label="Enter Email" aria-describedby="button-addon2"> -->
<!-- <div class="input-group-append"> -->
<!-- <button class="btn btn-primary" type="button" id="button-addon2">Send</button> -->
<!-- </div> -->
<!-- </div> -->
<!-- </form> -->
<!-- </div> -->

View File

@ -94,8 +94,8 @@
<div class="col-md-12" data-aos="fade-up" data-aos-delay="400">
<h2 class="text-white font-weight-light mb-2 display-4">{{show_name}}</h2>
<p class="text-white font-weight-light">{{about_show}}</p>
<h4 class="text-white font-weight-light mb-2 display-4">Latest Episode: # {{episode_number}}</h4>
<p class="text-white font-weight-light">This week music from: {{episode_artists}}</p>
<h4 class="text-white font-weight-light mb-2 display-4" style="color: white; background-color: black;" >Latest Episode: # {{episode_number}}</h4>
<p class="text-white font-weight-light" style="color: white; background-color: black;" >This week music from: {{episode_artists}}</p>
<p><a href="episode/{{episode_number}}/index.html" class="btn btn-primary btn-sm py-3 px-4 small">Episode Details and Player</a></p>
<div class="text-white mb-4"><span class="text-white">Presented by: {{episode_author}} / Zavod Rizoma | {{episode_date}}</span>

View File

@ -12,8 +12,7 @@ import uuid
#import pypika # sql query builder
from pypika import Query, Table, Field, Column
music_library_path = "/home/rob/antena/music/"
music_library_path = "/home/rob/uho/music/"
conn = sqlite3.connect("database/show.db")
#TODO fix getting bandcamp urls into db

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
# CREATE PODCAST -----------------------------------------
# CREATE UHO EPISODE -----------------------------------------
import sys, os, datetime, fnmatch, glob, random, time, pathlib, re
from datetime import timedelta
@ -8,10 +8,18 @@ from os.path import join
from tinytag import TinyTag
from random import shuffle
import sqlite3, json
import subprocess
import uuid
import subprocess, uuid, argparse, contextlib
from pypika import Query, Table, Field, Column
import argparse
from PIL import Image, ImageDraw, ImageFont
from jinja2 import Template, Environment, FileSystemLoader
import tkinter as tk
from tkinter import filedialog as fd
# TODO get specific file into playlist
#name= fd.askopenfilename()
#print(name)
# look up the path in db to get full details to add to episode
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--date", help="Show Date")
@ -25,8 +33,7 @@ parser.add_argument("-t", "--top_tail", action="store_true")
args = parser.parse_args()
path = "/home/rob/antena/"
path = "/home/rob/uho/"
show_name = "UhO"
show_url = "https://uho.rizom.si"
show_rss = "podcast_rss.xml"
@ -47,7 +54,7 @@ artist_abreviated = []
# sqlite database connection
conn = sqlite3.connect("database/show.db")
web_path = "/home/rob/antena/html/episode/{0}/img".format(episode_number)
web_path = "/home/rob/uho/html/episode/{0}/img".format(episode_number)
if not os.path.exists(web_path):
os.makedirs(web_path)
@ -60,14 +67,14 @@ def set_episode_date(input_date):
episode_date = datetime.date(int(d[0]),int(d[1]),int(d[2])).strftime("%A, %d %B, %Y")
return episode_date
def create_intro():
def get_intro():
intropath = path + "audio/texts/clips/this_is"
intropath = path + "audio/intros"
intro = random.choice(os.listdir(intropath))
#final_playlist.insert(0, str(os.path.abspath(intropath)) + "/" + str(intro))
return str(str(intropath) + "/" + str(intro))
def choose_a_track(conn, episode_number):
def choose_a_track(conn, episode_number, ):
print("adding a track")
global episode_duration
global track_count
@ -95,8 +102,8 @@ def choose_a_track(conn, episode_number):
track_comment = str(r[11])
print(track_duration/60)
# SOME LOGIC TO SEE IF WE ALLOW THAT TRACK OR NOT
if check_album(track_album) is True \
and check_artist(track_artist) is True \
and check_for_KM_compilation(track_album) is True:
@ -114,7 +121,7 @@ def choose_a_track(conn, episode_number):
track_year = "0000"
e = Table('EPISODES')
track_number = track_count
track_number = '{:0>2}'.format(track_count)
id = str(uuid.uuid4())
print("adding..." + str(track_count))
q = e.insert(id, episode_number, track_number, str(episode_date),\
@ -125,8 +132,10 @@ def choose_a_track(conn, episode_number):
conn.commit()
track_count += 1;
episode_duration = episode_duration + track_duration
return track_count
# else: print("TRACK TOO SHORT..........." )
return '{:0>2}'.format(track_count)
# else: print("TRACK TOO SHORT..........." )
# else: print("TRACK TOO LONG..........." )
# else: print("SONG PLAYED IN PREVIOUS EPISODE" )
#else: print("ARTIST ALREADY IN PODCAST")
@ -163,7 +172,7 @@ def check_for_KM_compilation(track_album):
print('Klubski Maraton compilation already featured this episode!?', [track_album, data])
return False
def check_album(track_album):
# check if album is played already on this episode - maybe last 2 episodes >= or similar
@ -192,16 +201,20 @@ def check_artist(track_artist):
print('ARTIST already featured on this episode:', [track_artist, data[0]])
return False
# -----------------------------------------------------------------------------
track_count = 0
track_count = 1
def create_episode_playlist(conn, episode_number):
global episode_duration
global archive
global track_count
track_count = 1
max_track_dur = 10
min_track_dur = 2
episode_duration = 0
set_episode_date(input_date)
@ -210,68 +223,86 @@ def create_episode_playlist(conn, episode_number):
cursor.execute('DELETE FROM EPISODES WHERE episode = {0}'.format(episode_number))
# 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 :
print(track_count)
choose_a_track(conn, episode_number)
modify_playlist(conn, episode_number, episode_duration)
#TODO maybe episode duration needs fixing after new track insertion
# -----------------------------------------------------------------------------
# TODO shuffle playlist order as an option
def playlist_replace_track(conn, episode_number, episode_duration):
global track_count
cursor = conn.cursor()
track_to_replace = int(input("which track number would you like to replace?"))
# get a random track to replace the removed
# TODO put it here
cursor.execute('DELETE FROM EPISODES WHERE episode = {0} AND track_number={1}'.format(episode_number, track_to_replace ))
track_to_replace = int(input(">>>>>>>>>> Which track number would you like to REPLACE? : "))
# delete the old track
cursor.execute('DELETE FROM EPISODES WHERE episode = {0} AND track_number={1}'\
.format(episode_number, track_to_replace ))
conn.commit()
track_count = track_to_replace# this is where the index number comes from in choose a track funciont
# this is where the index number comes from in the below choose_a_track function
track_count = track_to_replace
# insert the new track
choose_a_track(conn, episode_number)
# cursor.execute('SELECT EPISODE FROM EPISODES WHERE EPISODE = {0} ORDER BY track_number ASC'.format(episode_number, track_to_replace ))
conn.commit()
# TODO does broken track order effect playlist order.... check this - yes its a bit broken - nned to SORT
# TODO ABOVE ORDER QUERY IS NOT WORKING .... too tired... go to bed its 3:38
# get the new episode time
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
modify_playlist(conn, episode_number, episode_duration)
def playlist_add_track(conn, episode_number, episode_duration):
global track_count
cursor = conn.cursor()
#track_to_add = int(input(">>>>>>>>>> Where would you like to ADD the track? : "))
# this is where the index number comes from in the below choose_a_track function
#track_count = track_to_add
# add the new track
choose_a_track(conn, episode_number)
# conn.commit()
# re sequence track numbers
cursor.execute('\
UPDATE EPISODES SET track_number = (SELECT COUNT(*)+1 FROM EPISODES r \
WHERE EPISODES.track_number>r.track_number AND EPISODE=?);',[episode_number] )
conn.commit()
# get the new episode time
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
# q = 'SELECT * FROM MUSIC_LIBRARY ORDER BY random() LIMIT 1;'.format(episode_number)
# # TODO let me have a choice of specific file/folder or random file
# # a number of q choices through an input()
# cursor.execute(q)
# r = cursor.fetchall()
# print(r)
# # delete the old episode
# cursor.execute('DELETE FROM EPISODES WHERE episode = {0} AND track_number={1}'.format(episode_number, track_to_replace ))
# track_count = 0;
# # write in the shuffled version
# for i in r:
# print("...................................................................." )
# # print('{0} : {1} {2} {3} {4}'.format(i[2], i[4], i[5], i[6], i[7]))
# e = Table('EPISODES')
# track_number = track_count
# id = str(uuid.uuid4())
# q = e.insert(id, episode_number, track_to_replace, str(episode_date),\
# i[4], i[5], i[6], i[7], i[8], i[9], i[10], i[11], i[11])
# cursor.execute(str(q))
# track_count += 1;
# #episode_duration = episode_duration #+ track_duration
modify_playlist(conn, episode_number, episode_duration)
def playlist_delete_track(conn, episode_number, episode_duration):
global track_count
cursor = conn.cursor()
track_to_replace = int(input(">>>>>> Which track number would you like to DELETE? : "))
# delete the old track
cursor.execute('DELETE FROM EPISODES WHERE episode = {0} AND track_number={1}'\
.format(episode_number, track_to_replace ))
conn.commit()
# interate through the column an insert new track_number sequence to replace the gap
cursor.execute('\
UPDATE EPISODES SET track_number = (SELECT COUNT(*)+1 FROM EPISODES r \
WHERE EPISODES.track_number>r.track_number AND EPISODE=?);',[episode_number] )
conn.commit()
# get the new episode time
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
modify_playlist(conn, episode_number, episode_duration)
def playlist_shuffle_tracks(conn, episode_number, episode_duration):
os.system("clear")
# shuffle the episode
cursor = conn.cursor()
@ -280,7 +311,7 @@ def playlist_shuffle_tracks(conn, episode_number, episode_duration):
r = cursor.fetchall()
# delete the old episode
cursor.execute('DELETE FROM EPISODES WHERE episode = {0}'.format(episode_number))
track_count = 0;
track_count = 1;
# write in the shuffled version
print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(">>NEW SHUFFLED PLAYLIST: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
@ -288,7 +319,7 @@ def playlist_shuffle_tracks(conn, episode_number, episode_duration):
for i in r:
print('{0} : {1} {2} {3} {4} '.format(i[2], i[4], i[5], i[6], i[7],))
e = Table('EPISODES')
track_number = track_count
track_number = '{:0>2}'.format(track_count)
id = str(uuid.uuid4())
q = e.insert(id, episode_number, track_number, str(episode_date),\
i[4], i[5], i[6], i[7], i[8], i[9], i[10], i[11], i[11]) #TODO fix last index
@ -296,71 +327,73 @@ def playlist_shuffle_tracks(conn, episode_number, episode_duration):
track_count += 1;
episode_duration = episode_duration
conn.commit()
print("\n>>>>>>>>>>>>>>TOTAL EPISODE DURATION:>>>> {0} >>>>>>>>>>>>>>>>>>>>>>>\n".format(episode_duration/60))
print("\n>>>>>>>>>>>>>>TOTAL EPISODE DURATION:>>>> {0} >>>>>>>>>>>>>>>>>>>>>>>\n"\
.format(timedelta(seconds=round(episode_duration))) )
modify_playlist(conn, episode_number, episode_duration)
def playlist_preview_track(conn, episode_number, episode_duration):
cursor = conn.cursor()
# preview a track --------------------------------------
preview_track = input("which track would you like to preview [0-12]:")
preview_track = input(">>>>>>>> Which track would you like to preview : ")
cursor.execute('SELECT path FROM EPISODES WHERE EPISODE=? AND track_number=?', [episode_number, preview_track ])
preview_track_path = cursor.fetchone()[0]
print(preview_track_path)
#os.system("mplayer '{0}' &".format(preview_track_path))
subprocess.Popen(["nohup mplayer '{0}' &".format(preview_track_path)], shell=True)
#Popen.run("mplayer '{0}' &".format(preview_track_path))
track_previewed = input("track OK? :")
if track_previewed == 'y':
print("ok groovy choice then...")
return True
else:
return False
subprocess.Popen(["nohup vlc '{0}' &".format(preview_track_path)], shell=True)
modify_playlist(conn, episode_number, episode_duration)
def modify_playlist(conn, episode_number, episode_duration):
#TODO some broken logic here - cant do multip shuffles or generate new playlist
cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
preview = cursor.fetchall()
#os.system("clear")
cursor.execute('SELECT SUM(trackdur) FROM EPISODES WHERE EPISODE=? ', [episode_number])
episode_duration = cursor.fetchone()[0]
os.system("clear")
print("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(">>PROPOSED PLAYLIST: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(">> PROPOSED EPISODE #{0} PLAYLIST: ({1}) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"\
.format(episode_number, timedelta(seconds=round(episode_duration))))
print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
for i in preview:
print('{0} : {1} {2} {3} {4} '.format(i[2], i[4], i[5], i[6], i[7],))
print("\n>>>> TOTAL EPISODE DURATION:>>>> {0} >>>>>>>>>>>>>>>\n".format(episode_duration/60))
print('| {0} | {3} ||| {2} ||| {1} ||| {5} ||| [{6}] ||| {4} |||\n'\
.format('{:0>2}'.format(i[2]), i[4], i[5], i[6], timedelta(seconds=round(i[7])), i[9], i[11] ) )
print("\n>>SELECT AN OPTION: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(">> SELECT AN OPTION: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
user_input = input('''
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
(l)isten to track
(n)EW (playlist),
(s)HUFFLE
(r)EPLACE
(d)ELETE
(a)DD
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> OR PRESS ENTER TO PROCEED....
''')
>>>>>>>>>>>>>>>>>>>>>>>>>>> OR PRESS ENTER TO PROCEED................... : ''')
if user_input == 'y':
create_episode_playlist(conn, episode_number, episode_duration)
if user_input == 'n':
track_count = 1
create_episode_playlist(conn, episode_number)
elif user_input == 's':
playlist_shuffle_tracks(conn, episode_number, episode_duration)
elif user_input == 'r':
playlist_replace_track(conn, episode_number, episode_duration)
elif user_input == 'p':
playlist_preview_track(conn, episode_number)
elif user_input == 'l':
playlist_preview_track(conn, episode_number, episode_duration)
elif user_input == 'd':
playlist_delete_track(conn, episode_number, episode_duration)
elif user_input == 'a':
playlist_add_track(conn, episode_number, episode_duration)
else:
print(">>>>>>>>>>>>>>>>>> Goodbye Happy DJ !!!!!!!!!!!!!!")
episode_duration = timedelta(seconds=round(episode_duration))
@ -374,9 +407,6 @@ def combine_images(columns, space, images, variants:int):
global show_cover
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
set_episode_date(input_date)
@ -466,8 +496,9 @@ def create_show_coverart(variants):
set_episode_date(input_date)
final_playlist = []
cursor = conn.cursor()
cursor.execute('SELECT path FROM EPISODES WHERE EPISODE=?', [episode_number])
cursor.execute('SELECT path FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
preview = cursor.fetchall()
for i in preview: # database >> python list
final_playlist.append(i[0])
@ -496,11 +527,11 @@ def create_show_coverart(variants):
def create_animated_gif():
import contextlib
from PIL import Image
# filepaths
fp_in = "/home/rob/antena/html/episode/2/img/*.png".format(episode_number)
fp_out = "/home/rob/antena/html/episode/2/img/show_cover.gif"
fp_in = "/home/rob/uho/html/episode/2/img/*.png".format(episode_number)
fp_out = "/home/rob/uho/html/episode/2/img/show_cover.gif"
# use exit stack to automatically close opened images
with contextlib.ExitStack() as stack:
@ -516,6 +547,7 @@ def create_animated_gif():
img.save(fp=fp_out, format='GIF', append_images=imgs,
save_all=True, duration=200, loop=0)
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@ -528,67 +560,62 @@ def create_podcast():
from glob import glob
from pydub import AudioSegment
fill_path = "audio/fills/"
# grab the conpleted playlist from the database
final_playlist = []
cursor = conn.cursor()
cursor.execute('SELECT path FROM EPISODES WHERE EPISODE=?', [episode_number])
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
preview = cursor.fetchall()
#TODO add track duration counter into this loop to get final duration
# metaflac --show-total-samples --show-sample-rate foo.flac | tr '\n' ' ' | awk '{print $1/$2}' -
for i in preview: # database >> python list
final_playlist.append(i[0])
# if its the first track then put the show intro before it
# no track intro but yes track outro
#episode_number=0 #TODO undo this ... just for testing
if i[2] == 1:
print("adding track intro: " + "{0}e_{1}_t_{2}_in.flac".format(fill_path, episode_number, i[2] ))
intro = get_intro()
final_playlist.insert(0,intro)
print("adding track: " + i[10])
final_playlist.insert(1, i[10]) # insert the intro
print("adding track intro: " + "{0}e_{1}_t_{2}_out.flac".format(fill_path, episode_number, i[2] ))
final_playlist.append("{0}e_{1}_t_{2}_out.flac".format(fill_path, episode_number, i[2] ))
elif i[2] == len(preview):
print("adding track intro: " + "{0}e_{1}_t_{2}_in.flac".format(fill_path, episode_number, i[2] ))
final_playlist.append("{0}e_{1}_t_{2}_in.flac".format(fill_path, episode_number, i[2] ))
print("adding last track intro no outro : " + i[10])
final_playlist.append(i[10])
else:
#TODO insert some call to action filler after a track outro
# x 2
# TODO = episode_number must be zero to get the dummy filler files -
print("adding track intro: " + "{0}e_{1}_t_{2}_in.flac".format(fill_path, episode_number, i[2] ))
final_playlist.append("{0}e_{1}_t_{2}_in.flac".format(fill_path, episode_number, i[2] ))
print("adding track: " + i[10])
final_playlist.append(i[10])
print("adding track outro: " + "{0}e_{1}_t_{2}_out.flac".format(fill_path, episode_number, i[2] ))
final_playlist.append("{0}e_{1}_t_{2}_out.flac".format(fill_path, episode_number, i[2] ))
print('''
========================================================================
{0}
========================================================================'''.format(final_playlist))
for i in final_playlist:
print(i)
playlist_length = len(final_playlist) / (1000*60)
# makes an array of songs and fills as audiosegments
show_playlist = [AudioSegment.from_file(flac_file) for flac_file in final_playlist]
playlist = show_playlist[0]
for track in show_playlist[1:]:
playlist = playlist.append(track)
playlist_songs = [AudioSegment.from_file(flac_file) for flac_file in final_playlist]
#TODO intro is not here anymore change index
show_intro = playlist_songs[0]
# first_song = playlist_songs[0].fade_in(0) # only fadein if used over show intro - currently not used
# intro_and_first = first_song.overlay(show_intro)
first_three_blurb = playlist_songs[0]
second_three_blurb = playlist_songs[0]
final_songs_blurb = playlist_songs[0]
final_show_outro = playlist_songs[0]
# next two commented lines are for if intro goes over first track or not
#playlist = intro_and_first
playlist = show_intro
# playlist = []
#for song in playlist_songs[2:3]:
for song in playlist_songs[1:4]: # first three songs (first added with intro)
# We don't want an abrupt stop at the end, so let's do a 1 second crossfades
playlist = playlist.append(song)
print(song)
print("first songs added")
# blurb about first three tracks
# playlist = playlist.append(first_three_blurb) # <--------------BLURB INSERT
for song in playlist_songs[4:7]: # second three songs
playlist = playlist.append(song)
print(song)
print("second songs added")
# playlist = playlist.append(second_three_blurb) # <--------------BLURB INSERT
for song in playlist_songs[7:10]: # second three song
#playlist = playlist.append(song, crossfade=(1 * 1000))
playlist = playlist.append(song)
print(song)
print("third songs added")
# playlist = playlist.append(final_songs_blurb) # <--------------BLURB INSERT
for song in playlist_songs[10:13]: # second three song
playlist = playlist.append(song)
print(song)
print("final songs added")
# playlist = playlist.append(final_show_outro) # <-------------- OUTRO SEQUENCE
# get length of final show / podcast
playlist_length = len(playlist) / (1000*60)
# 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...")
@ -601,9 +628,14 @@ def create_podcast():
playlist.export(out_f, format='mp3')
print("MP3 audio file exported...")
# TODO duration of final file
# ffprobe -i html/episode/0/show.mp3 -show_entries format=duration -v quiet -of csv="p=0" -sexagesimal
### ------------------------------------------------------------
def create_html_homepage_from_template():
# TODO "on this weeks show" variants fed to html from list here
# TODO "on this weeks show" variants fed to html from list here
from jinja2 import Template, Environment, FileSystemLoader
set_episode_date(input_date)
@ -625,7 +657,7 @@ def create_html_homepage_from_template():
for i in range(num_eps):
artists = []
cursor.execute("SELECT artist FROM EPISODES WHERE episode=?", [i])
cursor.execute("SELECT artist FROM EPISODES WHERE episode=? ORDER BY track_number ASC", [i])
rows = cursor.fetchall()
for artist in rows:
@ -649,7 +681,7 @@ def create_html_homepage_from_template():
episodes = reversed(episodes[1:episode_number])
cursor = conn.cursor()
cursor.execute('SELECT * FROM EPISODES WHERE episode=?', [episode_number])
cursor.execute('SELECT * FROM EPISODES WHERE episode=? ORDER BY track_number ASC', [episode_number])
r = cursor.fetchall()
for t in r:
@ -678,17 +710,14 @@ def create_html_homepage_from_template():
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_number, episode_duration):
from jinja2 import Template, Environment, FileSystemLoader
set_episode_date(input_date)
def parse_db_episode():
playlist_table = []
env = Environment(loader=FileSystemLoader('html/templates'))
episode_template = env.get_template('episode.jinja')
playlist_table = []
# maybe a jinja2 template loop here instead
cursor = conn.cursor()
@ -698,8 +727,8 @@ def create_html_episode_from_template(episode_number, episode_duration):
e.episode
).where(
e.episode == episode_number)
# raw 'SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number]
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=? ORDER BY track_number ASC', [episode_number])
#cursor.execute(str(q))
r = cursor.fetchall()
@ -715,7 +744,6 @@ def create_html_episode_from_template(episode_number, episode_duration):
track_label = str(t[11])
track_comment = str(t[12])
playlist_entry = [track_number, track_title, track_artist,\
track_album, track_year,\
timedelta(seconds=round(track_duration)),\
@ -724,6 +752,7 @@ def create_html_episode_from_template(episode_number, episode_duration):
playlist_table.append(playlist_entry)
# populate the jinja html template for the EPISODE
output_from_parsed_template = episode_template.render(\
show_name=show_name, episode_author=episode_author,\
episode_number=episode_number, show_url=show_url, show_rss=show_rss,\
@ -732,6 +761,58 @@ def create_html_episode_from_template(episode_number, episode_duration):
episode_playlist=playlist_table, \
episode_image="img/cover0.png".format(episode_number))
return output_from_parsed_template
def create_html_episode_from_template(episode_number, episode_duration):
set_episode_date(input_date)
output_from_parsed_template = parse_db_episode()
# playlist_table = []
# # maybe a jinja2 template loop here instead
# cursor = conn.cursor()
# e = Table('episodes')
# q = Query.from_(e).select(
# e.episode
# ).where(
# e.episode == episode_number)
# cursor.execute('SELECT * FROM EPISODES WHERE EPISODE=?', [episode_number])
# #cursor.execute(str(q))
# r = cursor.fetchall()
# for t in r:
# song = str(t[0])
# track_number = str(t[2])
# track_album = str(t[4])
# track_title = str(t[5])
# track_artist = str(t[6]).upper()
# track_duration = float(t[7])
# track_genre = str(t[8])
# track_year = str(t[9])
# track_label = str(t[11])
# track_comment = str(t[12])
# playlist_entry = [track_number, track_title, track_artist,\
# track_album, track_year,\
# timedelta(seconds=round(track_duration)),\
# track_label.upper() ]
# populate the jinja html template for the EPISODE
# output_from_parsed_template = episode_template.render(\
# show_name=show_name, episode_author=episode_author,\
# episode_number=episode_number, show_url=show_url, show_rss=show_rss,\
# episode_duration=timedelta(seconds=round(episode_duration)), \
# episode_date=episode_date, about_show=show_short_description, \
# episode_playlist=playlist_table, \
# 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)
@ -757,11 +838,13 @@ def create_RSS_XML_from_template():
def main():
# playlist options
if args.playlist == "new":
print("creating new playlist >>>>> database ")
create_episode_playlist(conn, episode_number)
elif args.playlist=="keep":
print("working with playlist from database... ")
elif args.playlist=="edit":
@ -775,15 +858,8 @@ def main():
if args.top_tail == True:
print("inserting intro and outro......")
# output options
if args.mp3 == True:
print("creating MP3 audio output......")
create_intro()
create_podcast()
else:
print("not creating audio output......")
if args.web == True:
print("creating html......")
@ -797,7 +873,14 @@ def main():
print("creating artwork for socials ......")
create_show_coverart(4) #episode_duration = 100
#create_animated_gif()
if args.mp3 == True:
print("creating MP3 audio output......")
#get_intro()
create_podcast()
else:
print("not creating audio output......")
conn.close()
main()