Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Beta of 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Charron committed Oct 6, 2010
2 parents 75dc418 + e3fdbe7 commit 5867ee3
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 1,093 deletions.
2 changes: 0 additions & 2 deletions .bzrignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
*.kpf
*.geany
*.log
toueid
mplayer.out
touei_run.out
build
uninstall.db
cfg/geany_run_script.sh
48 changes: 2 additions & 46 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
touei README
HYBERIA README
============

Version : 0.2.1
Expand Down Expand Up @@ -53,50 +53,6 @@ DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS PACKAGE.
* Your video file with specific filename
* Enough of disk space for the video muxing

@TODO: Missing how to configure xorg and initrc
@TODO: add source for software

There is NO check if those programs are installed. You should make sure they are.

4) Prerequisites
----------------

** filename pattern **

First you need to rename your file according to a specific pattern:
- The first 4 characters are the time the video will be played in
24 military hours format (4h00 PM = 1600).
Minutes need to comply with a modulus 5, meaning must be a multiple of 5. 1604 is invalid.

- A dot "."

- The name of the video. it will be used for the subtitling of the
introduction video. It NEEDS to be unique.
NO SPACE. Use underscores, they will be replaced by space. Also, don't
worry about the case, it will be `Title` for the intro video.

- The ".mkv" string for extension.

If you want to play "Higurashi no Naku Koro ni" at 3h45 PM the filename
will be:

1545.Higurashi_no_Naku_Koro_ni.mkv

DO NOT PUT SPECIAL CHARACTERS IN THE FILENAME, PARSING WILL BREAK

** File structure **

The file structure is simple, inside the folder in the LOCATION config
entry you will need one folder for each day. The name of the folder is a
zero padded day of the month(04 for the 4th of the month,10 for the 10th of the month).
If the location does not exist, the script will die.
The script will also create the folder structure in the TMP-LOCATION.
If you are not sure what is the structure delete the TMP-LOCATION folder
and it will be recreated.

Since the default is in the /tmp you shouldn't worry to much, as it is wiped
at each reboot. Just make sure there is enough space for the intro videos.


5) Installation
---------------
Expand All @@ -105,7 +61,7 @@ Until there is a better way to install this setup, follow these instructions:

- Execute as root:
./install.sh
It will build and install toueid and readconfig then execute setup.py.
It will build and install hyberiactl and readconfig then execute setup.py.

This accepts the following arguments: install, uninstall, clean

Expand Down
14 changes: 7 additions & 7 deletions cfg/hyberia.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
; This file should be locate at /etc/hyberia.conf
[core]
; Location of the YAML playlist file
; Default: /mnt/video/playlist.yaml
playlist: /mnt/video/playlist.yaml
; Default: /mnt/video/playlist.json
playlist: cfg/playlist.json

; the location of pid file for the mplayer process will be located
; Default: /var/pid/touei.pid
; Default: /var/pid/hyberia.pid
pid: /var/pid/hyberia.pid

; Location of the FIFO slave socket file (used for control)
; Default: /tmp/touei_slave.fifo
; Default: /tmp/hyberia_slave.fifo
slave_socket: /tmp/hyberia_slave.fifo

[logs]
; Location of the logs for the python script
; Default: touei_main.log
; Default: hyberia_main.log
main_log: /tmp/hyberia_main.log

; Level of debug. Possible value are:
Expand Down Expand Up @@ -61,5 +61,5 @@ location: /mnt/video
intro: /mnt/video/intro.mkv

; Location for the intro/outro files
; default: /tmp/touei
tmp-location: /tmp/touei
; default: /tmp/hyberia
tmp-location: /tmp/hyberia
4 changes: 2 additions & 2 deletions cfg/intro.empty.ass
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; This script was created by touei %s
; http://elwillow.net/touei
; This script was created by hyberia %s
; http://elwillow.net/hyberia
ScriptType: V4.00+
Timer: 100.0000

