Skip to content

Commit

Permalink
Add additional exception handling and logging around the GetRecording…
Browse files Browse the repository at this point in the history
…URL() function
  • Loading branch information
margro committed Dec 10, 2016
1 parent b09c2cd commit 3456cde
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 38 deletions.
1 change: 1 addition & 0 deletions TVServerKodi/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.15.0.136:
- Added: Support for detecting the recording type (TV, Radio, webstream)
- Fixed: Add additional exception handling around the GetRecordingURL() function

1.15.0.135:
- Added: IPv6 support (Vista and above)
Expand Down
208 changes: 208 additions & 0 deletions TVServerKodi/Installer/MPEI_update_1_10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,214 @@
<ValueType>Template</ValueType>
<Description>The file used to configure the extension.
If it has .exe extension the will be executed.
If it has .dll extension it's started like MP plugin configuration.</Description>
</SectionParam>
<SectionParam Name="Online Screenshots">
<Value />
<ValueType>String</ValueType>
<Description>Online stored screenshot urls separated by ; </Description>
</SectionParam>
<SectionParam Name="Force to uninstall on update">
<Value>yes</Value>
<ValueType>Bool</ValueType>
<Description>Show dialog and force to uninstall previous version when updating an extension. Should only be disabled if you are using an NSIS/MSI installer.</Description>
</SectionParam>
</Items>
</Params>
</GeneralInfo>
<UniqueFileList>
<Items />
</UniqueFileList>
<ProjectSettings>
<FolderGroups />
</ProjectSettings>
<IsSkin>false</IsSkin>
</PackageClass>
<PackageClass>
<Version>2.0</Version>
<Groups>
<Items>
<GroupItem Name="TVServer_plugin">
<DisplayName>TVServer_plugin</DisplayName>
<DefaulChecked>true</DefaulChecked>
<Description>TVServer_plugin</Description>
<Files>
<Items />
</Files>
</GroupItem>
</Items>
</Groups>
<Sections>
<Items />
</Sections>
<Dependencies>
<Items>
<DependencyItem>
<Type>Installer</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>5</Minor>
<Build>0</Build>
<Revision>0</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>20</Minor>
<Build>999</Build>
<Revision>0</Revision>
</MaxVersion>
<WarnOnly>true</WarnOnly>
<Message>requires at least MPEI 1.5.x</Message>
<Name>MPEI</Name>
</DependencyItem>
<DependencyItem>
<Type>TvServer</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>9</Minor>
<Build>0</Build>
<Revision>0</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>20</Minor>
<Build>999</Build>
<Revision>0</Revision>
</MaxVersion>
<WarnOnly>true</WarnOnly>
<Message>requires MediaPortal TVServer version 1.5.* or above</Message>
<Name>MediaPortal TVServer</Name>
</DependencyItem>
<DependencyItem>
<Type>MediaPortal</Type>
<Id />
<MinVersion>
<Major>1</Major>
<Minor>1</Minor>
<Build>6</Build>
<Revision>27644</Revision>
</MinVersion>
<MaxVersion>
<Major>1</Major>
<Minor>1</Minor>
<Build>6</Build>
<Revision>27644</Revision>
</MaxVersion>
<WarnOnly>false</WarnOnly>
<Message>requires MediaPortal version 1.1.6.27644 to 1.1.6.27644.</Message>
<Name>MediaPortal</Name>
</DependencyItem>
</Items>
</Dependencies>
<PluginDependencies>
<Items />
</PluginDependencies>
<GeneralInfo>
<Name>TVServerKodi</Name>
<Id>81b6b5e8-b4e0-4d1c-a2e2-cb2db54844f1</Id>
<Author>Marcel Groothuis, Prashant V</Author>
<HomePage>http://www.scintilla.utwente.nl/~marcelg/xbmc/tvserverxbmc.html</HomePage>
<ForumPage>http://forum.xbmc.org/forumdisplay.php?fid=171</ForumPage>
<UpdateUrl>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/MPEI_Update_1_10.xml</UpdateUrl>
<Version>
<Major>1</Major>
<Minor>15</Minor>
<Build>0</Build>
<Revision>136</Revision>
</Version>
<ExtensionDescription>With this plugin you can watch Live TV, recordings, EPG and schedules in XBMC (v12.0 or above) and Kodi























. The TVServerKodi plugin extends the MediaPortal TVServer with a dedicated RPC gateway to allow XBMC/Kodi to access and control the TVServer.















































