1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Resolved PHP to parse podcast

Discussion in 'Mac Programming' started by newtoiphonesdk, Mar 29, 2012.

  1. newtoiphonesdk, Mar 29, 2012
    Last edited: Mar 30, 2012

    macrumors 6502a

    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.:
    View attachment script.zip
  2. macrumors 68030


    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.
  3. macrumors 6502a

    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>
    		<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="" />
  4. jared_kipe, Mar 29, 2012
    Last edited: Mar 29, 2012

    macrumors 68030


    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);
    $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.
  5. newtoiphonesdk, Mar 29, 2012
    Last edited: Mar 29, 2012

    macrumors 6502a

    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. View attachment FeedForAll_XMLParser.inc.php.zip

    EDIT: These May also be needed View attachment alsoneeded.zip
  6. macrumors 68030


    Uncomment out the //die line and see if you get the first GUID link.
  7. macrumors 6502a

    Yes, uncommented it, uploaded it, and then navigated in browser and it displayed the URL for the first GUID link.
  8. jared_kipe, Mar 30, 2012
    Last edited: Mar 30, 2012

    macrumors 68030


    In the more recent file you uploaded, that includes the XML parser.

    case "GUID":
    $this->currentItem->guid .= $data;
    Make it:
    case "GUID":
    $this->currentItem->guid .= $data;
    $this->currentItem->link = $data;
    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.
  9. macrumors 6502a

    Brilliant! Thank you SOOO Much! Works perfect!

Share This Page