Podcast RSS Feed to post - Podcast Import

Summary

Create a post from an podcast episode from RSS.

Behavior

Check external RSS feed on pre-set day in the week and time of the day and sync frequency.

I am a podcast host and producer and for many years I was using MODX for my website. But after an podcast episode, I had to copy the content from the podcast platform and add it to MODX.
In 2023 I switched to the other CMS I will not mention the name (WP :wink: because there is this great plugin to import a podcast episode to a WP post, WP Podcast Importer.

I would really really love to have this feature in MODX. I’ve looked for an solution but can seem to find it. What I found on the form is to look at GetFeed, Spiefeed.

It seem it would need two parts:
1 xml parser to check the RSS url.
2 Have an event / cron job checking for an update in the RSS.

So what this plugin does is check for new content in the RSS item. You can set it to check it per day, per week, per month. So you can set the import interval. Import the podcast episode image.

And of course settings to determine how to post the content to a post.

Is there anyone who would like to help me create this in MODX?

Best regards,
Lucas Degen

For cron you could use the extra CronManager. This extra allows you to run a MODX snippet periodically with cron.

Do you use MODX 2.x or MODX 3?
With MODX 2.x, you could use the class modRSSParser (that is also used in the extra getFeed).
In MODX 3, modRSSParser doesn’t seem to exist anymore. You probably have to use SimplePie (that is a dependency of MODX 3) instead.


For this task you have to write a custom snippet.
How good are your programming skills?

1 Like

Thanks, I always work with the latest version. So MODX 3.x
My programming skills are limited to html css :slight_smile: and copy and paste. :slight_smile:

So I beter go ask around in my network for help or in this forum. :slight_smile:

Here is some MODX code, that uses SimplePie to download and parse an RSS feed (for the “News Feed” widget on the dashboard):

In your snippet, you could do something similar.
(Replace $this->modx with $modx in the snippet code).


To programmatically add a new resource in MODX, you can use code like this

use MODX\Revolution\modResource;

$doc = $modx->newObject(modResource::class); // create a new resource
$doc->set('parent', 1); // set the fields to their values
$doc->set('pagetitle', 'new resource');
$doc->set('template', 1);
$doc->setContent('some content');
...
$doc->save(); // save the resource

or alternatively call the “resource/create” processor:

$resource = [];
$resource['parent'] = 1;
$resource['pagetitle'] = 'new resource';
$resource['template'] = '1';
$resource['content'] = 'some content';
...
$response = $modx->runProcessor('Resource/Create', $resource);

If you have more specific questions, you probably have to provide your RSS-feed-URL.

1 Like

Thanks I will look into it soon.

This is my podcast RSS: https://anchor.fm/s/1388c80/podcast/rss be aware there are 165+ episodes recorded. So it’s a long list of items.

So I’m not a coder and asked ChatGPT to help a hand.

Here is the code it came up with and told me to install the MODX extra;s

  • getFeed and spieFeed snippets
  • also install the CronManager extra.
  • And install SimplePie to core/components/simplepie/
<?php
// Include SimplePie autoloader
require_once $modx->getOption('core_path') . 'components/simplepie/autoloader.php';

// RSS feed URL
$feed_url = 'http://example.com/podcast/rss';

// SimplePie initialiseren
$feed = new SimplePie();
$feed->set_feed_url($feed_url);
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();

// Checken of de feed geldig is
if ($feed->error()) {
    return 'Error: ' . $feed->error();
}

// Loop door de feed items
foreach ($feed->get_items() as $item) {
    // Haal data uit het item
    $title = $item->get_title();
    $description = $item->get_description();
    $link = $item->get_link();
    $pubDate = $item->get_date('Y-m-d H:i:s');

    // Check of een resource met deze titel al bestaat
    $existing = $modx->getObject('modResource', array('pagetitle' => $title));
    if (!$existing) {
        // Maak een nieuwe resource aan
        $resource = $modx->newObject('modResource');
        $resource->fromArray(array(
            'pagetitle' => $title,
            'alias' => $modx->filterPathSegment($modx->resource->get('id'), $title),
            'content' => $description,
            'published' => 1,
            'pub_date' => strtotime($pubDate),
            'template' => 1, // Pas dit aan naar het gewenste template ID
            'parent' => 0, // Pas dit aan naar de gewenste parent ID
            'uri' => $link,
        ));
        $resource->save();
    }
}

return 'Podcast RSS feed succesvol geĂŻmporteerd.';
?>

Let’s give ChatGPT some more training data for the next version :wink: :

For this solution, you don’t need these extras.

MODX 3 already comes with SimplePie (core/vendor/simplepie). You can use it directly without a custom installation.

Not necessary.

The function “filterPathSegment” has the arguments $string and an $options array. Not sure what ChatGPT does here! Only using the title $modx->filterPathSegment($title) should probably be fine. Or use the $resource->cleanAlias($title) function instead.

pub_date is only used for auto-publishing (when you want MODX to automatically publish a resource on a future date). In this case use publishedon instead.

Not sure what ChatGPT does here either. Why $link? Anyway, the uri is set automatically and doesn’t have to be set here.

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.