create show script functions added
parent
4d3f8922e7
commit
aa1e047e95
138
create_show.py
138
create_show.py
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os, random, time
|
||||
from tinytag import TinyTag
|
||||
import datetime
|
||||
|
@ -8,107 +7,116 @@ from datetime import timedelta
|
|||
from random import shuffle
|
||||
|
||||
DATE = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
|
||||
kamizdat_playlist = []
|
||||
sploh_playlist = []
|
||||
trf_playlist = []
|
||||
complete_playlist = []
|
||||
|
||||
total_show_duration = 0
|
||||
show_array = []
|
||||
show_info = []
|
||||
show_cover = "---"
|
||||
archive = []
|
||||
|
||||
# open master playlist
|
||||
# /////////////////////////////////////////////////
|
||||
|
||||
with open('music/kamizdat_flac.pls') as playlist_file:
|
||||
for line in playlist_file:
|
||||
kamizdat_playlist.append(line)
|
||||
def create_intro():
|
||||
intropath = "/home/rob/antena/texts/clips/u_have_been"
|
||||
intro = random.choice(os.listdir(intropath))
|
||||
show_array.append(str(os.path.abspath(intropath)) + "/" + str(intro))
|
||||
|
||||
with open('music/terraformer_research_facilities.pls') as playlist_file:
|
||||
for line in playlist_file:
|
||||
trf_playlist.append(line)
|
||||
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")
|
||||
|
||||
with open('music/complete.pls') as playlist_file:
|
||||
def check_archive():
|
||||
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):
|
||||
global total_show_duration
|
||||
global archive
|
||||
complete_playlist = []
|
||||
|
||||
track_count = 0
|
||||
artist_played = []
|
||||
max_track_dur = 12
|
||||
|
||||
with open('music/complete.pls') as playlist_file:
|
||||
for line in playlist_file:
|
||||
complete_playlist.append(line)
|
||||
|
||||
# /////////////////////////////////////////////////
|
||||
|
||||
intropath = "/home/rob/antena/texts/clips/u_have_been"
|
||||
intro = random.choice(os.listdir(intropath))
|
||||
show_array.append(str(os.path.abspath(intropath)) + "/" + str(intro))
|
||||
|
||||
# //// ===================================
|
||||
|
||||
# selector of non-long tracks by various artists - no artist duplication
|
||||
|
||||
total_show_duration = 0
|
||||
track_count = 0
|
||||
artist_played = []
|
||||
maxTrackDur = 12
|
||||
|
||||
while total_show_duration < 60 * 60:
|
||||
|
||||
while total_show_duration < 60 * 58:
|
||||
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 int(track.duration) < maxTrackDur*60:
|
||||
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
|
||||
print(track_count)
|
||||
|
||||
print(artist_played)
|
||||
|
||||
|
||||
#for i in random.sample(trf_playlist, 8):
|
||||
# show_array.append(i.rstrip())
|
||||
|
||||
print(show_array)
|
||||
|
||||
# remove any duplicates
|
||||
show_array = list(set(show_array))
|
||||
|
||||
# /////////////////////////////////////////////////
|
||||
# create a markdown file containing show information
|
||||
else: print("inclusion conditions not met...................... " + 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
|
||||
|
||||
|
||||
|
||||
for i in show_array:
|
||||
|
||||
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)
|
||||
return show_cover
|
||||
|
||||
def create_web_page(show_array:list):
|
||||
show_info = []
|
||||
find_show_coverart(show_array)
|
||||
global total_show_duration
|
||||
print(show_array)
|
||||
|
||||
# create a HTML file containing show information
|
||||
for i in show_array:
|
||||
track = TinyTag.get(i)
|
||||
detail = str(track.artist) + " | " + str(track.album) + \
|
||||
" | " + str(track.title) + " | " + str(track.year) + " | " + str(timedelta(seconds=round(track.duration)))
|
||||
" | " + str(track.title) + " | " + str(track.year) + \
|
||||
" | " + str(timedelta(seconds=round(track.duration)))
|
||||
show_info.append("" + detail)
|
||||
print(show_info)
|
||||
#total_show_duration = 100
|
||||
|
||||
|
||||
total_show_duration = timedelta(seconds=round(total_show_duration))
|
||||
|
||||
with open("shows/antena_showinfo_" + DATE + ".html","w") as file:
|
||||
|
||||
with open("shows/antena_showinfo_" + DATE + ".html","w") as file:
|
||||
file.write('''
|
||||
<html>
|
||||
<head>
|
||||
<title> SHOW INFO </title>
|
||||
</head>
|
||||
|
||||
<body> <h1>Inside the with open: %s </h1>\n \
|
||||
<body> <h1>Inside the with open: %s </h1>\n
|
||||
\n ''' % DATE)
|
||||
|
||||
file.writelines("<h2>" +"SHOW INFO FOR ANTENA " + DATE + "</h2> \n")
|
||||
file.writelines('''<h3>Total Playtime excluding fills: %s </h3>
|
||||
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
|
||||
''' % 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.close()
|
||||
|
||||
file.close()
|
||||
|
||||
def create_pls():
|
||||
# write the selection as a playlist file
|
||||
with open("shows/antena_playlist_" + DATE + ".pls","w") as file:
|
||||
with open("shows/antena_playlist_" + DATE + ".pls","w") as file:
|
||||
file.writelines(" \n ".join(show_array))
|
||||
|
||||
create_playlist(show_array)
|
||||
create_web_page(show_array)
|
||||
|
|
Loading…
Reference in New Issue