From 27213534e6b5ece48860ef65699d9556a901e622 Mon Sep 17 00:00:00 2001
From: Uffe Heerfordt <uffe@heerfordt.com>
Date: Tue, 19 Apr 2011 16:59:55 +0200
Subject: [PATCH] Added playlist support

---
 MPWebStream/MPWebStream.csproj        |    7 +++
 MPWebStream/Playlist.aspx             |    1 +
 MPWebStream/Playlist.aspx.cs          |   69 +++++++++++++++++++++++++++++++++
 MPWebStream/Playlist.aspx.designer.cs |   15 +++++++
 4 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 MPWebStream/Playlist.aspx
 create mode 100644 MPWebStream/Playlist.aspx.cs
 create mode 100644 MPWebStream/Playlist.aspx.designer.cs

diff --git a/MPWebStream/MPWebStream.csproj b/MPWebStream/MPWebStream.csproj
index c24daeb..5e0cf1a 100644
--- a/MPWebStream/MPWebStream.csproj
+++ b/MPWebStream/MPWebStream.csproj
@@ -47,6 +47,7 @@
   <ItemGroup>
     <Content Include="Default.aspx" />
     <Content Include="MediaStream.svc" />
+    <Content Include="Playlist.aspx" />
     <Content Include="VLC.aspx" />
     <Content Include="Web.config">
       <SubType>Designer</SubType>
@@ -72,6 +73,12 @@
       <DependentUpon>Default.aspx</DependentUpon>
     </Compile>
     <Compile Include="Log.cs" />
+    <Compile Include="Playlist.aspx.cs">
+      <DependentUpon>Playlist.aspx</DependentUpon>
+    </Compile>
+    <Compile Include="Playlist.aspx.designer.cs">
+      <DependentUpon>Playlist.aspx</DependentUpon>
+    </Compile>
     <Compile Include="Service\IMediaStream.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Service\Channel.cs" />
diff --git a/MPWebStream/Playlist.aspx b/MPWebStream/Playlist.aspx
new file mode 100644
index 0000000..80a13bf
--- /dev/null
+++ b/MPWebStream/Playlist.aspx
@@ -0,0 +1 @@
+﻿<%@ Page EnableViewState="false" Language="C#" AutoEventWireup="true" CodeBehind="Playlist.aspx.cs" Inherits="MPWebStream.Site.Playlist" %>
\ No newline at end of file
diff --git a/MPWebStream/Playlist.aspx.cs b/MPWebStream/Playlist.aspx.cs
new file mode 100644
index 0000000..16d9cda
--- /dev/null
+++ b/MPWebStream/Playlist.aspx.cs
@@ -0,0 +1,69 @@
+﻿#region Copyright
+/* 
+ *  Copyright (C) 2010, 2011 Oxan
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *   
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *   
+ *  You should have received a copy of the GNU General Public License
+ *  along with GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *  http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+#endregion
+
+using MPWebStream.Site.Service;
+using System;
+using System.Web;
+using System.Web.UI.WebControls;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace MPWebStream.Site {
+    public partial class Playlist : System.Web.UI.Page {
+        protected void Page_Load(object sender, EventArgs e) {
+            // this whole page probably qualifies for The Daily WTF, but I'm not a ASP.NET coder and I don't have enough time to learn it. Suggestions and patches welcome.
+            if (!Authentication.authenticate(HttpContext.Current))
+                return;
+
+            Configuration config = new Configuration();
+            MediaStream remoteControl = new MediaStream();
+            
+            Response.ContentType = "audio/x-mpegurl";
+            Response.Write("#EXTM3U\r\n");
+            Response.Write(GetPlayList(remoteControl, config));
+
+        }
+
+        private String GetPlayList(MediaStream remoteControl, Configuration config) {
+
+            StringBuilder builder = new StringBuilder();
+            int pos = 0;
+            foreach (Channel channel in remoteControl.GetChannels()) {
+                // all transcoders
+                foreach (Transcoder transcoder in remoteControl.GetTranscoders()) {
+                        String name = "#EXTINF:"+(++pos)+","+channel.Name;
+                        String streamurl = remoteControl.GetTranscodedTvStreamUrl(channel.IdChannel, config.Username, config.Password, transcoder.Id);
+                        builder.Append(name);
+                        builder.Append("\r\n");
+                        builder.Append(streamurl);
+                        builder.Append("\r\n");
+                        builder.Append("\r\n");
+                        break;
+
+                }
+            }
+
+
+            return builder.ToString();
+        }
+    }
+}
\ No newline at end of file
diff --git a/MPWebStream/Playlist.aspx.designer.cs b/MPWebStream/Playlist.aspx.designer.cs
new file mode 100644
index 0000000..608ecf7
--- /dev/null
+++ b/MPWebStream/Playlist.aspx.designer.cs
@@ -0,0 +1,15 @@
+﻿//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated. 
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MPWebStream.Site {
+    
+    
+    public partial class Playlist {
+    }
+}
-- 
1.7.4

