Here is my first provider.xm file. I haven't been able to give these a proper test yet so please be aware of that.
Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<VideoService
DefaultCategoryTransform="Feed"
DefaultCategoryUrl="http://www.escapistmagazine.com/rss/videos/list/1.xml"
Description="Zero Punctuation is The Escapist's groundbreaking video review series starring Ben 'Yahtzee' Croshaw. Every Wednesday Zero Punctuation picks apart the games so you don't have to."
Enabled="false"
Image="http://services.jasmio.com/macrotube/providers/ZeroPunctuation.png"
Name="Zero Punctuation"
IsMultipage="False"
Type="XSLT"
UpdateUrl="http://services.jasmio.com/macrotube/providers/ZeroPunctuation.xml"
Version="1.0"
>
<Categories>
<Category ID="all" Name="All" />
</Categories>
<SortOrders>
<SortOrder ID="date" Name="date" />
</SortOrders>
<Transforms>
<Transform Name="Feed">
<xsl:stylesheet
version="1.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
xmlns:gml="http://www.opengis.net/gml"
xmlns:georss="http://www.georss.org/georss"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007"
xmlns:gd="http://schemas.google.com/g/2005"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:func="urn:local-functions"
>
<msxsl:script language="C#" implements-prefix="func">
<![CDATA[
static Regex descMatch = new Regex(@"^.*<p>(.+?)</p>.*", RegexOptions.Compiled);
public string escapeuridata(string unescaped)
{
return Uri.EscapeDataString(unescaped);
}
public string fixdesc(string source)
{
return string.Format("{0}", descMatch.Replace(source, @"$1"));
}
public string fixdate(string source)
{
return Regex.Replace(source, ".{3}$", "+0000");
}
]]>
</msxsl:script>
<xsl:output indent="yes" method="xml" />
<xsl:template match="item">
<xsl:element name="item">
<xsl:attribute name="date">
<xsl:value-of select="func:fixdate(pubDate)" />
</xsl:attribute>
<xsl:attribute name="duration">
500
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="title" />
</xsl:attribute>
<xsl:attribute name="rating">
0
</xsl:attribute>
<xsl:element name="description">
<xsl:value-of select="func:fixdesc(description)" />
</xsl:element>
<xsl:element name="thumbnails">
<xsl:element name="thumbnail">
<xsl:attribute name="width">150</xsl:attribute>
<xsl:attribute name="height">128</xsl:attribute>
<xsl:attribute name="url">http://img1.imageshack.us/thumbnail.png</xsl:attribute>
</xsl:element>
</xsl:element>
<xsl:element name="videos">
<xsl:element name="video">
<xsl:attribute name="type">video/mpeg</xsl:attribute>
<xsl:attribute name="url">
<xsl:value-of select="link" />
</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="/">
<xsl:element name="items">
<xsl:apply-templates select="//item" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
</Transform>
</Transforms>
<VideoProviders>
<VideoProvider class="MacroTube.Model.ZeroPunctuationProvider">
<![CDATA[
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace MacroTube.Model
{
public class ZeroPunctuationProvider : VideoProvider
{
private static readonly Regex _watchMatch = new Regex(@"^http://www.escapistmagazine.com/.*", RegexOptions.Compiled);
private static readonly Regex _jsMatch = new Regex(@"^.*flashvars=""config=(.+?)"".*", RegexOptions.Compiled | RegexOptions.Singleline);
private static readonly Regex _urlMatch = new Regex(@"^.*url':'(http://video2.+?)'.*", RegexOptions.Compiled | RegexOptions.Singleline);
public YouTubeVideoProvider()
: base()
{
}
public override string GetDownloadUrl(string sourceURL)
{
if (!IsProvider(sourceURL)) return null;
string newsourceURL = null;
string resolvedURL = null;
Debug.WriteLine(string.Format("Source URL: {0}", sourceURL));
try
{
WebClient client = new WebClient();
string html = client.DownloadString(sourceURL);
newsourceURL = string.Format("{0}", _jsMatch.Replace(html, "$1"));
Debug.WriteLine(string.Format("New Source URL: {0}", newsourceURL));
client.Headers.Clear();
client.Headers.Add("Referer", sourceURL);
string newhtml = client.DownloadString(newsourceURL);
Debug.WriteLine("NEW HTML: " + newhtml);
resolvedURL = string.Format("{0}", _urlMatch.Replace(newhtml, "$1"));
Debug.WriteLine(string.Format("Resolved URL: {0}", resolvedURL));
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("Error getting download URL: {0}\r\n{1}\r\n{2}", sourceURL, ex));
}
return Uri.IsWellFormedUriString(resolvedURL, UriKind.Absolute) ? resolvedURL : null;
}
public override bool IsProvider(string url)
{
return _watchMatch.IsMatch(url);
}
}
}
]]></VideoProvider>
</VideoProviders>
</VideoService>