finished fakeTV.py script. Doing long term testing...
This commit is contained in:
parent
13e0b2f126
commit
824ecd3f75
@ -6,14 +6,23 @@ apt update & upgrade
|
||||
|
||||
edit /boot/config.txt
|
||||
comment out all hdmi lines
|
||||
uncomment default overscan lines ??? (no)
|
||||
uncomment default overscan lines
|
||||
|
||||
overscan_left=-8
|
||||
overscan_right=-8
|
||||
overscan_top=-12
|
||||
overscan_bottom=-12
|
||||
|
||||
framebuffer_width=640
|
||||
framebuffer_height=480
|
||||
|
||||
add "sdtv_mode=0" and "sdtv_aspect=1"
|
||||
|
||||
raspi-config
|
||||
Advanced -> Compositor -> No
|
||||
Display Options->Composite->Yes->Reboot Now
|
||||
|
||||
Python3-> sudo pip install moviepy && sudo pip install yt-dlp
|
||||
Python3-> sudo pip install opencv2-python && sudo pip install yt-dlp
|
||||
|
||||
|
||||
ancient abandoned esoteric animations or AAEA for short
|
||||
|
71
faketv.py
71
faketv.py
@ -1,9 +1,10 @@
|
||||
import cv2
|
||||
import datetime
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
from moviepy.editor import VideoFileClip
|
||||
#from moviepy.editor import VideoFileClip
|
||||
|
||||
#The channel bug that displays while the channel is playing episodes
|
||||
buglocation = "/media/zella/anime/aaeachannelbug.png"
|
||||
@ -19,13 +20,13 @@ episodeBlockTime = 1560
|
||||
minimumTime = 30
|
||||
|
||||
def get_next_show_episode(showNumber):
|
||||
if lineupStack[showNumber].empty():
|
||||
if len(lineupStack[showNumber]) == 0:
|
||||
return None
|
||||
else:
|
||||
return lineupStack[showNumber].pop()
|
||||
|
||||
def get_next_commercial():
|
||||
if commercialStack.empty():
|
||||
if len(commercialStack) == 0:
|
||||
for file in os.listdir(commercials):
|
||||
commercialStack.append(os.path.join(commercials,file))
|
||||
random.shuffle(commercialStack)
|
||||
@ -36,9 +37,16 @@ def get_next_commercial():
|
||||
return commercialStack.pop()
|
||||
|
||||
#requires moviepy module. rounded up to nearest whole second, for simplicity.
|
||||
def get_video_length_in_seconds(videoFile):
|
||||
clip = VideoFileClip(videoFile)
|
||||
return math.ceil(clip.duration)
|
||||
#def get_video_length_in_seconds(videoFile):
|
||||
# clip = VideoFileClip(videoFile)
|
||||
# return math.ceil(clip.duration)
|
||||
|
||||
def get_video_length_in_seconds(video_path):
|
||||
cap = cv2.VideoCapture(video_path)
|
||||
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||
frame_rate = cap.get(cv2.CAP_PROP_FPS)
|
||||
video_length = total_frames / frame_rate
|
||||
return math.ceil(video_length)
|
||||
|
||||
def get_remaining_seconds_in_hour():
|
||||
now = datetime.datetime.now()
|
||||
@ -72,12 +80,16 @@ for direc in os.listdir(shows):
|
||||
print("\nOpening show " + str(showNumber) + " folder: " + folder + "\n")
|
||||
showEpisodes = []
|
||||
for file in os.listdir(folder):
|
||||
showEpisodes.append(os.path.abspath(file))
|
||||
print(os.path.join(folder,file))
|
||||
showEpisodes.append(os.path.join(folder,file))
|
||||
lineupStack.append(showEpisodes)
|
||||
print("\n Added " + str(len(lineupStack[showNumber])) + " episodes from " + folder + "\n")
|
||||
showNumberList.append(showNumber)
|
||||
showNumber += 1
|
||||
|
||||
#reverse each show stack in the lineupStack list so we start from episode 1
|
||||
for show in lineupStack:
|
||||
show.reverse()
|
||||
|
||||
|
||||
#build season lineup station playlist using schedule:
|
||||
@ -103,12 +115,6 @@ for direc in os.listdir(shows):
|
||||
#-random commercial block (2 minutes)
|
||||
#repeat until out of episodes
|
||||
|
||||
|
||||
#time = get_video_length_in_seconds(stationID)
|
||||
|
||||
#print("\n The station ID video length in seconds is: " + str(time) + "\n")
|
||||
|
||||
|
||||
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
||||
print(" Building Playlist ")
|
||||
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
||||
@ -119,21 +125,22 @@ firstLoop = True
|
||||
while not episodesEmptyFlag:
|
||||
if firstLoop:
|
||||
timeLeft = get_remaining_seconds_in_hour()
|
||||
firstLoop = False
|
||||
else:
|
||||
timeLeft = secondsInHour
|
||||
random.shuffle(showNumberList)
|
||||
showNumberListCount = 0
|
||||
while timeLeft > miniumTime:
|
||||
while timeLeft > minimumTime:
|
||||
if timeLeft >= episodeBlockTime:
|
||||
print("Enough time for an episode block")
|
||||
#add station id
|
||||
timeLeft -= get_video_length_in_seconds(stationID)
|
||||
playlist.write(stationID)
|
||||
playlist.write(stationID + "\n")
|
||||
|
||||
#add commercial. Maybe add a while loop here to add multiple commercials if one is too short
|
||||
nextAd = get_next_commercial()
|
||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||
playlist.write(nextAd)
|
||||
playlist.write(nextAd + "\n")
|
||||
|
||||
#add tv episode
|
||||
nextEpisode = ""
|
||||
@ -145,13 +152,41 @@ while not episodesEmptyFlag:
|
||||
else:
|
||||
showNumberListCount += 1
|
||||
timeLeft -= get_video_length_in_seconds(nextEpisode)
|
||||
playlist.write(nextEpisode)
|
||||
playlist.write(nextEpisode + "\n")
|
||||
print("\nEpisode " + nextEpisode + " added to playlist. " + str(len(lineupStack[showNumberList[showNumberListCount - 1]])) + " episodes left in stack\n")
|
||||
|
||||
break
|
||||
if nextEpisode is None:
|
||||
print("Episodes exhausted! Completing Playlist!\n")
|
||||
episodesEmptyFlag = True
|
||||
break
|
||||
#add commercial
|
||||
|
||||
#add commercial.
|
||||
nextAd = get_next_commercial()
|
||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||
playlist.write(nextAd + "\n")
|
||||
|
||||
#add commercial.
|
||||
nextAd = get_next_commercial()
|
||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||
playlist.write(nextAd + "\n")
|
||||
|
||||
else:
|
||||
#no time for furtur episodes this hour
|
||||
print("Not enough time for another episode this hour. Padding")
|
||||
|
||||
#add station id
|
||||
timeLeft -= get_video_length_in_seconds(stationID)
|
||||
playlist.write(stationID + "\n")
|
||||
|
||||
#add commercial.
|
||||
nextAd = get_next_commercial()
|
||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||
playlist.write(nextAd + "\n")
|
||||
|
||||
#add commercial.
|
||||
nextAd = get_next_commercial()
|
||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||
playlist.write(nextAd + "\n")
|
||||
|
||||
print("playlist file creation complete")
|
||||
|
Loading…
Reference in New Issue
Block a user