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
|
edit /boot/config.txt
|
||||||
comment out all hdmi lines
|
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"
|
add "sdtv_mode=0" and "sdtv_aspect=1"
|
||||||
|
|
||||||
raspi-config
|
raspi-config
|
||||||
Advanced -> Compositor -> No
|
Advanced -> Compositor -> No
|
||||||
Display Options->Composite->Yes->Reboot Now
|
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
|
ancient abandoned esoteric animations or AAEA for short
|
||||||
|
71
faketv.py
71
faketv.py
@ -1,9 +1,10 @@
|
|||||||
|
import cv2
|
||||||
import datetime
|
import datetime
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import subprocess
|
import subprocess
|
||||||
from moviepy.editor import VideoFileClip
|
#from moviepy.editor import VideoFileClip
|
||||||
|
|
||||||
#The channel bug that displays while the channel is playing episodes
|
#The channel bug that displays while the channel is playing episodes
|
||||||
buglocation = "/media/zella/anime/aaeachannelbug.png"
|
buglocation = "/media/zella/anime/aaeachannelbug.png"
|
||||||
@ -19,13 +20,13 @@ episodeBlockTime = 1560
|
|||||||
minimumTime = 30
|
minimumTime = 30
|
||||||
|
|
||||||
def get_next_show_episode(showNumber):
|
def get_next_show_episode(showNumber):
|
||||||
if lineupStack[showNumber].empty():
|
if len(lineupStack[showNumber]) == 0:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return lineupStack[showNumber].pop()
|
return lineupStack[showNumber].pop()
|
||||||
|
|
||||||
def get_next_commercial():
|
def get_next_commercial():
|
||||||
if commercialStack.empty():
|
if len(commercialStack) == 0:
|
||||||
for file in os.listdir(commercials):
|
for file in os.listdir(commercials):
|
||||||
commercialStack.append(os.path.join(commercials,file))
|
commercialStack.append(os.path.join(commercials,file))
|
||||||
random.shuffle(commercialStack)
|
random.shuffle(commercialStack)
|
||||||
@ -36,9 +37,16 @@ def get_next_commercial():
|
|||||||
return commercialStack.pop()
|
return commercialStack.pop()
|
||||||
|
|
||||||
#requires moviepy module. rounded up to nearest whole second, for simplicity.
|
#requires moviepy module. rounded up to nearest whole second, for simplicity.
|
||||||
def get_video_length_in_seconds(videoFile):
|
#def get_video_length_in_seconds(videoFile):
|
||||||
clip = VideoFileClip(videoFile)
|
# clip = VideoFileClip(videoFile)
|
||||||
return math.ceil(clip.duration)
|
# 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():
|
def get_remaining_seconds_in_hour():
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
@ -72,12 +80,16 @@ for direc in os.listdir(shows):
|
|||||||
print("\nOpening show " + str(showNumber) + " folder: " + folder + "\n")
|
print("\nOpening show " + str(showNumber) + " folder: " + folder + "\n")
|
||||||
showEpisodes = []
|
showEpisodes = []
|
||||||
for file in os.listdir(folder):
|
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)
|
lineupStack.append(showEpisodes)
|
||||||
print("\n Added " + str(len(lineupStack[showNumber])) + " episodes from " + folder + "\n")
|
print("\n Added " + str(len(lineupStack[showNumber])) + " episodes from " + folder + "\n")
|
||||||
showNumberList.append(showNumber)
|
showNumberList.append(showNumber)
|
||||||
showNumber += 1
|
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:
|
#build season lineup station playlist using schedule:
|
||||||
@ -103,12 +115,6 @@ for direc in os.listdir(shows):
|
|||||||
#-random commercial block (2 minutes)
|
#-random commercial block (2 minutes)
|
||||||
#repeat until out of episodes
|
#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("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
||||||
print(" Building Playlist ")
|
print(" Building Playlist ")
|
||||||
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
|
||||||
@ -119,21 +125,22 @@ firstLoop = True
|
|||||||
while not episodesEmptyFlag:
|
while not episodesEmptyFlag:
|
||||||
if firstLoop:
|
if firstLoop:
|
||||||
timeLeft = get_remaining_seconds_in_hour()
|
timeLeft = get_remaining_seconds_in_hour()
|
||||||
|
firstLoop = False
|
||||||
else:
|
else:
|
||||||
timeLeft = secondsInHour
|
timeLeft = secondsInHour
|
||||||
random.shuffle(showNumberList)
|
random.shuffle(showNumberList)
|
||||||
showNumberListCount = 0
|
showNumberListCount = 0
|
||||||
while timeLeft > miniumTime:
|
while timeLeft > minimumTime:
|
||||||
if timeLeft >= episodeBlockTime:
|
if timeLeft >= episodeBlockTime:
|
||||||
print("Enough time for an episode block")
|
print("Enough time for an episode block")
|
||||||
#add station id
|
#add station id
|
||||||
timeLeft -= get_video_length_in_seconds(stationID)
|
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
|
#add commercial. Maybe add a while loop here to add multiple commercials if one is too short
|
||||||
nextAd = get_next_commercial()
|
nextAd = get_next_commercial()
|
||||||
timeLeft -= get_video_length_in_seconds(nextAd)
|
timeLeft -= get_video_length_in_seconds(nextAd)
|
||||||
playlist.write(nextAd)
|
playlist.write(nextAd + "\n")
|
||||||
|
|
||||||
#add tv episode
|
#add tv episode
|
||||||
nextEpisode = ""
|
nextEpisode = ""
|
||||||
@ -145,13 +152,41 @@ while not episodesEmptyFlag:
|
|||||||
else:
|
else:
|
||||||
showNumberListCount += 1
|
showNumberListCount += 1
|
||||||
timeLeft -= get_video_length_in_seconds(nextEpisode)
|
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
|
break
|
||||||
if nextEpisode is None:
|
if nextEpisode is None:
|
||||||
|
print("Episodes exhausted! Completing Playlist!\n")
|
||||||
episodesEmptyFlag = True
|
episodesEmptyFlag = True
|
||||||
break
|
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:
|
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