Expand Down
8 changes: 4 additions & 4 deletions cfg/playlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

},
"blocks":{
"20100917":{
"0000": {
"20101005":{
"0313": {
"name" : "Evangelion",
"description": "Evangelion TV serie remastered",
"parts": [
Expand All @@ -31,7 +31,7 @@
"sponsor_01"
]
},
"0120": {
"0340": {
"name" : "Nana",
"description": "Nana TV serie",
"parts": [
Expand All @@ -46,4 +46,4 @@
}
}
}
}
}
3 changes: 1 addition & 2 deletions hyberia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

__all__ = ["player", "playlist", "mkvutils", "daemon"]

CONFIG_DEFAULT_VALUE={"playlist": "/mnt/video/playlist.yaml",
CONFIG_DEFAULT_VALUE={"playlist": "cfg/playlist.json",
"pid": "/var/pid/hyberia.pid",
"slave_socket": "/tmp/hyberia_slave.fifo",
"main_log": "/tmp/hyberia_main.log",
Expand All @@ -42,6 +42,5 @@
"block_duration": "60",
"loop_sleep": "10",
"location": "/mnt/video",
"intro": "/mnt/video/intro.mkv",
"tmp-location": "/tmp/hyberia",
}
131 changes: 59 additions & 72 deletions hyberia/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@

__author__ = "G-Anime"
__license__ = "Eiffel Version 2"
__version__ = "0.3.2"
__version__ = "0.4"
__contributors__= "Mathieu Charron, Martin Samson"

import time, signal, datetime, os, sched
import time, signal, datetime, os, sched, logging
import mkvutils

# Instanciate the logging
import logging
logger = logging.getLogger("hyberia.daemon")

class HyberiaDaemon():
"""This class provide a way to keep the video database in memory and
Expand All @@ -43,7 +40,6 @@ class HyberiaDaemon():
def __init__(self, playlist, player, config, mkv):
# Instanciate the logger
self.logger = logging.getLogger("hyberia.daemon")
self.logger.info("Creating instance")

signal.signal (signal.SIGTERM, self._signalTerm)
signal.signal (signal.SIGINT, self._signalTerm)
Expand All @@ -61,31 +57,33 @@ def __init__(self, playlist, player, config, mkv):
def stop(self):
"""Stop the loop
"""
self.logger.debug("stop() called")
self.logger.debug("stop called")
self._Player.stop()
map(self.__scheduler.cancel, self.__scheduler.queue)

def secondsDelta(self, blockStart):
"""Return the number of seconds since the begining of the current block
@param string blockStart
"""
delta = datetime.datetime.now() - datetime.datetime.strptime(str(blockStart),"%Y%m%d%H%M")
print delta
self.logger.debug("BLOCK DELTA IS %d SECONDS" % (delta.seconds, ) )
return delta.seconds

def run(self):
"""Main daemon routine
"""
self.logger.debug("Entering Run")
self.__scheduler.enter(0,1, self.events, ())
self.__scheduler.run()

def play(self,duration,playList):
def play(self,duration,playList, seekTo = 0):
#TODO: play the playlist!

#Schedule next event check
print "scheduling end of block in %s seconds" % duration

self.logger.info("Scheduling end of block in %s seconds" % duration)

first = True
for file in playList:
if first:
self._Player.openFile(file,False)
first = False
else:
self._Player.openFile(file,True)

if seekTo > 0:
self._Player.seek(True,seekTo)

self.__scheduler.enter(duration, 1, self.events,())
return

Expand All @@ -99,19 +97,19 @@ def events(self):

block = self._Playlist.getCurrentBlock()
if not block:
self.logger.info("Nothing to play.")
self.__scheduler.enter(10,1,self.events, ())
self.logger.debug("nothing to play.")
#TODO: Get next block and timeout
#TODO: Get next playing block
return

self.logger.debug("preparing to play block %s" % block['id'])
self.logger.info("Preparing to play block %s" % block['id'])
curTime = int(time.time())

#Transfer in seconds and determine if the presentation isa lready in progress (recovery) or will play next.
if curTime > block['id']:

#Recovery
self.logger.debug("block has already started. preparing to seek to file.")
self.logger.info("Block has already started. Preparing to seek to file.")

curPart = None
playList = []
Expand All @@ -129,75 +127,64 @@ def events(self):
self.__scheduler.enter(10,1,self.events,())
return

self.logger.debug("verifying if playing %s" % repr(curPart))
self.logger.debug("Verifying if playing %s" % repr(curPart))

blockStopAt = (block['id'] + block['totalRunTime'])

if curTime > blockStopAt:
self.logger.debug("current block has ended. no possible recovery")
self.logger.debug("Current block has ended. No possible recovery")
self.__scheduler.enter(30,1,self.events,())
return

if curTime > curPart['playAt']:
self.logger.debug("part should currently be playing.")

seekTo = curTime - curPart['playAt']

duration = curTime - block['id']

#Give 30 sec back to the people?
if seekTo > 180:
seekTo -= 180
duration -= 180
else:
self.logger.debug("Part should be currently playing.")

playList.insert(0, curPart['file'])

#seek to the time it should be playing and remove 1 minute for recovery
seekTo = curTime - curPart['playAt'] - 60

if (seekTo < 0):
seekTo = 0

#TODO: Send playlist and seek
self.__scheduler.enter(0,1,self.play,(duration,playList))

duration = block['totalRunTime'] - seekTo

self.__scheduler.enter(0,1,self.play,(duration,playList,seekTo))

return

#if we fall here... something very weird has happened...
self.logger.critical("got to the end of recovery process with nothing to recover.")
self.logger.critical("At the end of recovery process with nothing to recover.")
self.__scheduler.enter(1,1,self.events,())
return

else:
#Play next
timeTillBlock = block['id'] - curTime
self.logger.debug("block will start in %s seconds" % timeTillBlock)
self.__scheduler.enter(timeTillBlock,1,self.play,(block,))
self.logger.debug("Playing block in %s seconds" % timeTillBlock)

playList = []
for part in block['parts']:
playList.append(part['file'])

duration = block['totalRunTime']
seekTo = 0

intro_file = self._MkvUtils.generate_intro(playList[0])
if intro_file:
if timeTillBlock > 10:
timeTillBlock -= 10
else:
seekTo = 10 - timeTillBlock

playList.insert(0,intro_file)

self.__scheduler.enter(timeTillBlock,1,self.play,(duration,playList,seekTo))
return

def comp_dates(self, d1, d2):
# Date format: %Y-%m-%d %H:%M:%S
return time.mktime(time.strptime(d2,"%Y%m%d%H%M%S"))-\
time.mktime(time.strptime(d1, "%Y%m%d%H%M%S"))

def _getFormattedDateTime(self, format = "%Y%m%d%H%M"):
return int(datetime.datetime.now().strftime(format))

def _signalTerm(self,signal,frame):
"""Will exit the loop and let the application close.
"""
self.logger.warn("SIGNTERM signal received, quitting")
self._isRunning = False
map(self.__scheduler.cancel, self.__scheduler.queue)


if __name__ == "__main__":
print "##### DEBUG ######"

ch = logging.StreamHandler()
cformatter = logging.Formatter("[%(levelname)s] %(name)s - %(message)s")
ch.setFormatter(cformatter)
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)

from mkvutils import MkvUtils
from playlist import PlayList
m = MkvUtils()
p = PlayList(m)
p.load('../cfg/playlist.json')

#(self, playlist, player, config, mkv)
d = HyberiaDaemon(p,None,None,m)
d.run()
map(self.__scheduler.cancel, self.__scheduler.queue)
Loading

0 comments on commit 5867ee3

Please sign in to comment.