pydub now generates the audio output
parent
aa1e047e95
commit
d258bdd307
|
@ -1,6 +1,8 @@
|
|||
|
||||
# reminders of some useful oneliners
|
||||
|
||||
for i in *.zip; do echo unzip \"$i\" -d \"${i%.zip}\" ; done
|
||||
|
||||
find /home/rizoma/kamizdat_archive/kamizdat.si -iname "*FLAC*.zip" -exec unzip "{}" \;
|
||||
|
||||
for i in *.zip; do unzip "$i" ; done;
|
||||
|
|
150
create_show.py
150
create_show.py
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
import os, random, time
|
||||
import os, fnmatch, random, time
|
||||
from tinytag import TinyTag
|
||||
import datetime
|
||||
|
||||
|
@ -8,76 +8,97 @@ from random import shuffle
|
|||
|
||||
DATE = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
total_show_duration = 0
|
||||
complete_playlist = []
|
||||
show_array = []
|
||||
show_cover = "---"
|
||||
archive = []
|
||||
|
||||
show_name = "THE AND IF"
|
||||
path = "/home/rob/antena/"
|
||||
|
||||
# /////////////////////////////////////////////////
|
||||
|
||||
def create_intro():
|
||||
intropath = "/home/rob/antena/texts/clips/u_have_been"
|
||||
def create_intro(show_array):
|
||||
intropath = path + "texts/clips/this_is"
|
||||
intro = random.choice(os.listdir(intropath))
|
||||
show_array.append(str(os.path.abspath(intropath)) + "/" + str(intro))
|
||||
show_array.insert(0, 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")
|
||||
|
||||
def check_archive():
|
||||
def check_archive(track):
|
||||
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):
|
||||
if track not in archive:
|
||||
print("____ TRACK NOT YET PLAYED ... ADDING _____")
|
||||
return True
|
||||
else:
|
||||
print("____ TRACK ALREADY PLAYED _____")
|
||||
return False
|
||||
|
||||
def load_all_music():
|
||||
with open('music/complete_music_archive.pls') as playlist_file:
|
||||
for line in playlist_file:
|
||||
complete_playlist.append(line)
|
||||
print("loaded %s".format(str(len(complete_playlist))))
|
||||
return complete_playlist
|
||||
|
||||
def create_show_playlist(show_array: list, complete_playlist:list):
|
||||
load_all_music()
|
||||
|
||||
global total_show_duration
|
||||
global archive
|
||||
complete_playlist = []
|
||||
|
||||
track_count = 0
|
||||
artist_played = []
|
||||
max_track_dur = 12
|
||||
max_track_dur = 8
|
||||
min_track_dur = 3
|
||||
|
||||
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
|
||||
while total_show_duration < 60 * 55:
|
||||
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 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
|
||||
else: print("inclusion conditions not met...................... " + str(track))
|
||||
if track.artist not in artist_played:
|
||||
if check_archive(track.title) is True:
|
||||
if int(track.duration) > min_track_dur * 60:
|
||||
if 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
|
||||
else: print("TRACK TOO SHORT..........." + str(track))
|
||||
else: print("TRACK TOO LONG..........." + str(track))
|
||||
else: print("SONG PLAYED IN PREVIOUS EPISODE" + str(track))
|
||||
else: print("ARTIST ALREADY IN PODCAST" + 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
|
||||
|
||||
|
||||
|
||||
|
||||
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)
|
||||
print("THIS WEEKS COVER ART OF THE WEEK is ...." + show_cover)
|
||||
return show_cover
|
||||
|
||||
#def create_show_audio():
|
||||
|
||||
def create_web_page(show_array:list):
|
||||
|
||||
dir_path = "shows/"
|
||||
pattern = "*.html"
|
||||
show_count = len(fnmatch.filter(os.listdir(dir_path), pattern))
|
||||
|
||||
show_info = []
|
||||
find_show_coverart(show_array)
|
||||
global total_show_duration
|
||||
|
@ -102,21 +123,72 @@ def create_web_page(show_array:list):
|
|||
<body> <h1>Inside the with open: %s </h1>\n
|
||||
\n ''' % DATE)
|
||||
|
||||
file.writelines("<h2>" +"SHOW INFO FOR ANTENA " + DATE + "</h2> \n")
|
||||
file.writelines("<h2>" +"Show info for: {0} #{1} release date: {2} </h2> \n".format(show_name, show_count, DATE))
|
||||
file.writelines('''<img src="{0}" alt="podcast cover of the week" width="600" height="600">
|
||||
<h3>Total Playtime excluding fills: {1} </h3>
|
||||
ARTIST | ALBUM | TRACK | YEAR | DURATION
|
||||
'''.format(show_cover, total_show_duration) )
|
||||
'''.format(show_cover, total_show_duration) )
|
||||
|
||||
for x in show_info:
|
||||
file.writelines("<p>" + x + "</p>" +" \n " )
|
||||
file.writelines("</body></html>")
|
||||
|
||||
file.writelines(''' \n\n <hr> <p>For more information on the artists or to buy thier albums visit their bandcamp page. </p>" +" \n ''' )
|
||||
file.writelines("</body></html>")
|
||||
file.close()
|
||||
|
||||
def create_pls():
|
||||
# write the selection as a playlist file
|
||||
|
||||
def create_pls_file():
|
||||
# write the selection as a playlist file
|
||||
with open("shows/antena_playlist_" + DATE + ".pls","w") as file:
|
||||
file.writelines(" \n ".join(show_array))
|
||||
file.writelines("\n".join(show_array))
|
||||
|
||||
create_playlist(show_array)
|
||||
|
||||
def create_podcast(show_array: list):
|
||||
|
||||
from glob import glob
|
||||
from pydub import AudioSegment
|
||||
|
||||
playlist_songs = [AudioSegment.from_file(flac_file) for flac_file in show_array]
|
||||
|
||||
show_intro = playlist_songs.pop(0)
|
||||
first_song = playlist_songs[0].fade_in(3000)
|
||||
intro_and_first = first_song.overlay(show_intro)
|
||||
first_three_blurb = playlist_songs.pop(0)
|
||||
second_three_blurb = playlist_songs.pop(0)
|
||||
final_songs_blurb = playlist_songs.pop(0)
|
||||
final_show_outro = playlist_songs.pop(0)
|
||||
|
||||
playlist = intro_and_first
|
||||
|
||||
for song in playlist_songs[2:3]: # 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, crossfade=(10 * 1000))
|
||||
|
||||
# blurb about first three tracks
|
||||
playlist = playlist.append(first_three_blurb) # <--------------BLURB INSERT
|
||||
|
||||
for song in playlist_songs[4:6]: # second three songs
|
||||
# We don't want an abrupt stop at the end, so let's do a 1 second crossfades
|
||||
playlist = playlist.append(song, crossfade=(10 * 1000))
|
||||
playlist = playlist.append(second_three_blurb) # <--------------BLURB INSERT
|
||||
|
||||
for song in playlist_songs[7:]: # second three songs
|
||||
# We don't want an abrupt stop at the end, so let's do a 1 second crossfades
|
||||
playlist = playlist.append(song, crossfade=(10 * 1000))
|
||||
playlist = playlist.append(final_songs_blurb) # <--------------BLURB INSERT
|
||||
|
||||
playlist = playlist.append(final_show_outro) # <-------------- OUTRO SEQUENCE
|
||||
|
||||
|
||||
|
||||
# get length of final show / podcast
|
||||
playlist_length = len(playlist) / (1000*60)
|
||||
# save the entire poidcast
|
||||
with open("%s_minute_playlist.flac" % playlist_length, 'wb') as out_f:
|
||||
playlist.export(out_f, format='flac')
|
||||
|
||||
create_show_playlist(show_array, complete_playlist)
|
||||
#create_intro(show_array)
|
||||
create_pls_file()
|
||||
create_web_page(show_array)
|
||||
create_podcast(show_array)
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
s = mksafe(once(single("/home/rizoma/sketchbook/libraries/minim/examples/Analysis/offlineAnalysis/data/jingle.mp3")))
|
||||
#s = mksafe(once(single("/home/rizoma/sketchbook/libraries/minim/examples/Analysis/offlineAnalysis/data/jingle.mp3")))
|
||||
|
||||
intro = single("/home/rob/antena/texts/clips/u_have_been/a_selection_of_3.wav")
|
||||
show = mksafe(once(playlist("shows/antena_playlist_2024-01-08.pls")))
|
||||
|
||||
#list = once(single("/home/rizoma/sketchbook/libraries/minim/examples/Analysis/offlineAnalysis/data/jingle.mp3"))
|
||||
|
||||
#s = fallback(track_sensitive=false, [s, list])
|
||||
|
||||
output.file(%wav, "backup.wav", s)
|
||||
output.file(%wav, "backup.wav", [intro, show] )
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
path="/home/rob/antena/music"
|
||||
find $path -iname "*.flac" | sort | shuf > complete_music_archive.pls
|
||||
|
Loading…
Reference in New Issue