From: Antonio Ospite <ao2@ao2.it> Date: Sat, 28 Feb 2015 00:54:34 +0000 (+0100) Subject: Add support for converting Instagram user timelines to RSS X-Git-Tag: v0.4~33 X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/eafac3f425aa88b42e6a496b62304848d5bbb4a9?ds=inline Add support for converting Instagram user timelines to RSS --- diff --git a/rss_converter_instagram.com.xsl b/rss_converter_instagram.com.xsl new file mode 100644 index 0000000..f42ca8b --- /dev/null +++ b/rss_converter_instagram.com.xsl @@ -0,0 +1,104 @@ +<!-- + Stylesheet to convert Instagram user timelines to RSS. + + Copyright (C) 2015 Antonio Ospite <ao2@ao2.it> + + This file is part of tweeper. + + 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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>. +--> +<xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:php="http://php.net/xsl" + xsl:extension-element-prefixes="php" + exclude-result-prefixes="php"> + + <xsl:param name="generateEnclosure"/> + + <xsl:output method="xml" indent="yes"/> + + <xsl:variable name="BaseURL"> + <xsl:text>https://instagram.com</xsl:text> + </xsl:variable> + + <xsl:template match="images"> + <xsl:value-of disable-output-escaping="yes" select="php:function('Tweeper::generate_enclosure', string(./standard_resolution/url))"/> + </xsl:template> + + <xsl:variable name="screen-name" select="//UserProfile/XML_Serializer_Tag/user/full_name"/> + <xsl:variable name="user-name" select="//UserProfile/XML_Serializer_Tag/user/username"/> + + <xsl:template match="//userMedia/XML_Serializer_Tag"> + <xsl:variable name="item-content-title" select="./caption/text"/> + <xsl:variable name="item-content-src" select="./images/standard_resolution/url"/> + <xsl:variable name="item-permalink" select="./link"/> + <item> + <title> + <xsl:value-of select="concat($user-name, ': ', $item-content-title)"/> + </title> + <link> + <xsl:value-of select="$item-permalink"/> + </link> + <guid> + <xsl:value-of select="$item-permalink"/> + </guid> + <pubDate> + <xsl:variable name="timestamp" select="./created_time"/> + <xsl:value-of select="php:functionString('Tweeper::epoch_to_gmdate', number($timestamp))"/> + </pubDate> + <description> + <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text> + <p><xsl:value-of select="$item-content-title"/></p><br /> + <img src="{$item-content-src}" title="{$item-content-title}" /> + <xsl:text disable-output-escaping="yes">]]></xsl:text> + </description> + <xsl:if test="$generateEnclosure = 1"> + <xsl:apply-templates select="./images"/> + </xsl:if> + </item> + </xsl:template> + + <xsl:template match="/"> + <xsl:variable name="channel-title" select="concat('Instagram / ', $screen-name)"/> + <xsl:variable name="channel-link" select="concat($BaseURL, //user/__path)"/> + + <rss version="2.0"> + <xsl:attribute name="xml:base"><xsl:value-of select="$BaseURL" /></xsl:attribute> + <channel> + <generator>Tweeper</generator> + <title> + <xsl:value-of select="$channel-title"/> + </title> + <link> + <xsl:value-of select="$channel-link"/> + </link> + <description> + <xsl:value-of select="//user/bio"/> + </description> + <image> + <title> + <xsl:value-of select="$channel-title"/> + </title> + <link> + <xsl:value-of select="$channel-link"/> + </link> + <url> + <xsl:value-of select="//user/profile_picture"/> + </url> + </image> + <xsl:apply-templates select="//userMedia/XML_Serializer_Tag"/> + </channel> + </rss> + </xsl:template> +</xsl:stylesheet> diff --git a/tweeper.php b/tweeper.php index 9f09936..ed1e1c7 100644 --- a/tweeper.php +++ b/tweeper.php @@ -201,6 +201,10 @@ class Tweeper { return $serializer->getSerializedData(); } + private function get_xml_instagram_com($html) { + return $this->json_to_xml($html, '/window._sharedData = (.*);/', 'instagram'); + } + private function html_to_xml($html, $host) { $xmlDoc = new DOMDocument();