mygpo icon indicating copy to clipboard operation
mygpo copied to clipboard

Add new podcast by API

Open geraldo opened this issue 5 years ago • 7 comments

I would like to add new podcasts and episodes by the API but don't find any information about the first.

We are a community radio network and offer all the radio content as podcasts. Now we are looking for a open/libre podcast directory to submit our content and we are actually evaluation fyyd and gpodder.

geraldo avatar Jun 03 '19 11:06 geraldo

A podcast is automatically added once the first user subscribes to it. Then gpodder.net should automatically and periodically fetch the latest episodes. A dedicated API currently doesn’t exist, but I don’t see any reason why we could/shouldn’t add one.

stefankoegl avatar Jul 21 '19 18:07 stefankoegl

Here's a short summary of how I would approach this.

Overview

I'd suggest to implement an interface that accepts a URL and parses / creates the podcast asynchronously. In this way we can delay creating the podcast until after the feed has been parsed, and avoid to create podcasts that are actually empty.

HTTP Interface

Request

POST /api/2/podcasts/create

{
  url: "http://www.example.com/feed.rss"
}

Authentication does not seem to be necessary.

Processing

Check if a podcast for the given URL already exists. If so, redirect to it (see Retrieve Podcast Data). If not, accept the URL for processing.

Response

  • 303 See Other
  • 202 Accepted
  • Location header pointing to a podcast (for 303, see Retrieve Podcast Data) or a job status object (for 202), eg /api/2/task/<id> where is the Celery task id.

Request Job Status

Returns the celery task id. When the job finished successfully it contains a link to the podcast (as above).

If it finished unsuccessfully (because the URL was not a feed), it can contain a 4xx status code and a respective error message.

GET /api/2/task/<id>

200 OK

{
  id: "<id>",
  type: "create-podcast",
  url: "<url>",
  status: "pending",

  # successful
  status: "successful",
  podcast: "/api/2/data/podcast.json?url=<url>",

  # unsuccessful
  status: "unsuccessful",
  error: "feed could not be parsed"
}

Implementation

I'd implement the API views in mygpo/api/advanced/directory.py.

The function for parsing a podcast in a celery task is mygpo.data.tasks.update_podcasts, and can be called as update_podcasts.delay([podcast_url]). It returns a celery task result.

Documentation

The API should be documented in mygpo/doc/api/reference/directory.rst.

stefankoegl avatar Sep 16 '19 17:09 stefankoegl

I'd like to contribute with this!

nico-stefani avatar Oct 05 '19 17:10 nico-stefani

@nicolas471, that would be great! Please feel free to go ahead and submit a pull request. I am happy to also review partially finished changes to guide you along the way. If there's anything you need, please let me know!

stefankoegl avatar Oct 06 '19 10:10 stefankoegl

  • API for adding new podcast. by SiqingYu · Pull Request #328 · gpodder/mygpo
  • Tests for adding podcast API by SiqingYu · Pull Request #336 · gpodder/mygpo
  • [x] API views
  • [x] Pass CI builds
  • [ ] Testing
  • [ ] Read the Docs update, including API changes
  • [ ] Check edge case - Podcast URL not exist
  • [ ] Check edge case - Podcast XML format error
  • [ ] Code reviews

SiqingYu avatar Jan 12 '20 16:01 SiqingYu

I'd suggest to include functional code, tests, documentation, etc all in one pull request. It might get a bit longer but it will be easier to keep track of things that way. Also you can make sure that things are complete (ie docs or tests might be forgotten after the code has been merged).

stefankoegl avatar Jan 18 '20 10:01 stefankoegl

@stefankoegl Thanks for your advice. The previous PR has been merged, so I had to open a new PR. Next time I'll tick the boxes before opening the PR.

SiqingYu avatar Jan 18 '20 10:01 SiqingYu