PDA

View Full Version : [Resolved] PHP to parse podcast




newtoiphonesdk
Mar 29, 2012, 11:21 AM
I use FeedForAll RSS 2 HTML PHP Script, and am having some issues. The podcast I am parsing has two different URL links in it. One goes to their website with details about the episode, and the other goes to the actual mp3. They are labeled link, and guid respectively in the xml. The issue I have is this: On click of the episode, the browser is going to the link URL and I would like for it go to to the GUID URL. I have looked through the script, but cannot figure out where to make the change. Here is the script in its entirety.:
333015



jared_kipe
Mar 29, 2012, 04:07 PM
I use FeedForAll RSS 2 HTML PHP Script, and am having some issues. The podcast I am parsing has two different URL links in it. One goes to their website with details about the episode, and the other goes to the actual mp3. They are labeled link, and guid respectively in the xml. The issue I have is this: On click of the episode, the browser is going to the link URL and I would like for it go to to the GUID URL. I have looked through the script, but cannot figure out where to make the change. Here is the script in its entirety.:
333015

That why would the URL not be what you want, but instead GUID is right? In this context I would guess that GUID stands for "Globally unique identifier" and is usually 32 hex digits.

Where does the data come from? Do you have control over it?

EDIT: Ok maybe I should read better. For my misunderstanding I'll look at the script you uploaded.

newtoiphonesdk
Mar 29, 2012, 05:07 PM
That why would the URL not be what you want, but instead GUID is right? In this context I would guess that GUID stands for "Globally unique identifier" and is usually 32 hex digits.

Where does the data come from? Do you have control over it?

EDIT: Ok maybe I should read better. For my misunderstanding I'll look at the script you uploaded.
Thanks, also, here is a snippet from the XML Source. The item "LINK" is what is now being opened when you click the episode on the php script I had uploaded. I need to open the url from the "ENCLOSURE" or the "GUID" item.
<title>The Big Hunt</title>
<link>http://www.smcoc.net/index.php?option=com_biblestudy&amp;view=studydetails&amp;id=301&amp;templatemenuid=20&amp;Itemid=1</link>
<comments>http://www.smcoc.net/index.php?option=com_biblestudy&amp;view=studydetails&amp;id=301&amp;templatemenuid=20&amp;Itemid=1</comments>

<itunes:author>Dale Jenkins</itunes:author>
<dc:creator>Dale Jenkins</dc:creator>
<description>SUNDAY AM: Jesus: The Parables and the People</description>
<content:encoded>SUNDAY AM: Jesus: The Parables and the People</content:encoded>
<pubDate>Sun, 11 Mar 2012 11:43:33 -0400</pubDate>
<itunes:subtitle>The Big Hunt</itunes:subtitle>

<itunes:summary>SUNDAY AM: Jesus: The Parables and the People</itunes:summary>
<itunes:keywords>church of christ, sermon, spring meadows</itunes:keywords>
<itunes:duration>00:34:46</itunes:duration><enclosure url="http://www.smcoc.net/content/audio/sermons/2012/2012_03_11am_the_big_hunt.mp3" length="7644119" type="" />
<guid>http://www.smcoc.net/content/audio/sermons/2012/2012_03_11am_the_big_hunt.mp3</guid>

jared_kipe
Mar 29, 2012, 05:23 PM
Ok, this was non trivial given the fact that I had to write my own implementation for FeedForAll_scripts_readFile($file, $notused) and comment out a lot of other stuff that doesn't work without whatever supporting files need to be in place.

Find the line that looks like this.

$template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink), $template);


Replace it with this.

$start = strpos($XML, '<guid>');
$end = strpos($XML, '</guid>');
$guidValue = null;
if ($start !== false && $end !== false) {
$guidValue = substr($XML, $start + 6, $end - $start - 6);
//die($guidValue);
}
$link = ($guidValue)?$guidValue:FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink);
$template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", $link, $template);
//$template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink), $template);


