Created
July 6, 2022 21:04
-
-
Save rsheldiii/7a7bb3d020cdfc590e9db70645ff02f3 to your computer and use it in GitHub Desktop.
John Stewart raspberry pi service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /home/pi/johnstewart.rb | |
require 'pp' | |
# monke | |
class String | |
def naturalized | |
scan(/[^\d\.]+|[\d\.]+/).collect { |f| f.match(/\d+(\.\d+)?/) ? f.to_f : f } | |
end | |
end | |
episode_path = "/home/pi/Episodes" | |
counter = "/home/pi/.johnstewart" | |
`touch #{counter}` | |
episodes = Dir["#{episode_path}/*.mp4"].sort_by { |f| f.naturalized } | |
puts "total episodes: #{episodes.length}" | |
previous_episode = File.open(counter).read | |
puts "raw previous episode: #{previous_episode}" | |
previous_episode = episodes.first if previous_episode == "" or not episodes.include? previous_episode | |
puts "actual previous episode: #{previous_episode}" | |
episodes = episodes.drop_while { |episode| episode != previous_episode } if previous_episode != episodes.last | |
puts "episodes left: #{episodes.length}" | |
episodes.each do |episode| | |
puts "writing #{episode} to counter..." | |
File.write(counter, episode) | |
puts "opening #{episode}..." | |
`/usr/bin/omxplayer "#{episode}"` | |
end | |
# o | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/johnstewart.service | |
[Unit] | |
Description=The Daily Show with John Stewart | |
Before=systemd-user-sessions.service | |
[Service] | |
TimeoutStartSec=0 | |
# removed -r and -o hdmi | |
#ExecStart=/usr/bin/omxplayer --loop "/home/pi/Episodes/s4e1.mp4" | |
ExecStart=/usr/bin/ruby /home/pi/johnstewart.rb | |
Type=simple | |
User=pi | |
ExecStop=/usr/bin/killall omxplayer | |
User=pi | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment