danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 192 forks source link

Podcasts sometimes bring in audio as image #229

Closed wccrawford closed 7 years ago

wccrawford commented 7 years ago

https://www.npr.org/rss/podcast.php?id=510308

<item>
<title>Episode 65: Tunnel Vision</title>
<description>
<![CDATA[
When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.
]]>
</description>
<pubDate>Mon, 20 Mar 2017 21:00:14 -0400</pubDate>
<copyright>Copyright 2015 NPR - For Personal Use Only</copyright>
<guid>e601ab3e-deb9-457c-a15d-4c83456e2fb4</guid>
<itunes:title>Episode 65: Tunnel Vision</itunes:title>
<itunes:author>NPR</itunes:author>
<itunes:summary>
<![CDATA[
When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.
]]>
</itunes:summary>
<itunes:duration>2200</itunes:duration>
<itunes:explicit>no</itunes:explicit>
<content:encoded>
<![CDATA[
When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.
]]>
</content:encoded>
<enclosure url="https://play.podtrac.com/npr-510308/npr.mc.tritondigital.com/NPR_510308/media/anon.npr-mp3/npr/hiddenbrain/2017/03/20170320_hiddenbrain_65.mp3?orgId=1&d=2200&p=510308&story=520136937&t=podcast&e=520136937&ft=pod&f=510308" length="0" type="audio/mpeg"/>
</item>

Becomes

{"guid":"e601ab3e-deb9-457c-a15d-4c83456e2fb4","title":"Episode 65: Tunnel Vision","description":"When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.","summary":"When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.","link":null,"pubDate":"2017-03-21T01:00:14.000Z","image":"https://play.podtrac.com/npr-510308/npr.mc.tritondigital.com/NPR_510308/media/anon.npr-mp3/npr/hiddenbrain/2017/03/20170320_hiddenbrain_65.mp3?orgId=1&d=2200&p=510308&story=520136937&t=podcast&e=520136937&ft=pod&f=510308"}

But other instances put an image in the image field instead, like when the have an itunes:image tag.

We would like to support audio officially and always put audio in an audio tag, or have another way to access the audio link from each article separately from the image in the article.

danmactough commented 7 years ago

@wccrawford I can't reproduce this. If you share your code, maybe I can see what's going on.

When I parse my feed, I see the following for that episode:

{
  "title": "Episode 65: Tunnel Vision",
  "description": "When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.",
  "summary": "When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives.",
  "date": "2017-03-21T01:00:14.000Z",
  "pubdate": "2017-03-21T01:00:14.000Z",
  "pubDate": "2017-03-21T01:00:14.000Z",
  "link": null,
  "guid": "e601ab3e-deb9-457c-a15d-4c83456e2fb4",
  "author": "NPR",
  "comments": null,
  "origlink": null,
  "image": {},
  "source": {},
  "categories": [],
  "enclosures": [
    {
      "url": "https://play.podtrac.com/npr-510308/npr.mc.tritondigital.com/NPR_510308/media/anon.npr-mp3/npr/hiddenbrain/2017/03/20170320_hiddenbrain_65.mp3?orgId=1&d=2200&p=510308&story=520136937&t=podcast&e=520136937&ft=pod&f=510308",
      "type": "audio/mpeg",
      "length": "0"
    }
  ],
  "rss:@": {},
  "rss:title": {
    "@": {},
    "#": "Episode 65: Tunnel Vision"
  },
  "rss:description": {
    "@": {},
    "#": "When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives."
  },
  "rss:pubdate": {
    "@": {},
    "#": "Mon, 20 Mar 2017 21:00:14 -0400"
  },
  "rss:copyright": {
    "@": {},
    "#": "Copyright 2015 NPR - For Personal Use Only"
  },
  "permalink": "e601ab3e-deb9-457c-a15d-4c83456e2fb4",
  "rss:guid": {
    "@": {},
    "#": "e601ab3e-deb9-457c-a15d-4c83456e2fb4"
  },
  "itunes:title": {
    "@": {},
    "#": "Episode 65: Tunnel Vision"
  },
  "itunes:author": {
    "@": {},
    "#": "NPR"
  },
  "itunes:summary": {
    "@": {},
    "#": "When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives."
  },
  "itunes:duration": {
    "@": {},
    "#": "2200"
  },
  "itunes:explicit": {
    "@": {},
    "#": "no"
  },
  "content:encoded": {
    "@": {},
    "#": "When you're hungry, it can be hard to think of anything other than food. When you're desperately poor, you may constantly worry about making ends meet. When you're lonely, you might obsess about making friends. This week on Hidden Brain, we explore the psychological phenomenon of <em>scarcity </em>and how it can affect our ability to see the big picture and cope with problems in our lives."
  },
  "rss:enclosure": {
    "@": {
      "url": "https://play.podtrac.com/npr-510308/npr.mc.tritondigital.com/NPR_510308/media/anon.npr-mp3/npr/hiddenbrain/2017/03/20170320_hiddenbrain_65.mp3?orgId=1&d=2200&p=510308&story=520136937&t=podcast&e=520136937&ft=pod&f=510308",
      "length": "0",
      "type": "audio/mpeg"
    }
  },
  "meta": {
    "#ns": [
      {
        "xmlns:npr": "https://www.npr.org/rss/"
      },
      {
        "xmlns:nprml": "https://api.npr.org/nprml"
      },
      {
        "xmlns:itunes": "http://www.itunes.com/dtds/podcast-1.0.dtd"
      },
      {
        "xmlns:content": "http://purl.org/rss/1.0/modules/content/"
      },
      {
        "xmlns:dc": "http://purl.org/dc/elements/1.1/"
      }
    ],
    "@": [
      {
        "xmlns:npr": "https://www.npr.org/rss/"
      },
      {
        "xmlns:nprml": "https://api.npr.org/nprml"
      },
      {
        "xmlns:itunes": "http://www.itunes.com/dtds/podcast-1.0.dtd"
      },
      {
        "xmlns:content": "http://purl.org/rss/1.0/modules/content/"
      },
      {
        "xmlns:dc": "http://purl.org/dc/elements/1.1/"
      }
    ],
    "#xml": {
      "version": "1.0",
      "encoding": "UTF-8"
    },
    "#type": "rss",
    "#version": "2.0",
    "title": "Hidden Brain",
    "description": "The Hidden Brain helps curious people understand the world – and themselves. Using science and storytelling, Hidden Brain's host Shankar Vedantam reveals the unconscious patterns that drive human behavior, the biases that shape our choices, and the triggers that direct the course of our relationships.",
    "date": "2017-08-08T01:00:29.000Z",
    "pubdate": "2017-08-08T01:00:29.000Z",
    "pubDate": "2017-08-08T01:00:29.000Z",
    "link": "http://npr.org/series/423302056/hidden-brain",
    "xmlurl": null,
    "xmlUrl": null,
    "author": "NPR",
    "language": "en-us",
    "favicon": null,
    "copyright": "Copyright 2015 NPR - For Personal Use Only",
    "generator": "NPR API RSS Generator 0.94",
    "cloud": {},
    "image": {
      "url": "https://media.npr.org/assets/img/2017/01/12/hiddenbrain_sq-c52ddc28021ba306c99f2a94f06e0f649b0b62cd.jpg?s=200",
      "title": "Hidden Brain"
    },
    "categories": [
      "Social Sciences",
      "Science & Medicine",
      "Performing Arts",
      "Natural Sciences",
      "Literature"
    ],
    "rss:@": {},
    "rss:title": {
      "@": {},
      "#": "Hidden Brain"
    },
    "rss:link": {
      "@": {},
      "#": "http://npr.org/series/423302056/hidden-brain"
    },
    "rss:description": {
      "@": {},
      "#": "The Hidden Brain helps curious people understand the world – and themselves. Using science and storytelling, Hidden Brain's host Shankar Vedantam reveals the unconscious patterns that drive human behavior, the biases that shape our choices, and the triggers that direct the course of our relationships."
    },
    "rss:copyright": {
      "@": {},
      "#": "Copyright 2015 NPR - For Personal Use Only"
    },
    "rss:generator": {
      "@": {},
      "#": "NPR API RSS Generator 0.94"
    },
    "rss:language": {
      "@": {},
      "#": "en-us"
    },
    "itunes:new-feed-url": {
      "@": {},
      "#": "https://www.npr.org/rss/podcast.php?id=510308"
    },
    "itunes:summary": {
      "@": {},
      "#": "The Hidden Brain helps curious people understand the world – and themselves. Using science and storytelling, Hidden Brain's host Shankar Vedantam reveals the unconscious patterns that drive human behavior, the biases that shape our choices, and the triggers that direct the course of our relationships."
    },
    "itunes:subtitle": {
      "@": {},
      "#": "A conversation about life's unseen patterns."
    },
    "itunes:author": {
      "@": {},
      "#": "NPR"
    },
    "itunes:block": {
      "@": {},
      "#": "no"
    },
    "itunes:owner": {
      "@": {},
      "itunes:email": {
        "@": {},
        "#": "podcasts@npr.org"
      },
      "itunes:name": {
        "@": {},
        "#": "NPR"
      }
    },
    "itunes:category": [
      {
        "@": {
          "text": "Social Sciences"
        }
      },
      {
        "@": {
          "text": "Science & Medicine"
        }
      },
      {
        "@": {
          "text": "Performing Arts"
        }
      },
      {
        "@": {
          "text": "Natural Sciences"
        }
      },
      {
        "@": {
          "text": "Literature"
        }
      }
    ],
    "itunes:image": {
      "@": {
        "href": "https://media.npr.org/assets/img/2017/01/12/hiddenbrain_sq-c52ddc28021ba306c99f2a94f06e0f649b0b62cd.jpg?s=1400"
      }
    },
    "rss:image": {
      "@": {},
      "url": {
        "@": {},
        "#": "https://media.npr.org/assets/img/2017/01/12/hiddenbrain_sq-c52ddc28021ba306c99f2a94f06e0f649b0b62cd.jpg?s=200"
      },
      "title": {
        "@": {},
        "#": "Hidden Brain"
      },
      "link": {
        "@": {},
        "#": "http://npr.org/series/423302056/hidden-brain"
      }
    },
    "rss:lastbuilddate": {
      "@": {},
      "#": "Mon, 07 Aug 2017 21:00:29 -0400"
    }
  }
}
wccrawford commented 7 years ago

Gah. I'm sorry. This is entirely my code's fault. Thank you for looking at it.