Note that this is best guess based on me not being able to run the script to completion and just relying on die()'s and var_dump()'s to work out what is supposed to happen. For example, the rss container class "baseParserClass()" doesn't seem to implemented in this file and doesn't seem to be a stock php class.

This solution will gracefully fail on anything that doesn't have <guid> elements, but will not gracefully fail on things that have <guid> elements that are not the links you are looking for.

newtoiphonesdk
Mar 29, 2012, 06:02 PM
Ok, this was non trivial given the fact that I had to write my own implementation for FeedForAll_scripts_readFile($file, $notused) and comment out a lot of other stuff that doesn't work without whatever supporting files need to be in place.
Note that this is best guess based on me not being able to run the script to completion and just relying on die()'s and var_dump()'s to work out what is supposed to happen. For example, the rss container class "baseParserClass()" doesn't seem to implemented in this file and doesn't seem to be a stock php class.

Sorry about that, I forgot that there was another .php that it relied upon to complete. That .php is attached to this reply. I tried the solution you had posted, but it still was referencing the LINK of the XML and not the GUID element URL.333095

EDIT: These May also be needed 333096

jared_kipe
Mar 29, 2012, 11:57 PM
Sorry about that, I forgot that there was another .php that it relied upon to complete. That .php is attached to this reply. I tried the solution you had posted, but it still was referencing the LINK of the XML and not the GUID element URL.333095

EDIT: These May also be needed 333096

Uncomment out the //die line and see if you get the first GUID link.

newtoiphonesdk
Mar 30, 2012, 12:30 AM
Uncomment out the //die line and see if you get the first GUID link.

Yes, uncommented it, uploaded it, and then navigated in browser and it displayed the URL for the first GUID link.

jared_kipe
Mar 30, 2012, 11:25 AM
In the more recent file you uploaded, that includes the XML parser.

Find:

case "GUID":
$this->currentItem->guid .= $data;
break;


Make it:

case "GUID":
$this->currentItem->guid .= $data;
$this->currentItem->link = $data;
break;


This will work. Though I'm honestly not sure why the original fix didn't work. That code path must not be taken due to some newer code or something.

EDIT: Ok I see why my original fix didn't work, it was replacing FeedLink which is not the same as the individual ITEMLinks. The actual parsing of individual items is left 100% up to that second file you uploaded. Also oddly, it seems that it at least partially supports using <guid> tags as the links given the setting of the ivar $guidIsPermaLink which it sets based on an attribute of the <guid> tag itself (that isn't there on this feed). However this original base class does not in fact ever use this attribute/ivar for any calculation of the item link. It must be intended for one to subclass the parser to implement that feature. (not that it would help since its not set on this feed).

EDIT2: Oh and I forgot to mention, you can remove the earlier code change. Just roll back to the original file you uploaded, and implement the change in the second one.

newtoiphonesdk
Mar 30, 2012, 05:55 PM
In the more recent file you uploaded, that includes the XML parser.

Find:

case "GUID":
$this->currentItem->guid .= $data;
break;


Make it:

case "GUID":
$this->currentItem->guid .= $data;
$this->currentItem->link = $data;
break;


This will work. Though I'm honestly not sure why the original fix didn't work. That code path must not be taken due to some newer code or something.

EDIT: Ok I see why my original fix didn't work, it was replacing FeedLink which is not the same as the individual ITEMLinks. The actual parsing of individual items is left 100% up to that second file you uploaded. Also oddly, it seems that it at least partially supports using <guid> tags as the links given the setting of the ivar $guidIsPermaLink which it sets based on an attribute of the <guid> tag itself (that isn't there on this feed). However this original base class does not in fact ever use this attribute/ivar for any calculation of the item link. It must be intended for one to subclass the parser to implement that feature. (not that it would help since its not set on this feed).

EDIT2: Oh and I forgot to mention, you can remove the earlier code change. Just roll back to the original file you uploaded, and implement the change in the second one.

Brilliant! Thank you SOOO Much! Works perfect!