</ExtensionDescription>
<VersionDescription />
<DevelopmentStatus>Stable</DevelopmentStatus>
<OnlineLocation>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/TVServerKodi-1.15.0.136.mpe1</OnlineLocation>
<ReleaseDate>2016-12-10T19:29:03</ReleaseDate>
<Tags>xbmc, kodi, tv server plugins</Tags>
<Location>..\bin\[Name]-[Version].mpe1</Location>
<Params>
<Items>
<SectionParam Name="Online Icon">
<Value />
<ValueType>String</ValueType>
<Description>The icon file of the package stored online (jpg,png,bmp)</Description>
</SectionParam>
<SectionParam Name="Configuration file">
<Value />
<ValueType>Template</ValueType>
<Description>The file used to configure the extension.
If it has .exe extension the will be executed.
If it has .dll extension it's started like MP plugin configuration.</Description>
</SectionParam>
<SectionParam Name="Online Screenshots">
Expand Down
24 changes: 21 additions & 3 deletions TVServerKodi/Installer/TVServerKodi.xmp2
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,20 @@ Click Next to continue or Cancel to exit Setup.</Value>
<Major>1</Major>
<Minor>15</Minor>
<Build>0</Build>
<Revision>134</Revision>
<Revision>136</Revision>
</Version>
<ExtensionDescription>With this plugin you can watch Live TV, recordings, EPG and schedules in XBMC (v12.0 or above) and Kodi
. The TVServerKodi plugin extends the MediaPortal TVServer with a dedicated RPC gateway to allow XBMC/Kodi to access and control the TVServer.
Expand All @@ -218,14 +224,26 @@ Click Next to continue or Cancel to exit Setup.</Value>
</ExtensionDescription>
<VersionDescription />
<DevelopmentStatus>Stable</DevelopmentStatus>
<OnlineLocation>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/TVServerXBMC-1.12.0.130.mpe1</OnlineLocation>
<ReleaseDate>2016-07-16T19:29:03</ReleaseDate>
<OnlineLocation>https://dl.dropbox.com/u/7249985/xbmc/tvserverxbmc/TVServerKodi-1.15.0.136.mpe1</OnlineLocation>
<ReleaseDate>2016-12-10T19:29:03</ReleaseDate>
<Tags>xbmc, kodi, tv server plugins</Tags>
<Location>..\bin\[Name]-[Version].mpe1</Location>
<Params>
Expand Down
76 changes: 41 additions & 35 deletions TVServerKodi/TV/ServerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,69 +233,75 @@ public bool StopTimeShifting()

public string GetRecordingURL(int idRecording, TvServer server, bool resolveHostnames, ref string OriginalURL)
{
//TvServer server = new TvServer();
string rtspURL;

if (server == null)
server = new TvServer();

string rtspURL = server.GetStreamUrlForFileName(idRecording);

// we resolve any host names, as xbox can't do NETBIOS resolution..
try
{
rtspURL = server.GetStreamUrlForFileName(idRecording);

// we resolve any host names, as xbox can't do NETBIOS resolution..
// XBMC/Kodi's ffmpeg rtsp code does not like port numbers in the url
rtspURL = rtspURL.Replace(":554", "");
// Workaround for MP TVserver bug when using default port for rtsp => returns rtsp://ip:0
rtspURL = rtspURL.Replace(":0", "");

OriginalURL = rtspURL;
if (resolveHostnames)
try
{
Uri u = new Uri(rtspURL);
System.Net.IPAddress ipaddr = null;
try
{
ipaddr = System.Net.IPAddress.Parse(u.DnsSafeHost); //Fails on a hostname
}
catch { }

if ((ipaddr == null) || (ipaddr.IsIPv6LinkLocal || ipaddr.IsIPv6Multicast || ipaddr.IsIPv6SiteLocal))
if (resolveHostnames)
{
System.Net.IPAddress ipaddr = null;
Uri u = new Uri(rtspURL);
try
{
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(u.DnsSafeHost);
ipaddr = System.Net.IPAddress.Parse(u.DnsSafeHost); //Fails on a hostname
}
catch { }

string newHost = "";
foreach (System.Net.IPAddress ipaddr2 in hostEntry.AddressList)
if ((ipaddr == null) || (ipaddr.IsIPv6LinkLocal || ipaddr.IsIPv6Multicast || ipaddr.IsIPv6SiteLocal))
{
try
{
// we only want ipv4.. this is just the xbox after all
if (ipaddr2.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
System.Net.IPHostEntry hostEntry = System.Net.Dns.GetHostEntry(u.DnsSafeHost);

string newHost = "";
foreach (System.Net.IPAddress ipaddr2 in hostEntry.AddressList)
{
newHost = ipaddr2.ToString();
break;
// we only want ipv4.. this is just the xbox after all
if (ipaddr2.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
{
newHost = ipaddr2.ToString();
break;
}
}
}

rtspURL = u.AbsoluteUri.Replace(u.Scheme + "://" + u.Host + "/", u.Scheme + "://" + newHost + "/");
rtspURL = u.AbsoluteUri.Replace(u.Scheme + "://" + u.Host + "/", u.Scheme + "://" + newHost + "/");

if (newHost.Length == 0)
if (newHost.Length == 0)
{
Console.WriteLine("No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
Log.Error("TVServerKodi: No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
}
}
catch (Exception ex)
{
Console.WriteLine("No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
Log.Debug("TVServerKodi: No IPv4 adress found for '" + u.DnsSafeHost + "' failed. Returning original URL.");
Console.WriteLine("IP resolve for '" + u.DnsSafeHost + "' failed.");
Console.WriteLine("Error: " + ex.ToString());
Log.Error("TVServerKodi: IP resolve for '" + u.DnsSafeHost + "' failed.");
Log.Error("TVServerKodi: Error: " + ex.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("IP resolve for '" + u.DnsSafeHost + "' failed.");
Console.WriteLine("Error: " + ex.ToString());
Log.Debug("TVServerKodi: IP resolve for '" + u.DnsSafeHost + "' failed.");
Log.Debug("TVServerKodi: Error: " + ex.ToString());
}
}
}
catch { }
}
catch
catch (Exception ex)
{
//Console.WriteLine("IP resolve failed");
Log.Error("TVServerKodi: GetStreamUrlForFileName(" + idRecording + ") failed.");
Log.Error("TVServerKodi: Error: " + ex.ToString());
return "";
}

Expand Down

0 comments on commit 3456cde

Please sign in to comment.