();
27 |
28 | var ipAddress = IPAddress.Parse(config.Slingbox.IPAddress);
29 | var port = config.Slingbox.Port;
30 | var username = config.Slingbox.Username;
31 | var password = config.Slingbox.AdminPassword;
32 |
33 | services.Add(new ServiceDescriptor(typeof(VideoStream), v => new VideoStream(), ServiceLifetime.Singleton));
34 | services.Add(new ServiceDescriptor(typeof(SlingboxService), v => new SlingboxService(ipAddress, port, username, password), ServiceLifetime.Singleton));
35 | }
36 |
37 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
38 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
39 | {
40 | if (env.IsDevelopment())
41 | {
42 | app.UseDeveloperExceptionPage();
43 | }
44 | //else
45 | //{
46 | // // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
47 | // app.UseHsts();
48 | //}
49 |
50 | //app.UseHttpsRedirection();
51 | app.UseMvc(r=> {
52 | r.MapRoute("DefaultApi", "api/{controller}/{id}");
53 | });
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Slingbox.Services/Model/InitialForceOkStatus.cs:
--------------------------------------------------------------------------------
1 | namespace Slingbox.Services.Model
2 | {
3 | [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.slingbox.com")]
4 | [System.Xml.Serialization.XmlRoot(Namespace = "http://www.slingbox.com", ElementName = "session", IsNullable = false)]
5 | public class InitialForceOKStatus
6 | {
7 |
8 | [System.Xml.Serialization.XmlElement("events")]
9 | public SessionAddress Events { get; set; }
10 |
11 |
12 | [System.Xml.Serialization.XmlElement("events_v2")]
13 | public SessionAddress EventsV2 { get; set; }
14 |
15 |
16 | [System.Xml.Serialization.XmlElement("events_reg")]
17 | public SessionAddress EventsReg { get; set; }
18 |
19 |
20 | [System.Xml.Serialization.XmlElement("caps")]
21 | public SessionAddress Caps { get; set; }
22 |
23 |
24 | [System.Xml.Serialization.XmlElement("avinputs")]
25 | public SessionAddress AVInputs { get; set; }
26 |
27 |
28 | [System.Xml.Serialization.XmlElement("current_avinput")]
29 | public SessionAddress CurrentAVInput { get; set; }
30 |
31 |
32 | [System.Xml.Serialization.XmlElement("streams")]
33 | public SessionAddress Streams { get; set; }
34 |
35 |
36 | [System.Xml.Serialization.XmlElement("device")]
37 | public SessionAddress Device { get; set; }
38 |
39 |
40 | [System.Xml.Serialization.XmlElement("whatison")]
41 | public SessionAddress WhatIsOn { get; set; }
42 |
43 |
44 | [System.Xml.Serialization.XmlElement("setup")]
45 | public SessionAddress Setup { get; set; }
46 |
47 |
48 | [System.Xml.Serialization.XmlElement("host_app")]
49 | public SessionAddress HostApp { get; set; }
50 |
51 |
52 | [System.Xml.Serialization.XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, AttributeName = "href", Namespace = "http://www.w3.org/1999/xlink")]
53 | public string SessionAddress { get; set; }
54 | }
55 |
56 | [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.slingbox.com")]
57 | public class SessionAddress
58 | {
59 | [System.Xml.Serialization.XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, AttributeName = "href", Namespace = "http://www.w3.org/1999/xlink")]
60 | public string Address { get; set; }
61 | }
62 | }
--------------------------------------------------------------------------------
/Slingbox.Capture.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29001.49
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Slingbox.Services.Test.Unit", "Slingbox.Services.Test.Unit\Slingbox.Services.Test.Unit.csproj", "{B629D4AF-9776-455B-A7D5-7041FD43E77F}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Slingbox.Services.Test.Integration", "Slingbox.Services.Test.Integration\Slingbox.Services.Test.Integration.csproj", "{F573C06A-FAF6-4371-AB50-8E9E6F66E868}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Slingbox.API", "Slingbox.API\Slingbox.API.csproj", "{58518E4F-2DA0-42CB-9EF9-589EE94F4B82}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Slingbox.Services", "Slingbox.Services\Slingbox.Services.csproj", "{B1655B90-C28E-49D0-84D3-3CC91C722595}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {B629D4AF-9776-455B-A7D5-7041FD43E77F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {B629D4AF-9776-455B-A7D5-7041FD43E77F}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {B629D4AF-9776-455B-A7D5-7041FD43E77F}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {B629D4AF-9776-455B-A7D5-7041FD43E77F}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {F573C06A-FAF6-4371-AB50-8E9E6F66E868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {F573C06A-FAF6-4371-AB50-8E9E6F66E868}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {F573C06A-FAF6-4371-AB50-8E9E6F66E868}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {F573C06A-FAF6-4371-AB50-8E9E6F66E868}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {58518E4F-2DA0-42CB-9EF9-589EE94F4B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {58518E4F-2DA0-42CB-9EF9-589EE94F4B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {58518E4F-2DA0-42CB-9EF9-589EE94F4B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {58518E4F-2DA0-42CB-9EF9-589EE94F4B82}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {B1655B90-C28E-49D0-84D3-3CC91C722595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {B1655B90-C28E-49D0-84D3-3CC91C722595}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {B1655B90-C28E-49D0-84D3-3CC91C722595}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {B1655B90-C28E-49D0-84D3-3CC91C722595}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {B6A4D5A9-F520-4C23-B742-EC083BA69901}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/Slingbox.Services/Model/DeviceStatus.cs:
--------------------------------------------------------------------------------
1 | namespace Slingbox.Services.Model
2 | {
3 | [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.slingbox.com")]
4 | [System.Xml.Serialization.XmlRoot(Namespace = "http://www.slingbox.com", ElementName = "device", IsNullable = false)]
5 | public class DeviceStatus
6 | {
7 | [System.Xml.Serialization.XmlElement("id")]
8 | public string Id { get; set; }
9 |
10 | [System.Xml.Serialization.XmlElement("product")]
11 | public string Product { get; set; }
12 |
13 | [System.Xml.Serialization.XmlElement("irblaster")]
14 | public string IRBlaster { get; set; }
15 |
16 | [System.Xml.Serialization.XmlElement("hardware_version")]
17 | public string HardwareVersion { get; set; }
18 |
19 | [System.Xml.Serialization.XmlElement("firmware_version")]
20 | public string FirmwareVersion { get; set; }
21 |
22 | [System.Xml.Serialization.XmlElement("firmware_date")]
23 | public string FirmwareDate { get; set; }
24 |
25 | [System.Xml.Serialization.XmlElement("mac")]
26 | public string MACAddress { get; set; }
27 |
28 | [System.Xml.Serialization.XmlElement("utf8_box_name")]
29 | public string UTF8BoxName { get; set; }
30 |
31 | [System.Xml.Serialization.XmlElement("name")]
32 | public string Name { get; set; }
33 |
34 | [System.Xml.Serialization.XmlElement("remote_config")]
35 | public string RemoteConfig { get; set; }
36 |
37 | [System.Xml.Serialization.XmlElement("remote_access")]
38 | public string RemoteAccess { get; set; }
39 |
40 | [System.Xml.Serialization.XmlArray("accounts")]
41 | public Account[] Accounts { get; set; }
42 |
43 | [System.Xml.Serialization.XmlElement("ip")]
44 | public IPInformation IPInformation { get; set; }
45 | }
46 |
47 | public class Account
48 | {
49 | [System.Xml.Serialization.XmlElement("name")]
50 | public string Name { get; set; }
51 |
52 | [System.Xml.Serialization.XmlElement("description")]
53 | public string Description { get; set; }
54 | }
55 |
56 | public class IPInformation
57 | {
58 | [System.Xml.Serialization.XmlElement("type")]
59 | public string Type { get; set; }
60 |
61 | [System.Xml.Serialization.XmlElement("address")]
62 | public string Address { get; set; }
63 |
64 | [System.Xml.Serialization.XmlElement("subnet_mask")]
65 | public string SubnetMask { get; set; }
66 |
67 | [System.Xml.Serialization.XmlElement("gateway")]
68 | public string Gateway { get; set; }
69 |
70 | [System.Xml.Serialization.XmlElement("port")]
71 | public string Port { get; set; }
72 |
73 | [System.Xml.Serialization.XmlElement("mtu")]
74 | public string MTU { get; set; }
75 |
76 | [System.Xml.Serialization.XmlElement("dns_preferred")]
77 | public string DNSPreferred { get; set; }
78 |
79 | [System.Xml.Serialization.XmlElement("dns_alernate")]
80 | public string DNSAlternate { get; set; }
81 | }
82 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Getting started
2 |
3 | This project was started (and stalled) several years ago. ~~As a result, it's running on .NET Framework 4.5.2.~~ **It now runs on .NET Core 2.2!** It consists of an API project and a helper class library (~~which are labeled backwards, don't ask me why~~ no longer labeled backwards!) See below for step-by-step instructions on getting started.
4 |
5 | ### Requirements
6 |
7 | 1. A Slingbox connected to your local network
8 | 1. A Slingbox account
9 | 1. Your Slingbox admin password (see below)
10 | 1. .NET Core 2.2
11 | 1. Visual Studio (or any other IDE/utility which compiles/runs .NET Core)
12 | 1. VLC Media Player
13 |
14 | #### Slingbox admin password
15 |
16 | Internally, the Slingbox itself uses an admin password to authenticate requests. To obtain this password:
17 |
18 | 1. Navigate to the following URL in a web browser: https://newwatchsecure.slingbox.com/watch/slingAccounts/account_boxes_js
19 | 1. Log in when prompted. If you are already logged in, the page should load.
20 | 1. You should see something similar to the JS below. The block below is formatted for readability. The admin password is bolded.
21 | 1. Copy this value and keep it somewhere safe.
22 |
23 | var sling_account_boxes = {
24 | "memberslingbox": {
25 | "abcdef1234567890": {
26 | "lookupByFinderId": true,
27 | "adminPassword": "your-admin-password ",
28 | "userPassword": "your-user-password",
29 | "finderId": "your-finder-id",
30 | "isOwner": true,
31 | "productSignature": 00,
32 | "passwordAutoMode": true,
33 | "displayName": "Your Slingbox Name",
34 | "memberSlingBoxId": 1234567
35 | }
36 | },
37 | "size": 1
38 | }
39 |
40 |
41 | #### Slingbox port
42 |
43 | 1. Open a new tab in Chrome or Firefox, and open dev tools.
44 | 1. Open the network tab.
45 | 1. Navigate to newwatch.slingbox.com, log in if you have to.
46 | 1. One of the requests in the network window should be to the following URL: http://newwatch.slingbox.com/watch/slingAccounts/get_slingbox_sparcs_info/?finderId=your-finder-id&_=1605380817768
47 | 1. In the JSON response object, one of the fields is devicePort. If that is different that 5207, sub that in to the appsettings.json file.
48 |
49 | ### Setup
50 | 1. Open the project in Visual Studio.
51 | 1. Edit `appsettings.json` within Slingbox.API.
52 | 1. Under the `Slingbox` key:
53 | 1. Insert the IP address of your Slingbox in the value for key `IPAddress`.
54 | 1. Insert the admin password acquired above in the value for key `AdminPassword`.
55 | 1. Build and begin debugging Slingbox.API. Open the Debug window, it will show `Starting web server... FINISHED. Press any key to quit.` when ready.
56 | 1. Open VLC.
57 | 1. In the Media menu, click "Open Network Stream".
58 | 1. Copy the following URL into the box: `http://localhost:9090/api/stream/slingbox`.
59 | 1. If everything worked, you should see some activity (see below) in the ~~console window~~ Debug window and the output of your cable box should appear in VLC.
60 |
61 | Starting web server... FINISHED. Press any key to quit.
62 | Issuing forceOkStatus request... COMPLETE
63 | Issuing device request... COMPLETE
64 | Issuing stream request... COMPLETE
65 | Opening video stream... COMPLETE
66 |
67 | Beginning stream playback...
68 |
69 |
--------------------------------------------------------------------------------
/Slingbox.API/Controllers/StreamController.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.IO;
3 | using System.Net;
4 | using Microsoft.AspNetCore.Mvc;
5 | using Slingbox.Services;
6 | using Slingbox.Services.Model;
7 |
8 | namespace Slingbox.API.Controllers
9 | {
10 | [Route("/api/stream")]
11 | public class StreamController : Controller
12 | {
13 | private readonly VideoStream _videoStream;
14 | private readonly SlingboxService _slingboxService;
15 | private bool _streamingStatus { get; set; }
16 |
17 | public StreamController(VideoStream videoStream, SlingboxService slingboxService)
18 | {
19 | _videoStream = videoStream;
20 | _slingboxService = slingboxService;
21 |
22 | _videoStream.PropertyChanged += _videoStream_PropertyChanged;
23 | }
24 |
25 | private void _videoStream_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
26 | {
27 | Debug.WriteLine("Property changed: " + e.PropertyName);
28 |
29 | if (e.PropertyName == "IsStreaming")
30 | {
31 | Debug.WriteLine($" Old value was: {_streamingStatus}");
32 | _streamingStatus = _videoStream.IsStreaming;
33 | Debug.WriteLine($" New value is: {_streamingStatus}");
34 | }
35 | }
36 |
37 | [Route("slingbox")]
38 | [HttpGet]
39 | public ActionResult Slingbox()
40 | {
41 | if (!_videoStream.IsStreaming)
42 | {
43 | Debug.Write("Issuing forceOkStatus request... ");
44 |
45 | _slingboxService.Initialize();
46 |
47 | Debug.WriteLine("COMPLETE");
48 |
49 | Debug.Write("Issuing device request... ");
50 |
51 | var deviceStatus = _slingboxService.GetDeviceStatus();
52 |
53 | Debug.WriteLine("COMPLETE");
54 |
55 | Debug.Write("Issuing stream request... ");
56 |
57 | var streamStatus = _slingboxService.InitializeStreams();
58 |
59 | Debug.WriteLine("COMPLETE");
60 |
61 | Debug.Write("Opening video stream... ");
62 |
63 | var streamResponse = _slingboxService.ConnectToStream("/streams/stream.asf");
64 | var videoStream = streamResponse.GetResponseStream();
65 |
66 | if (videoStream == null)
67 | {
68 | Debug.WriteLine("ERROR OCCURRED");
69 | HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
70 | }
71 | else
72 | {
73 | Debug.WriteLine("COMPLETE\r\n");
74 |
75 | Debug.WriteLine("Beginning stream playback...");
76 | HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
77 |
78 | _videoStream.IsStreaming = true;
79 |
80 | _videoStream.Stream = new BufferedStream(videoStream);
81 | }
82 | }
83 |
84 | if (_videoStream.IsStreaming)
85 | {
86 | return new FileStreamResult(_videoStream.Stream, "video/h264");
87 | }
88 |
89 | return new NoContentResult();
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Slingbox.Services/Model/StreamStatus.cs:
--------------------------------------------------------------------------------
1 | using System.Xml;
2 |
3 | namespace Slingbox.Services.Model
4 | {
5 | [System.Xml.Serialization.XmlType(AnonymousType = true, Namespace = "http://www.slingbox.com")]
6 | [System.Xml.Serialization.XmlRoot(Namespace = "http://www.slingbox.com", ElementName = "stream", IsNullable = false)]
7 | public class StreamStatus
8 | {
9 | [System.Xml.Serialization.XmlElement("lebowski_profile")]
10 | public string LebowskiProfile { get; set; }
11 |
12 | [System.Xml.Serialization.XmlElement("video")]
13 | public Video Video { get; set; }
14 |
15 | [System.Xml.Serialization.XmlElement("audio")]
16 | public Audio Audio { get; set; }
17 |
18 | [System.Xml.Serialization.XmlElement("encryption")]
19 | public string Encryption { get; set; }
20 |
21 | [System.Xml.Serialization.XmlArray("stream_links")]
22 | [System.Xml.Serialization.XmlArrayItem("stream_link")]
23 | public StreamLink[] StreamLinks { get; set; }
24 |
25 | [System.Xml.Serialization.XmlAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, AttributeName = "href", Namespace = "http://www.w3.org/1999/xlink")]
26 | public string StreamAddress { get; set; }
27 | }
28 |
29 | public class StreamLink
30 | {
31 | [System.Xml.Serialization.XmlAttribute("id", Namespace = "")]
32 | public string Id { get; set; }
33 |
34 | [System.Xml.Serialization.XmlAttribute("href", Namespace = "http://www.w3.org/1999/xlink")]
35 | public string Address { get; set; }
36 | }
37 |
38 | public class Audio
39 | {
40 | [System.Xml.Serialization.XmlElement("codec")]
41 | public string Codec { get; set; }
42 |
43 | [System.Xml.Serialization.XmlElement("mode")]
44 | public string Profile { get; set; }
45 |
46 | [System.Xml.Serialization.XmlElement("sampling")]
47 | public string Level { get; set; }
48 |
49 | [System.Xml.Serialization.XmlElement("bitrate")]
50 | public Rate Bitrate { get; set; }
51 | }
52 |
53 | public class Video
54 | {
55 | [System.Xml.Serialization.XmlElement("codec")]
56 | public string Codec { get; set; }
57 |
58 | [System.Xml.Serialization.XmlElement("profile")]
59 | public string Profile { get; set; }
60 |
61 | [System.Xml.Serialization.XmlElement("level")]
62 | public string Level { get; set; }
63 |
64 | [System.Xml.Serialization.XmlElement("resolution")]
65 | public string Resolution { get; set; }
66 |
67 | [System.Xml.Serialization.XmlElement("iframeinterval")]
68 | public string IframeInterval { get; set; }
69 |
70 | [System.Xml.Serialization.XmlElement("videomode")]
71 | public string VideoMode { get; set; }
72 |
73 | [System.Xml.Serialization.XmlElement("forceiframe")]
74 | public string ForceIframe { get; set; }
75 |
76 | [System.Xml.Serialization.XmlElement("prefiltering")]
77 | public string Prefiltering { get; set; }
78 |
79 | [System.Xml.Serialization.XmlElement("smoothness")]
80 | public string Smoothness { get; set; }
81 |
82 | [System.Xml.Serialization.XmlElement("bitrate")]
83 | public Rate Bitrate { get; set; }
84 |
85 | [System.Xml.Serialization.XmlElement("framerate")]
86 | public Rate Framerate { get; set; }
87 | }
88 |
89 | public class Rate
90 | {
91 | [System.Xml.Serialization.XmlElement("min")]
92 | public string Min { get; set; }
93 |
94 | [System.Xml.Serialization.XmlElement("max")]
95 | public string Max { get; set; }
96 | }
97 |
98 |
99 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.vspscc
94 | *.vssscc
95 | .builds
96 | *.pidb
97 | *.svclog
98 | *.scc
99 |
100 | # Chutzpah Test files
101 | _Chutzpah*
102 |
103 | # Visual C++ cache files
104 | ipch/
105 | *.aps
106 | *.ncb
107 | *.opendb
108 | *.opensdf
109 | *.sdf
110 | *.cachefile
111 | *.VC.db
112 | *.VC.VC.opendb
113 |
114 | # Visual Studio profiler
115 | *.psess
116 | *.vsp
117 | *.vspx
118 | *.sap
119 |
120 | # Visual Studio Trace Files
121 | *.e2e
122 |
123 | # TFS 2012 Local Workspace
124 | $tf/
125 |
126 | # Guidance Automation Toolkit
127 | *.gpState
128 |
129 | # ReSharper is a .NET coding add-in
130 | _ReSharper*/
131 | *.[Rr]e[Ss]harper
132 | *.DotSettings.user
133 |
134 | # TeamCity is a build add-in
135 | _TeamCity*
136 |
137 | # DotCover is a Code Coverage Tool
138 | *.dotCover
139 |
140 | # AxoCover is a Code Coverage Tool
141 | .axoCover/*
142 | !.axoCover/settings.json
143 |
144 | # Coverlet is a free, cross platform Code Coverage Tool
145 | coverage*.json
146 | coverage*.xml
147 | coverage*.info
148 |
149 | # Visual Studio code coverage results
150 | *.coverage
151 | *.coveragexml
152 |
153 | # NCrunch
154 | _NCrunch_*
155 | .*crunch*.local.xml
156 | nCrunchTemp_*
157 |
158 | # MightyMoose
159 | *.mm.*
160 | AutoTest.Net/
161 |
162 | # Web workbench (sass)
163 | .sass-cache/
164 |
165 | # Installshield output folder
166 | [Ee]xpress/
167 |
168 | # DocProject is a documentation generator add-in
169 | DocProject/buildhelp/
170 | DocProject/Help/*.HxT
171 | DocProject/Help/*.HxC
172 | DocProject/Help/*.hhc
173 | DocProject/Help/*.hhk
174 | DocProject/Help/*.hhp
175 | DocProject/Help/Html2
176 | DocProject/Help/html
177 |
178 | # Click-Once directory
179 | publish/
180 |
181 | # Publish Web Output
182 | *.[Pp]ublish.xml
183 | *.azurePubxml
184 | # Note: Comment the next line if you want to checkin your web deploy settings,
185 | # but database connection strings (with potential passwords) will be unencrypted
186 | *.pubxml
187 | *.publishproj
188 |
189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
190 | # checkin your Azure Web App publish settings, but sensitive information contained
191 | # in these scripts will be unencrypted
192 | PublishScripts/
193 |
194 | # NuGet Packages
195 | *.nupkg
196 | # NuGet Symbol Packages
197 | *.snupkg
198 | # The packages folder can be ignored because of Package Restore
199 | **/[Pp]ackages/*
200 | # except build/, which is used as an MSBuild target.
201 | !**/[Pp]ackages/build/
202 | # Uncomment if necessary however generally it will be regenerated when needed
203 | #!**/[Pp]ackages/repositories.config
204 | # NuGet v3's project.json files produces more ignorable files
205 | *.nuget.props
206 | *.nuget.targets
207 |
208 | # Microsoft Azure Build Output
209 | csx/
210 | *.build.csdef
211 |
212 | # Microsoft Azure Emulator
213 | ecf/
214 | rcf/
215 |
216 | # Windows Store app package directories and files
217 | AppPackages/
218 | BundleArtifacts/
219 | Package.StoreAssociation.xml
220 | _pkginfo.txt
221 | *.appx
222 | *.appxbundle
223 | *.appxupload
224 |
225 | # Visual Studio cache files
226 | # files ending in .cache can be ignored
227 | *.[Cc]ache
228 | # but keep track of directories ending in .cache
229 | !?*.[Cc]ache/
230 |
231 | # Others
232 | ClientBin/
233 | ~$*
234 | *~
235 | *.dbmdl
236 | *.dbproj.schemaview
237 | *.jfm
238 | *.pfx
239 | *.publishsettings
240 | orleans.codegen.cs
241 |
242 | # Including strong name files can present a security risk
243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
244 | #*.snk
245 |
246 | # Since there are multiple workflows, uncomment next line to ignore bower_components
247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
248 | #bower_components/
249 |
250 | # RIA/Silverlight projects
251 | Generated_Code/
252 |
253 | # Backup & report files from converting an old project file
254 | # to a newer Visual Studio version. Backup files are not needed,
255 | # because we have git ;-)
256 | _UpgradeReport_Files/
257 | Backup*/
258 | UpgradeLog*.XML
259 | UpgradeLog*.htm
260 | ServiceFabricBackup/
261 | *.rptproj.bak
262 |
263 | # SQL Server files
264 | *.mdf
265 | *.ldf
266 | *.ndf
267 |
268 | # Business Intelligence projects
269 | *.rdl.data
270 | *.bim.layout
271 | *.bim_*.settings
272 | *.rptproj.rsuser
273 | *- [Bb]ackup.rdl
274 | *- [Bb]ackup ([0-9]).rdl
275 | *- [Bb]ackup ([0-9][0-9]).rdl
276 |
277 | # Microsoft Fakes
278 | FakesAssemblies/
279 |
280 | # GhostDoc plugin setting file
281 | *.GhostDoc.xml
282 |
283 | # Node.js Tools for Visual Studio
284 | .ntvs_analysis.dat
285 | node_modules/
286 |
287 | # Visual Studio 6 build log
288 | *.plg
289 |
290 | # Visual Studio 6 workspace options file
291 | *.opt
292 |
293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
294 | *.vbw
295 |
296 | # Visual Studio LightSwitch build output
297 | **/*.HTMLClient/GeneratedArtifacts
298 | **/*.DesktopClient/GeneratedArtifacts
299 | **/*.DesktopClient/ModelManifest.xml
300 | **/*.Server/GeneratedArtifacts
301 | **/*.Server/ModelManifest.xml
302 | _Pvt_Extensions
303 |
304 | # Paket dependency manager
305 | .paket/paket.exe
306 | paket-files/
307 |
308 | # FAKE - F# Make
309 | .fake/
310 |
311 | # CodeRush personal settings
312 | .cr/personal
313 |
314 | # Python Tools for Visual Studio (PTVS)
315 | __pycache__/
316 | *.pyc
317 |
318 | # Cake - Uncomment if you are using it
319 | # tools/**
320 | # !tools/packages.config
321 |
322 | # Tabs Studio
323 | *.tss
324 |
325 | # Telerik's JustMock configuration file
326 | *.jmconfig
327 |
328 | # BizTalk build output
329 | *.btp.cs
330 | *.btm.cs
331 | *.odx.cs
332 | *.xsd.cs
333 |
334 | # OpenCover UI analysis results
335 | OpenCover/
336 |
337 | # Azure Stream Analytics local run output
338 | ASALocalRun/
339 |
340 | # MSBuild Binary and Structured Log
341 | *.binlog
342 |
343 | # NVidia Nsight GPU debugger configuration file
344 | *.nvuser
345 |
346 | # MFractors (Xamarin productivity tool) working folder
347 | .mfractor/
348 |
349 | # Local History for Visual Studio
350 | .localhistory/
351 |
352 | # BeatPulse healthcheck temp database
353 | healthchecksdb
354 |
355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
356 | MigrationBackup/
357 |
358 | # Ionide (cross platform F# VS Code tools) working folder
359 | .ionide/
360 |
361 | # Fody - auto-generated XML schema
362 | FodyWeavers.xsd
363 |
--------------------------------------------------------------------------------
/Slingbox.Services/SlingboxService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Net;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Xml.Serialization;
8 | using Slingbox.Services.Model;
9 |
10 | namespace Slingbox.Services
11 | {
12 | public class SlingboxService : IDisposable
13 | {
14 | private readonly IPAddress _ipAddress;
15 | private readonly int _port;
16 | private readonly string _username;
17 | private readonly string _password;
18 | private int _requestIndex = 1;
19 | private EventsForceOkStatus _heartbeatData;
20 | private Timer _timer;
21 | private bool _hasReceivedLastHeartbeat = true;
22 |
23 | private string _sessionURI { get; set; }
24 |
25 | ///
26 | ///
27 | ///
28 | ///
29 | ///
30 | ///
31 | ///
32 | public SlingboxService(IPAddress ipAddress, int port, string username, string password)
33 | {
34 | _ipAddress = ipAddress;
35 | _port = port;
36 | _username = username;
37 | _password = password;
38 | }
39 |
40 | public bool IsConnected { get; private set; }
41 |
42 | public void Initialize()
43 | {
44 | var uri = "?forceOkStatus";
45 |
46 | var body = "" +
47 | "" +
48 | " Austin Flash 10 client @ Windows 10 " +
49 | " ";
50 |
51 | var response = SendRequestToSlingbox(uri, body);
52 |
53 | if (!string.IsNullOrWhiteSpace(response.SessionAddress))
54 | {
55 | IsConnected = true;
56 | _sessionURI = response.SessionAddress;
57 | }
58 | }
59 |
60 | private void BeginHeartbeat()
61 | {
62 | _timer = new Timer(state => SendHeartbeat(), _heartbeatData, 0, 5000);
63 | }
64 |
65 | private void CancelHeartbeat()
66 | {
67 | _timer.Dispose();
68 | }
69 |
70 | public void SendHeartbeat()
71 | {
72 | if (_hasReceivedLastHeartbeat)
73 | {
74 | _hasReceivedLastHeartbeat = false;
75 | _heartbeatData = GetEventStatus();
76 | _hasReceivedLastHeartbeat = true;
77 | }
78 | }
79 |
80 | public DeviceStatus GetDeviceStatus()
81 | {
82 | var uri = "/device?Method=GET&forceOkStatus";
83 | var body = "dummy";
84 |
85 | return SendRequestToSlingbox(uri, body);
86 | }
87 |
88 | public EventsForceOkStatus GetEventStatus()
89 | {
90 | var uri = "/events?Method=GET&forceOkStatus&timeout=5";
91 | var body = "dummy";
92 |
93 | return SendRequestToSlingbox(uri, body);
94 | }
95 |
96 | public DisconnectStatus Disconnect()
97 | {
98 | var uri = "?Method=DELETE&forceOkStatus";
99 | var body = "dummy";
100 |
101 | CancelHeartbeat();
102 |
103 | return SendRequestToSlingbox(uri, body);
104 | }
105 |
106 | public StreamStatus InitializeStreams()
107 | {
108 | var uri = "/streams?forceOkStatus";
109 | var body = "" +
110 | "" +
111 | " 2 " +
112 | " " +
113 | " h264 " +
114 | " high " +
115 | " 4.0 " +
116 | " 640x480 " +
117 | " " +
118 | " 1200 " +
119 | " 10000 " +
120 | " " +
121 | " " +
122 | " 5 " +
123 | " 30 " +
124 | " " +
125 | " " +
126 | " " +
127 | " AAC " +
128 | " stereo " +
129 | " " +
130 | " 32 " +
131 | " 96 " +
132 | " " +
133 | " " +
134 | " ";
135 |
136 | BeginHeartbeat();
137 |
138 | return SendRequestToSlingbox(uri, body);
139 | }
140 |
141 | public dynamic GetStream(string uri)
142 | {
143 | return SendRequestToSlingbox(uri);
144 | }
145 |
146 | private T SendRequestToSlingbox(string uri, string body = null) where T : class
147 | {
148 | var response = SendRequestToSlingbox(uri, body);
149 | var responseStream = response.GetResponseStream();
150 |
151 | if (responseStream == null)
152 | return null;
153 |
154 | var serializer = new XmlSerializer(typeof(T));
155 |
156 | return (T) serializer.Deserialize(responseStream);
157 | }
158 |
159 | public HttpWebResponse ConnectToStream(string uri)
160 | {
161 | if (!IsConnected && !string.IsNullOrWhiteSpace(_sessionURI))
162 | throw new Exception("Not connected to Slingbox. Call Initialize() method first.");
163 |
164 | // if URI was passed in with a leading slash, remove it
165 | if (uri.StartsWith("/"))
166 | uri = uri.Substring(1);
167 |
168 | var request = WebRequest.CreateHttp($"http://{_ipAddress}:{_port}/slingbox{_sessionURI}/{uri}");
169 | request.Method = WebRequestMethods.Http.Get;
170 | request.KeepAlive = true;
171 | request.Headers["Origin"] = "http://download.slingmedia.com";
172 | request.Headers["X-Requested-With"] = "ShockwaveFlash/23.0.0.207";
173 | request.Headers["Sling-Authorization"] = GenerateSlingAuthorizationHeader(_requestIndex, _username, _sessionURI, _password);
174 | request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36";
175 | request.Headers["Pragma"] = "Sling-Connection-Type=Stream, Session-Id=0";
176 | //request.ContentType = "text/xml";
177 | request.Accept = "*/*";
178 | request.Referer = "http://download.slingmedia.com/player/embedded/v28/austinapp.swf";
179 | //request.Headers["Accept-Encoding"] = "gzip, deflate";
180 | //request.Headers["Accept-Language"] = "en-US,en;q=0.8";
181 |
182 | _requestIndex++;
183 |
184 | var response = (HttpWebResponse)request.GetResponse();
185 |
186 | return response;
187 | }
188 |
189 | private HttpWebResponse SendRequestToSlingbox(string uri, string body = null)
190 | {
191 | if (!IsConnected && !string.IsNullOrWhiteSpace(_sessionURI))
192 | throw new Exception("Not connected to Slingbox. Call Initialize() method first.");
193 |
194 | // if URI was passed in with a leading slash, remove it
195 | if (uri.StartsWith("/"))
196 | uri = uri.Substring(1);
197 |
198 | var request = WebRequest.CreateHttp($"http://{_ipAddress}:{_port}/slingbox{_sessionURI}/{uri}");
199 | request.Method = WebRequestMethods.Http.Post;
200 | request.KeepAlive = true;
201 | request.Headers["Origin"] = "http://download.slingmedia.com";
202 | request.Headers["X-Requested-With"] = "ShockwaveFlash/23.0.0.207";
203 | request.Headers["Sling-Authorization"] = GenerateSlingAuthorizationHeader(_requestIndex, _username, _sessionURI, _password);
204 | request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36";
205 | request.ContentType = "text/xml";
206 | request.Accept = "*/*";
207 | request.Referer = "http://download.slingmedia.com/player/embedded/v28/austinapp.swf";
208 | request.Headers["Accept-Encoding"] = "gzip, deflate";
209 | request.Headers["Accept-Language"] = "en-US,en;q=0.8";
210 |
211 | if (!string.IsNullOrWhiteSpace(body))
212 | {
213 | using (var requestStream = request.GetRequestStream())
214 | using (var streamWriter = new StreamWriter(requestStream))
215 | {
216 | streamWriter.Write(body);
217 | }
218 | }
219 |
220 | _requestIndex++;
221 |
222 | var response = (HttpWebResponse) request.GetResponse();
223 |
224 | return response;
225 | }
226 |
227 | private static string GenerateSlingAuthorizationHeader(int requestIndex, string username, string numericURIComponent, string password)
228 | {
229 | var cnonce = Guid.NewGuid().ToString("N").ToLower();
230 | var digest = GenerateDigestHash(requestIndex, username, cnonce, numericURIComponent, password);
231 |
232 | var slingAuthorizationHeader = $"account={username}, counter={requestIndex}, cnonce={cnonce}, digest={digest}";
233 |
234 | return slingAuthorizationHeader;
235 | }
236 |
237 | private static string GenerateDigestHash(int requestIndex, string username, string cnonce, string numericURIComponent, string password)
238 | {
239 | var md5 = MD5.Create();
240 | md5.Initialize();
241 |
242 | var digestComponents = $"{username}:{numericURIComponent}:{cnonce}:{requestIndex}:{password}";
243 | var digestComponentsBytes = Encoding.ASCII.GetBytes(digestComponents);
244 | var digestBytes = md5.ComputeHash(digestComponentsBytes);
245 |
246 | var sb = new StringBuilder();
247 | foreach (var digestByte in digestBytes)
248 | {
249 | sb.Append(digestByte.ToString("X2"));
250 | }
251 | return sb.ToString().ToLower();
252 | }
253 |
254 | public void Dispose()
255 | {
256 | if (IsConnected)
257 | {
258 | Disconnect();
259 | }
260 | }
261 | }
262 | }
263 |
--------------------------------------------------------------------------------