SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV v7 Customizations

Notices

SageTV v7 Customizations This forums is for discussing and sharing user-created modifications for the SageTV version 7 application created by using the SageTV Studio or through the use of external plugins. Use this forum to discuss plugins for SageTV version 7 and newer.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-18-2015, 05:57 PM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Question about tuning scripts and post recording commands

I'm attempting to integrate Sling TV with SageTV. My testing has gone well so far. I've piped the composite and audio output to my PVR150 capture card and can view the Roku on a channel I've set up. I can also launch the app and tune a specific station stream via a script that uses CURL to send virtual keypresses.

I thought that Sage could pass channel numbers to a script or exe but it seems my memory is failing me and perhaps that was MythTV or GBPVR/nPVR that had that functionality. Is there an easy way to accomplish this in SageTV? My plan is to set up a separate channel for each Sling TV channel and ideally I'd like Sage to pass that logical channel number to a script that will digest that channel number and call the right sequence of keypresses to launch the app and tune that channel stream.

Also, I would need to stop the stream at the end of the recording. Is there a mechanism that I can use to call a script that would send the keypresses to stop a stream? Otherwise I'd have SlingTV running all the time consuming much more bandwidth than necessary.

Here's my original reply to the thread outlining what I'm working on:

http://forums.sagetv.com/forums/show...8&postcount=20

Any info is greatly appreciated.
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #2  
Old 07-20-2015, 03:51 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
I think you're looking for the EXEMultiTunerPlugin (and yes, the file IS that old) to initiate your channel changes. Regarding triggering something at the end, I'm not sure what would work for you.

Keep in mind, this is if you are using Sage to interface with the capture card. Antoher alternative for you would be to create a network encoder, which would be a standalone program that listens to a TCP port, and gets plain text commands from sage to tune, start, and stop recordings.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #3  
Old 07-20-2015, 07:09 AM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Quote:
Originally Posted by Fuzzy View Post
I think you're looking for the EXEMultiTunerPlugin (and yes, the file IS that old) to initiate your channel changes. Regarding triggering something at the end, I'm not sure what would work for you.

Keep in mind, this is if you are using Sage to interface with the capture card. Antoher alternative for you would be to create a network encoder, which would be a standalone program that listens to a TCP port, and gets plain text commands from sage to tune, start, and stop recordings.
Thank you for your reply. I'm interested in the network encoder you mentioned. Can you tell me where to find more information? What information does Sage send? Is it something like channel number and filename to record to? If so, I could write a little script that takes the channel and 'tunes' to the right stream and then starts VLC or something similar to capture to the passed filename. I guess at the end of the recording or channel change Sage then passes a message to the network encoder to stop recording to the file?
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #4  
Old 07-20-2015, 09:43 AM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Quote:
Originally Posted by dinki View Post
Thank you for your reply. I'm interested in the network encoder you mentioned. Can you tell me where to find more information? What information does Sage send? Is it something like channel number and filename to record to? If so, I could write a little script that takes the channel and 'tunes' to the right stream and then starts VLC or something similar to capture to the passed filename. I guess at the end of the recording or channel change Sage then passes a message to the network encoder to stop recording to the file?
Yes, that's pretty much exactly what it is. Here is a copy of a VERY old copy of the network encoder API. This is as of sagetv version 1.4. There are more features in the API, such as autodiscovery and configuration, but they are a mystery to us until we get the source opened up, but this is enough to use for your purposes.
Attached Files
File Type: txt NetworkEncoderSDK.txt (4.7 KB, 86 views)
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #5  
Old 07-20-2015, 10:08 AM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Thank you very much. This is really cool indeed!
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #6  
Old 07-20-2015, 01:20 PM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Fuzzy, can you tell me what port this needs to be running on? I didn't see anything in the docs you sent. I'm not sure how Sage will be able to add this network tuner. In reading the docs it seems that it will autodiscover the tuner if I code it to send the NOOP command to the server, but I don't know what port the server is listening to.
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #7  
Old 07-20-2015, 08:51 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Quote:
Originally Posted by dinki View Post
Fuzzy, can you tell me what port this needs to be running on? I didn't see anything in the docs you sent. I'm not sure how Sage will be able to add this network tuner. In reading the docs it seems that it will autodiscover the tuner if I code it to send the NOOP command to the server, but I don't know what port the server is listening to.
The port can be whatever you want. To connect to a network encoder, you have to manually add a bunch of entries to the sage.properties file, and one of those properties is the network address and port of the encoder. This is where the auto-detection and configuration that was never documented might come in handy, once it is polished and ready for prime-time. For the list of properties you need to add, you can check out some of the other network encoder's setup tutorials (the most recent and 'live' network encoder project is the PrimeNetEncoder).
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #8  
Old 07-27-2015, 07:48 PM
jpwegas jpwegas is offline
Sage Aficionado
 
Join Date: May 2007
Posts: 480
dinki,
As Fuzzy mentions, the API and autodiscovery aren't fully officially documented.

