[ExtractStream] ReceiveStream

Warren Toomey wkt at t...
Sat, 13 Jul 2002 08:58:28 +1000 (EST)


---------------------- multipart/mixed attachment
In article by Bob Gamble:
> Is there anyway to put a stream back on TiVo and have it accessible via Now Showing?
> It would be nice to be able to do this as it makes it easier for members of the family to watch archived material since random access is better than tape. Also could be used to reduce paying charges for not returning videos on time.
> Bob

Yes. You need to extract a tystream, then split it into mpv and mpa components,
then make these visible to the TiVo on a filesystem (e.g hard disk, nfs, smbfs).
The script is attached to put the two components back into Now Showing.

Warren

---------------------- multipart/mixed attachment
#!/tvbin/tivosh
#
# This script takes the elementary audio and video components of a TyStream
# (such as created by vsplit) in the Unix filesystem, copies these two files
# into the MFS and makes a TyStream. It then makes a NowShowing program
# entry so that you can watch it!
#
# Someone (who?) wrote most of this. Warren just added the bit to
# copy the Unix files into the MFS.
#
source $tcl_library/tv/mfslib.tcl

#
# Usage
# 
proc Usage {} {
puts {Usage: file-to-recording filename MFSname title time duration}
puts { Filename is the Unix filename without .mpv or .mpa}
puts { MFSname is the MFS filename with no slashes}
puts { title is a single word, or a phrase in double quotes}
puts { time is the start time: seconds since midnight tonight, e.g 0}
puts { duration is in seconds, e.g 3600}
exit
}

proc RecordMovie {unixPath mfsPath} {
global env
set TIVO_ROOT $env(TIVO_ROOT)
if {[RetryTransaction {catch {mfs find $mfsPath}}]} {
puts "Recording $unixPath to $mfsPath ..."
exec $TIVO_ROOT/tvbin/ele2pestriple $unixPath.mpv $unixPath.mpa $mfsPath
} else {
puts "MFS movie $mfsPath already exists."
exit
}
}

#
# I do not use the regular RetryTransaction because I do not like the fact
# it adds a puts in the middle if a transaction fails
proc MyRetryTransaction { body } {
global errorInfo errorCode

while { 1 } {
set code [catch {transaction {uplevel $body}} string]
if { $code == 0 } {
return $string
} elseif { $code == 1 } {
if { $errorCode == "errTmActiveLockConflict" ||
$errorCode == "errTmBackgroundHoldoff" ||
$errorCode == "errFsLockConflict" } {
after 100
# retry the transaction
continue
}
return -code error -errorinfo $errorInfo -errorcode $errorCode $string
} elseif { $code == 2 } {
return -code return $string
} elseif { $code == 3 } {
return -code break $string
} elseif { $code == 4 } {
return -code continue $string
}
}
}



#
# Main Part
#

if {$argc != 5} { Usage }

set today [expr [clock seconds] / 86400]
set now [expr [clock seconds] % 86400]
set date $today ;# days since 1970

set filename [lindex $argv 0]
set path [lindex $argv 1]
set title [lindex $argv 2]
set startTime [lindex $argv 3]
set duration [lindex $argv 4]


#
# Copy the file over to an MFS tystream
#
RecordMovie $filename /Recording/TmsId/$path

# Get a handle to the database
set db [dbopen]

# Create a recording object (with a bogus showing) that
# holds the stream file, and unlink it from its old location.
# (If it's not unlinked, MyWorld will be unable to delete it.)

MyRetryTransaction {

# figure out the fsid
set info [mfs find /Recording/TmsId/$path]
set fsid [lindex $info 0]
mfs unlink /Recording/TmsId/$path

# create the recording
set recording [db $db create Recording]
dbobj $recording set BitRate 0 ;# obsolete
dbobj $recording set ErrorString "test recording"
dbobj $recording set ExpirationDate [expr $today + 2]
dbobj $recording set ExpirationTime 0 ;# midnight
dbobj $recording set RecordQuality 100
dbobj $recording set Score 0
dbobj $recording set SelectionType 5 ;# explicit timer
dbobj $recording set StartDate $date
dbobj $recording set StartTime $startTime
dbobj $recording set State 4 ;# complete
dbobj $recording set StopDate $date
dbobj $recording set StopTime [expr $startTime + $duration]


# create a part
set part [db $db createsub RecordingPart $recording]
dbobj $part set Begin 0
dbobj $part set End [expr $duration * 1000]
dbobj $part set File $fsid
dbobj $recording add Part $part


# create a dummy program
set program [db $db create Program]
dbobj $program set Title $title


# create a dummy station
set station [db $db create Station]
dbobj $station set CallSign "Tuner2"
dbobj $station set Name "Tuner2"

# create a showing
set showing [db $db createsub Showing $recording]
dbobj $showing set Date $date
dbobj $showing set Duration $duration
dbobj $showing set Program $program
dbobj $showing set Station $station
dbobj $showing set Time $startTime
dbobj $recording set Showing $showing
puts [ dbobj $recording fsid ]
}

---------------------- multipart/mixed attachment--