I wrote a network encoder for SageTV called prime_encoder (see https://github.com/jwittkoski/prime_encoder), which allows the Sage server to tune channels on an HDHR Prime.

I really wanted installing it to be as seamless as possible so I did work out the details and implement autodiscovery in prime_encoder. No manual additions to the sage.properties file are required. I reviewed a combination of the document Fuzzy listed, several other network encoders that people have written and also did some network snooping to figure out how things worked.

There seemed to be multiple versions of the API (2.1, 3.0, and 4.1 are the ones I "saw" when testing). They have slightly different (mostly undocumented) formats and some of the commands are subtly different (i.e. different number of arguments or arguments in different order).

I only implemented what I needed to get prime_encoder working, so I can't guarantee that my code actually implements the API correctly. However, it has been working for myself and others for almost two years without any serious problems.

You may want to look at the code. It's not a complete API document but the code and comments might help. I haven't had time to better document what I learned.

I'll note that most of the code is "generic" as far as the autodiscovery and API goes - it's only the "tuning" and defining how to generate the video file that are specific to the Prime, so you could replace those parts with anything else that you need. I created an issue on the github project to make the code more generic to support other video "sources" but have not done any work on it.

--John
Reply With Quote
  #9  
Old 07-27-2015, 09:57 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
Quote:
Originally Posted by jpwegas View Post
dinki,
As Fuzzy mentions, the API and autodiscovery aren't fully officially documented.

I wrote a network encoder for SageTV called prime_encoder (see https://github.com/jwittkoski/prime_encoder), which allows the Sage server to tune channels on an HDHR Prime.

I really wanted installing it to be as seamless as possible so I did work out the details and implement autodiscovery in prime_encoder. No manual additions to the sage.properties file are required. I reviewed a combination of the document Fuzzy listed, several other network encoders that people have written and also did some network snooping to figure out how things worked.

There seemed to be multiple versions of the API (2.1, 3.0, and 4.1 are the ones I "saw" when testing). They have slightly different (mostly undocumented) formats and some of the commands are subtly different (i.e. different number of arguments or arguments in different order).

I only implemented what I needed to get prime_encoder working, so I can't guarantee that my code actually implements the API correctly. However, it has been working for myself and others for almost two years without any serious problems.

You may want to look at the code. It's not a complete API document but the code and comments might help. I haven't had time to better document what I learned.

I'll note that most of the code is "generic" as far as the autodiscovery and API goes - it's only the "tuning" and defining how to generate the video file that are specific to the Prime, so you could replace those parts with anything else that you need. I created an issue on the github project to make the code more generic to support other video "sources" but have not done any work on it.

--John
I've done the snooping as well, and yeah, it's not terribly difficult to figure out. I will definitely be involved in improving the API some once the source is opened up. First step will to actually document what IS implemented, find gaps, and then fill them, with a newer version of the API. Something I do want to add in, beyond just the tuning, is the ability for the API to optionally provide it's own channel mapping as well. Not always required, and not even possible on many source types, but there may be new sources in the future that would require them.
__________________
Buy Fuzzy a beer! (Fuzzy likes beer)

unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers.
Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA.
Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S
Other Clients: Mi Box in Master Bedroom, HD-200 in kids room
Reply With Quote
  #10  
Old 07-28-2015, 07:08 AM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Thank you both for the information. I'm planning on looking at all of this soon.
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #11  
Old 09-28-2015, 02:13 PM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
I've looked at prime_encoder source and see how it's sending the properties to the server via auto discovery, but I think that's too advanced for my skill level.

I'd like to manually create the device in sage.properties, and then work from there with the communications portion. I'm not a programmer but I can usually accomplish what I'm trying to do with some python scripts. The SDK document looks really straightforward as far as the commands go, but I could use some help setting things up on the server.

Can anyone tell me what additional properties I need to set to be able to tell sage the network encoder programs address and port? I'm guess there's also a properties option for telling the server that this is a network tuner as well? I'm thinking I can copy the mmc/encoders/ entries from one of devices, change the id # (these are just unique numbers?), name, etc, and set any additional options pertaining to this being a network tuner (address, port, etc).

Once I can at least talk to SageTV server I'm guessing the rest will be fairly straightforward. I'm already capable of scripting the sending of the tuning sequence to the roku and I have been able to set up an ffmpeg command that records the output of my capture card to a file. I just need to figure out how to set up the communications side between my SageTV server and the tuning and recording commands using the SDK linked above.

Any help with these configuration settings would be most appreciated.
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #12  
Old 09-29-2015, 08:38 AM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
To answer my own question. These properties work:

Code:
mmc/encoders/124/1/0/available_channels=
mmc/encoders/124/1/0/brightness=-1
mmc/encoders/124/1/0/broadcast_standard=
mmc/encoders/124/1/0/contrast=-1
mmc/encoders/124/1/0/device_name=
mmc/encoders/124/1/0/hue=-1
mmc/encoders/124/1/0/last_channel=2
mmc/encoders/124/1/0/provider_id=9999
mmc/encoders/124/1/0/saturation=-1
mmc/encoders/124/1/0/sharpness=-1
mmc/encoders/124/1/0/tuning_mode=Cable
mmc/encoders/124/1/0/tuning_plugin=
mmc/encoders/124/1/0/tuning_plugin_port=0
mmc/encoders/124/1/0/video_crossbar_index=0
mmc/encoders/124/1/0/video_crossbar_type=1
mmc/encoders/124/audio_capture_device_name=
mmc/encoders/124/broadcast_standard=
mmc/encoders/124/capture_config=2050
mmc/encoders/124/default_device_quality=
mmc/encoders/124/delay_to_wait_after_tuning=0
mmc/encoders/124/device_class=
mmc/encoders/124/encoder_merit=0
mmc/encoders/124/encoding_host=localhost\:4510
mmc/encoders/124/encoding_host_login_md5=
mmc/encoders/124/fast_network_encoder_switch=false
mmc/encoders/124/forced_video_storage_path_prefix=
mmc/encoders/124/last_cross_index=0
mmc/encoders/124/last_cross_type=1
mmc/encoders/124/live_audio_input=
mmc/encoders/124/multicast_host=
mmc/encoders/124/never_stop_encoding=false
mmc/encoders/124/video_capture_device_name=SageSlingBox-1
mmc/encoders/124/video_capture_device_num=0
mmc/encoders/124/video_encoding_params=Great
mmc/encoders/124/encode_digital_tv_as_program_stream=true
I'm now able to see SageTV server's communications via nc:

Code:
root@debian# nc -l -k -p 4510
VERSION
1
STOP
OK
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
  #13  
Old 10-02-2015, 08:28 AM
dinki's Avatar
dinki dinki is offline
Sage Expert
 
Join Date: Mar 2006
Posts: 682
Even a dummy (me) can do this

So I'm making great progress with my Python script. I've managed to pull enough information together to create a network device that listens for commands and acts upon them. I've done some testing and it does work though I have not added channel tuning yet. I am not a programmer, but perhaps this would be of benefit to someone thinking about writing a network encoder. It surely can be expanded but here's the basic version as it stands now:

Code:
import asyncio
import os
import subprocess

@asyncio.coroutine

def handler(reader, writer):
	global pid
	def send(msg):
		print("send to device: {}".format(msg))
		writer.write((msg + '\n').encode())

	print("device connected")
	while True:
		msg = yield from reader.readline()
		if not msg:
			print("device disconnected")
			break
		msg = msg.decode().strip()
		print("got from device: {}".format(msg))

		if msg == 'VERSION':
			send('1')
		elif msg == 'STOP':
			if pid:
				subprocess.Popen("TASKKILL /F /PID " + str(pid) + " /T")
				pid = ""
			send('OK')
		elif msg == 'NOOP':
			send('OK')
		elif "BUFFER" in msg:		
			msgsplit = msg.split('|')
			channel = msgsplit[1]
			size = msgsplit[2]
			filename = msgsplit[3]
			# Add change channel here
			recordcommand = ffmpeg_command + " -fs "+ size + " -y " + filename + " 2>NUL"
			pro = subprocess.Popen(recordcommand, shell=True)
			pid = pro.pid
		elif "GET_FILE_SIZE" in msg:
			msgsplit = msg.split(' ')
			filename = msgsplit[1]
			size = os.path.getsize(filename)
			send(str(size))
		elif "START" in msg:
			msgsplit = msg.split('|')
			channel = msgsplit[1]
			recordtime = str(int(msgsplit[2])/1000)  # Convert time from milli to seconds
			filename = msgsplit[3]
			# Add change channel here
			recordcommand = ffmpeg_command + " -t "+ recordtime + " -y " + filename + " 2>NUL"
			print (recordcommand)
			pro = subprocess.Popen(recordcommand, shell=True)
			pid = pro.pid

loop = asyncio.get_event_loop()
coro = asyncio.start_server(handler, '0.0.0.0', 4510, loop=loop)
server = loop.run_until_complete(coro)

global pid
ffmpeg_command='C:/Users/User/Desktop/ffmpeg-20150928-git-235381e-win64-static/bin/ffmpeg.exe -f dshow	-crossbar_video_input_pin_number 2	-i video="ATI AVStream Analog Capture" -f mpegts'


try:
	loop.run_forever()
except KeyboardInterrupt:
	pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
__________________
Intel Core i5-2500, 16GB RAM, OMV Linux 4.17, 3 TB of Data
SageTV 9 Docker, Open DCT Docker
Silicondust HDHomeRun Duo + Quatro
Sage Mini Client on Amazon Fire Sticks and Android TVs
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Could I pay one of you to write some SJQ scripts for me? FlyingShawn SageTV v7 Customizations 14 01-31-2012 04:09 AM
Scripts: SageTV backup scripts (dailly config, full weekly, full manual) robogeek SageTV Customizations 50 01-24-2012 07:24 AM
PRE and POST recording times.. HOW ?? vvulture SageTV Software 5 04-28-2007 10:26 PM
init scripts ChePazzo SageTV Linux 0 12-16-2006 12:28 PM
Question about Linking Infrared commands. flagg0204 SageTV Software 1 05-20-2004 09:42 PM


All times are GMT -6. The time now is 03:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.