├── .gitignore ├── .gitlab-ci.yml ├── .prettierignore ├── .prettierrc.json ├── README.md ├── index.js ├── jest.config.js ├── license ├── package-lock.json ├── package.json └── test └── api.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | .git 4 | coverage 5 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: node:latest 2 | 3 | stages: 4 | - test 5 | - deploy 6 | 7 | cache: 8 | paths: 9 | - node_modules/ 10 | 11 | test: 12 | script: 13 | - npm install 14 | - npx prettier --check . 15 | - npm test 16 | coverage: /All files\s*\|\s*([\d\.]+)/ 17 | except: 18 | - tags 19 | allow_failure: true 20 | 21 | deploy: 22 | stage: deploy 23 | script: 24 | - echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc 25 | - npm publish 26 | except: 27 | - tags 28 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .gitlab-ci.yml 2 | coverage 3 | package-lock.json 4 | package.json -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | "semi": false, 4 | "singleQuote": true 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Podcast Index API Javascript library 2 | 3 | > A Podcast Index API library for Node.js 4 | 5 | [![pipeline status](https://gitlab.com/comster/podcast-index-api/badges/master/pipeline.svg)](https://gitlab.com/comster/podcast-index-api/-/commits/master) 6 | [![coverage report](https://gitlab.com/comster/podcast-index-api/badges/master/coverage.svg)](https://gitlab.com/comster/podcast-index-api/-/commits/master) 7 | [![Install size](https://packagephobia.now.sh/badge?p=podcast-index-api)](https://packagephobia.now.sh/result?p=podcast-index-api) 8 | [![npm](https://img.shields.io/npm/v/podcast-index-api?style=plastic)](https://npmjs.com/podcast-index-api) 9 | [![Downloads](https://img.shields.io/npm/dw/podcast-index-api.svg)](https://npmjs.com/podcast-index-api) 10 | 11 | [Homepage](https://comster.github.io/podcast-index-api/) | [Source](https://github.com/comster/podcast-index-api) | [npm](https://npmjs.com/podcast-index-api) 12 | 13 | ## Installation 14 | 15 | Install with npm 16 | 17 | `npm install podcast-index-api --save` 18 | 19 | ## Configuration 20 | 21 | Sign up for API credentials here: https://api.podcastindex.org/ 22 | 23 | Description of API endpoints, arguments and returned data: https://podcastindex-org.github.io/docs-api/ 24 | 25 | Require the lib from your javascript file 26 | 27 | `const api = require('podcast-index-api')("YOUR_API_KEY_HERE", "YOUR_API_SECRET_HERE", "CUSTOM_USER_AGENT_HERE")` 28 | 29 | ## Usage 30 | 31 | Using Async/Await 32 | 33 | `const results = await api.searchByTerm('Joe Rogan Experience')` 34 | 35 | Using Promise 36 | 37 | `api.searchByTerm('Joe Rogan Experience').then(results => { console.log(results) })` 38 | 39 | ## Functions 40 | 41 | - Custom 42 | - Use for endpoints that don't have a specific function or if the function doesn't accept an argument for a 43 | desired parameter. 44 | - `custom(path: String, queries: Object)` 45 | - Search 46 | - `searchByTerm(q: String, val: String, clean: Boolean, fullText: Boolean)` 47 | - `searchByTitle(q: String, val: String, clean: Boolean, fullText: Boolean)` 48 | - `searchEpisodesByPerson(q: String, fullText: Boolean)` 49 | - Podcasts 50 | - `podcastsByFeedUrl(feedUrl: String)` 51 | - `podcastsByFeedId(feedId: Number)` 52 | - `podcastsByFeedItunesId(itunesId: Number)` 53 | - `podcastsByGUID(guid: Number)` 54 | - `podcastsByTag()` 55 | - `podcastsTrending(max: Number, since: Number, lang: String, cat: String, notcat: String)` 56 | - `podcastsDead()` 57 | - Episodes 58 | - `episodesByFeedId(feedId: Number, since: Number, max: Number, fullText: Boolean)` 59 | - `episodesByFeedUrl(feedUrl: String, since: Number, max: Number, fullText: Boolean)` 60 | - `episodesByItunesId(itunesId: Number, since: Number, max: Number, fullText: Boolean)` 61 | - `episodesById(id: Number, fullText: Boolean)` 62 | - `episodesRandom(max: Number, lang: String, cat: String, notcat: String, fullText: Boolean)` 63 | - Recent 64 | - `recentFeeds(max: Number, since: Number, cat: String, lang: String, notcat: String)` 65 | - `recentEpisodes(max: Number, excludeString: String, before: Number, fullText: Boolean)` 66 | - `recentNewFeeds(max: Number, since: Number)` 67 | - `recentSoundbites(max: Number)` 68 | - Value 69 | - `valueByFeedUrl(feedUrl: String)` 70 | - `valueByFeedId(feedId: Number)` 71 | - Categories 72 | - `categoriesList()` 73 | - Notify Hub 74 | - `hubPubNotifyById(feedId: Number)` 75 | - `hubPubNotifyByUrl(feedUrl: string)` 76 | - Add 77 | - `addByFeedUrl(feedUrl: String, chash: String, itunesId: Number)` 78 | - `addByItunesId(itunesId: Number)` 79 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const got = require('got') 2 | const crypto = require('crypto') 3 | const querystring = require('querystring') 4 | 5 | // 6 | // API docs: https://podcastindex-org.github.io/docs-api/#get-/search/byterm 7 | // 8 | 9 | const BASE_API_URL = 'https://api.podcastindex.org/api/1.0/' 10 | 11 | const PATH_SEARCH_BY_TERM = 'search/byterm' 12 | const PATH_SEARCH_BY_TITLE = 'search/bytitle' 13 | const PATH_SEARCH_EPISODE_BY_PERSON = 'search/byperson' 14 | const PATH_ADD_BY_FEED_URL = 'add/byfeedurl' 15 | const PATH_ADD_BY_ITUNES_ID = 'add/byitunesid' 16 | const PATH_EPISODES_BY_FEED_ID = 'episodes/byfeedid' 17 | const PATH_EPISODES_BY_FEED_URL = 'episodes/byfeedurl' 18 | const PATH_EPISODES_BY_ITUNES_ID = 'episodes/byitunesid' 19 | const PATH_EPISODES_BY_ID = 'episodes/byid' 20 | const PATH_EPISODES_RANDOM = 'episodes/random' 21 | const PATH_PODCASTS_BY_FEED_URL = 'podcasts/byfeedurl' 22 | const PATH_PODCASTS_BY_FEED_ID = 'podcasts/byfeedid' 23 | const PATH_PODCASTS_BY_ITUNES_ID = 'podcasts/byitunesid' 24 | const PATH_PODCASTS_BY_GUID = 'podcasts/byguid' 25 | const PATH_PODCASTS_BY_TAG = 'podcasts/bytag' 26 | const PATH_PODCASTS_TRENDING = 'podcasts/trending' 27 | const PATH_PODCASTS_DEAD = 'podcasts/dead' 28 | const PATH_RECENT_FEEDS = 'recent/feeds' 29 | const PATH_RECENT_EPISODES = 'recent/episodes' 30 | const PATH_RECENT_NEWFEEDS = 'recent/newfeeds' 31 | const PATH_RECENT_SOUNDBITES = 'recent/soundbites' 32 | const PATH_VALUE_BY_FEED_ID = 'value/byfeedid' 33 | const PATH_VALUE_BY_FEED_URL = 'value/byfeedurl' 34 | const PATH_CATEGORIES_LIST = 'categories/list' 35 | const PATH_HUB_PUBNOTIFIY = 'hub/pubnotify' 36 | 37 | const qs = (o) => '?' + querystring.stringify(o) 38 | 39 | const withResponse = (response) => { 40 | // Check for success or failure and create a predictable error response 41 | let body = response.body 42 | // if response.statusCode == 200? 43 | if ( 44 | response.statusCode === 500 || 45 | (body.hasOwnProperty('status') && body.status === 'false') 46 | ) { 47 | // Failed 48 | if (body.hasOwnProperty('description')) { 49 | // Error message from server API 50 | throw { message: body.description, code: response.statusCode } 51 | } else { 52 | throw { message: 'Request failed.', code: response.statusCode } 53 | } 54 | } else { 55 | // Succcess // 200 56 | return body 57 | } 58 | } 59 | 60 | module.exports = (key, secret, userAgent) => { 61 | if (!key || !secret) { 62 | throw new Error( 63 | 'API Key and Secret are required from https://api.podcastindex.org/' 64 | ) 65 | } 66 | 67 | const api = got.extend({ 68 | responseType: 'json', 69 | prefixUrl: BASE_API_URL, 70 | throwHttpErrors: false, 71 | hooks: { 72 | beforeRequest: [ 73 | (options) => { 74 | let dt = new Date().getTime() / 1000 75 | options.headers['User-Agent'] = 76 | userAgent || 77 | 'PodcastIndexBot/@podcast@noagendasocial.com' 78 | options.headers['X-Auth-Date'] = dt 79 | options.headers['X-Auth-Key'] = key 80 | options.headers['Authorization'] = crypto 81 | .createHash('sha1') 82 | .update(key + secret + dt) 83 | .digest('hex') 84 | }, 85 | ], 86 | }, 87 | }) 88 | 89 | const custom = async (path, queries) => { 90 | const response = await api(path + qs(queries)) 91 | return withResponse(response) 92 | } 93 | 94 | return { 95 | api, 96 | custom, 97 | 98 | searchByTerm: async (q, val = '', clean = false, fullText = false) => { 99 | let queries = { 100 | q: q, 101 | } 102 | if (val !== '') queries['val'] = val 103 | if (clean) queries['clean'] = '' 104 | if (fullText) queries['fullText'] = '' 105 | return custom(PATH_SEARCH_BY_TERM, queries) 106 | }, 107 | searchByTitle: async (q, val = '', clean = false, fullText = false) => { 108 | let queries = { 109 | q: q, 110 | } 111 | if (val !== '') queries['val'] = val 112 | if (clean) queries['clean'] = '' 113 | if (fullText) queries['fullText'] = '' 114 | return custom(PATH_SEARCH_BY_TITLE, queries) 115 | }, 116 | searchEpisodesByPerson: async (q, fullText = false) => { 117 | let queries = { 118 | q: q, 119 | } 120 | if (fullText) queries['fullText'] = '' 121 | return custom(PATH_SEARCH_EPISODE_BY_PERSON, queries) 122 | }, 123 | 124 | podcastsByFeedUrl: async (feedUrl) => { 125 | return custom(PATH_PODCASTS_BY_FEED_URL, { url: feedUrl }) 126 | }, 127 | podcastsByFeedId: async (feedId) => { 128 | return custom(PATH_PODCASTS_BY_FEED_ID, { id: feedId }) 129 | }, 130 | podcastsByFeedItunesId: async (itunesId) => { 131 | return custom(PATH_PODCASTS_BY_ITUNES_ID, { id: itunesId }) 132 | }, 133 | podcastsByGUID: async (guid) => { 134 | return custom(PATH_PODCASTS_BY_GUID, { guid: guid }) 135 | }, 136 | podcastsByTag: async () => { 137 | return custom(PATH_PODCASTS_BY_TAG, { 'podcast-value': '' }) 138 | }, 139 | podcastsTrending: async ( 140 | max = 10, 141 | since = null, 142 | lang = null, 143 | cat = null, 144 | notcat = null 145 | ) => { 146 | return custom(PATH_PODCASTS_TRENDING, { 147 | max: max, 148 | since: since, 149 | lang: lang, 150 | cat: cat, 151 | notcat: notcat, 152 | }) 153 | }, 154 | podcastsDead: async () => { 155 | return custom(PATH_PODCASTS_DEAD) 156 | }, 157 | 158 | addByFeedUrl: async (feedUrl, chash = null, itunesId = null) => { 159 | return custom(PATH_ADD_BY_FEED_URL, { 160 | url: feedUrl, 161 | chash: chash, 162 | itunesid: itunesId, 163 | }) 164 | }, 165 | addByItunesId: async (itunesId) => { 166 | return custom(PATH_ADD_BY_ITUNES_ID, { id: itunesId }) 167 | }, 168 | 169 | episodesByFeedId: async ( 170 | feedId, 171 | since = null, 172 | max = 10, 173 | fullText = false 174 | ) => { 175 | let queries = { 176 | id: feedId, 177 | since: since, 178 | max: max, 179 | } 180 | if (fullText) queries['fullText'] = '' 181 | return custom(PATH_EPISODES_BY_FEED_ID, queries) 182 | }, 183 | episodesByFeedUrl: async ( 184 | feedUrl, 185 | since = null, 186 | max = 10, 187 | fullText = false 188 | ) => { 189 | let queries = { 190 | url: feedUrl, 191 | since: since, 192 | max: max, 193 | } 194 | if (fullText) queries['fullText'] = '' 195 | return custom(PATH_EPISODES_BY_FEED_URL, queries) 196 | }, 197 | episodesByItunesId: async ( 198 | itunesId, 199 | since = null, 200 | max = 10, 201 | fullText = false 202 | ) => { 203 | let queries = { 204 | id: itunesId, 205 | since: since, 206 | max: max, 207 | } 208 | if (fullText) queries['fullText'] = '' 209 | return custom(PATH_EPISODES_BY_ITUNES_ID, queries) 210 | }, 211 | episodesById: async (id, fullText = false) => { 212 | let queries = { 213 | id: id, 214 | } 215 | if (fullText) queries['fullText'] = '' 216 | return custom(PATH_EPISODES_BY_ID, queries) 217 | }, 218 | episodesRandom: async ( 219 | max = 1, 220 | lang = null, 221 | cat = null, 222 | notcat = null, 223 | fullText = false 224 | ) => { 225 | let queries = { 226 | max: max, 227 | lang: lang, 228 | cat: cat, 229 | notcat: notcat, 230 | } 231 | if (fullText) queries['fullText'] = '' 232 | return custom(PATH_EPISODES_RANDOM, queries) 233 | }, 234 | 235 | recentFeeds: async ( 236 | max = 40, 237 | since = null, 238 | cat = null, 239 | lang = null, 240 | notcat = null 241 | ) => { 242 | return custom(PATH_RECENT_FEEDS, { 243 | max: max, 244 | since: since, 245 | lang: lang, 246 | cat: cat, 247 | notcat: notcat, 248 | }) 249 | }, 250 | recentEpisodes: async ( 251 | max = 10, 252 | excludeString = null, 253 | before = null, 254 | fullText = false 255 | ) => { 256 | let queries = { 257 | max: max, 258 | excludeString: excludeString ? excludeString : null, 259 | before: before, 260 | } 261 | if (fullText) queries['fullText'] = '' 262 | return custom(PATH_RECENT_EPISODES, queries) 263 | }, 264 | recentNewFeeds: async (max = 20, since = null) => { 265 | return custom(PATH_RECENT_NEWFEEDS, { 266 | max: max, 267 | since: since, 268 | }) 269 | }, 270 | recentSoundbites: async (max = 20) => { 271 | return custom(PATH_RECENT_SOUNDBITES, { 272 | max: max, 273 | }) 274 | }, 275 | 276 | valueByFeedId: async (feedId) => { 277 | return custom(PATH_VALUE_BY_FEED_ID, { 278 | id: feedId, 279 | }) 280 | }, 281 | valueByFeedUrl: async (feedUrl) => { 282 | return custom(PATH_VALUE_BY_FEED_URL, { 283 | url: feedUrl, 284 | }) 285 | }, 286 | 287 | categoriesList: async () => { 288 | return custom(PATH_CATEGORIES_LIST) 289 | }, 290 | 291 | hubPubNotifyById: async (feedId) => { 292 | let queries = { 293 | id: feedId, 294 | } 295 | return custom(PATH_HUB_PUBNOTIFIY, queries) 296 | }, 297 | hubPubNotifyByUrl: async (feedUrl) => { 298 | let queries = { 299 | url: feedUrl, 300 | } 301 | return custom(PATH_HUB_PUBNOTIFIY, queries) 302 | }, 303 | } 304 | } 305 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | // For a detailed explanation regarding each configuration property, visit: 2 | // https://jestjs.io/docs/en/configuration.html 3 | 4 | module.exports = { 5 | // All imported modules in your tests should be mocked automatically 6 | // automock: false, 7 | 8 | // Stop running tests after `n` failures 9 | // bail: 0, 10 | 11 | // The directory where Jest should store its cached dependency information 12 | // cacheDirectory: "/tmp/jest_rs", 13 | 14 | // Automatically clear mock calls and instances between every test 15 | clearMocks: true, 16 | 17 | // Indicates whether the coverage information should be collected while executing the test 18 | // collectCoverage: false, 19 | 20 | // An array of glob patterns indicating a set of files for which coverage information should be collected 21 | // collectCoverageFrom: undefined, 22 | 23 | // The directory where Jest should output its coverage files 24 | coverageDirectory: 'coverage', 25 | 26 | // An array of regexp pattern strings used to skip coverage collection 27 | // coveragePathIgnorePatterns: [ 28 | // "/node_modules/" 29 | // ], 30 | 31 | // Indicates which provider should be used to instrument code for coverage 32 | coverageProvider: 'v8', 33 | 34 | // A list of reporter names that Jest uses when writing coverage reports 35 | // coverageReporters: [ 36 | // "json", 37 | // "text", 38 | // "lcov", 39 | // "clover" 40 | // ], 41 | 42 | // An object that configures minimum threshold enforcement for coverage results 43 | // coverageThreshold: undefined, 44 | 45 | // A path to a custom dependency extractor 46 | // dependencyExtractor: undefined, 47 | 48 | // Make calling deprecated APIs throw helpful error messages 49 | // errorOnDeprecated: false, 50 | 51 | // Force coverage collection from ignored files using an array of glob patterns 52 | // forceCoverageMatch: [], 53 | 54 | // A path to a module which exports an async function that is triggered once before all test suites 55 | // globalSetup: undefined, 56 | 57 | // A path to a module which exports an async function that is triggered once after all test suites 58 | // globalTeardown: undefined, 59 | 60 | // A set of global variables that need to be available in all test environments 61 | // globals: {}, 62 | 63 | // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. 64 | // maxWorkers: "50%", 65 | 66 | // An array of directory names to be searched recursively up from the requiring module's location 67 | // moduleDirectories: [ 68 | // "node_modules" 69 | // ], 70 | 71 | // An array of file extensions your modules use 72 | // moduleFileExtensions: [ 73 | // "js", 74 | // "json", 75 | // "jsx", 76 | // "ts", 77 | // "tsx", 78 | // "node" 79 | // ], 80 | 81 | // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module 82 | // moduleNameMapper: {}, 83 | 84 | // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader 85 | // modulePathIgnorePatterns: [], 86 | 87 | // Activates notifications for test results 88 | // notify: false, 89 | 90 | // An enum that specifies notification mode. Requires { notify: true } 91 | // notifyMode: "failure-change", 92 | 93 | // A preset that is used as a base for Jest's configuration 94 | // preset: undefined, 95 | 96 | // Run tests from one or more projects 97 | // projects: undefined, 98 | 99 | // Use this configuration option to add custom reporters to Jest 100 | // reporters: undefined, 101 | 102 | // Automatically reset mock state between every test 103 | // resetMocks: false, 104 | 105 | // Reset the module registry before running each individual test 106 | // resetModules: false, 107 | 108 | // A path to a custom resolver 109 | // resolver: undefined, 110 | 111 | // Automatically restore mock state between every test 112 | // restoreMocks: false, 113 | 114 | // The root directory that Jest should scan for tests and modules within 115 | // rootDir: undefined, 116 | 117 | // A list of paths to directories that Jest should use to search for files in 118 | // roots: [ 119 | // "" 120 | // ], 121 | 122 | // Allows you to use a custom runner instead of Jest's default test runner 123 | // runner: "jest-runner", 124 | 125 | // The paths to modules that run some code to configure or set up the testing environment before each test 126 | // setupFiles: [], 127 | 128 | // A list of paths to modules that run some code to configure or set up the testing framework before each test 129 | // setupFilesAfterEnv: [], 130 | 131 | // The number of seconds after which a test is considered as slow and reported as such in the results. 132 | // slowTestThreshold: 5, 133 | 134 | // A list of paths to snapshot serializer modules Jest should use for snapshot testing 135 | // snapshotSerializers: [], 136 | 137 | // The test environment that will be used for testing 138 | testEnvironment: 'node', 139 | 140 | // Options that will be passed to the testEnvironment 141 | // testEnvironmentOptions: {}, 142 | 143 | // Adds a location field to test results 144 | // testLocationInResults: false, 145 | 146 | // The glob patterns Jest uses to detect test files 147 | testMatch: [ 148 | '**/test/**/*.[jt]s?(x)', 149 | // "**/?(*.)+(spec|test).[tj]s?(x)" 150 | ], 151 | 152 | // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped 153 | // testPathIgnorePatterns: [ 154 | // "/node_modules/" 155 | // ], 156 | 157 | // The regexp pattern or array of patterns that Jest uses to detect test files 158 | // testRegex: [], 159 | 160 | // This option allows the use of a custom results processor 161 | // testResultsProcessor: undefined, 162 | 163 | // This option allows use of a custom test runner 164 | // testRunner: "jasmine2", 165 | 166 | // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href 167 | // testURL: "http://localhost", 168 | 169 | // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" 170 | // timers: "real", 171 | 172 | // A map from regular expressions to paths to transformers 173 | // transform: undefined, 174 | 175 | // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation 176 | // transformIgnorePatterns: [ 177 | // "/node_modules/", 178 | // "\\.pnp\\.[^\\/]+$" 179 | // ], 180 | 181 | // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them 182 | // unmockedModulePathPatterns: undefined, 183 | 184 | // Indicates whether each individual test should be reported during the run 185 | // verbose: undefined, 186 | 187 | // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode 188 | // watchPathIgnorePatterns: [], 189 | 190 | // Whether to use watchman for file crawling 191 | // watchman: true, 192 | } 193 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Jeff Pelton (jeffpelton.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "podcast-index-api", 3 | "version": "1.1.10", 4 | "description": "JS lib for the Podcast Index API", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "dependencies": { 10 | "got": "^11.6.0" 11 | }, 12 | "devDependencies": { 13 | "jest": "^26.4.2", 14 | "prettier": "2.1.1" 15 | }, 16 | "scripts": { 17 | "test": "jest --coverage", 18 | "format": "npx prettier --write .", 19 | "tag": "npm version patch && git push && git push --tags" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+ssh://git@github.com/comster/podcast-index-api.git" 24 | }, 25 | "keywords": [ 26 | "API", 27 | "Podcast", 28 | "Directory", 29 | "Podcasts", 30 | "Search" 31 | ], 32 | "author": { 33 | "name": "Jeff Pelton", 34 | "email": "jeff@jeffpelton.com", 35 | "url": "https://www.jeffpelton.com/" 36 | }, 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/comster/podcast-index-api/issues" 40 | }, 41 | "homepage": "https://github.com/comster/podcast-index-api" 42 | } 43 | -------------------------------------------------------------------------------- /test/api.js: -------------------------------------------------------------------------------- 1 | jest.setTimeout(10000) 2 | 3 | const lib = require('../index.js') 4 | const api = lib( 5 | process.env.PODCASTINDEX_API_KEY, 6 | process.env.PODCASTINDEX_API_SECRET 7 | ) 8 | const apiBadCreds = lib('ABC', '123') 9 | 10 | const SEARCH_TERM = 'The Joe Rogan Experience' 11 | const SEARCH_PERSON = 'Joe Rogan' 12 | const FEED_ID = 550168 13 | const FEED_ID_VALUE = 920666 14 | const FEED_ITUNES_ID = 360084272 15 | const FEED_TITLE = 'The Joe Rogan Experience' 16 | const FEED_URL = 'http://joeroganexp.joerogan.libsynpro.com/rss' 17 | const FEED_URL_NOT_FOUND = 'http://www.google.com/' 18 | const FEED_URL_VALUE = 'https://mp3s.nashownotes.com/pc20rss.xml' 19 | const EPISODE_ID = 16795090 20 | const RECENT_FEEDS_COUNT = 3 21 | const RECENT_EPISODES_COUNT = 3 22 | const RECENT_EPISODES_EXCLUDE = 'news' 23 | const FEED_GUID = '9d783600-a77f-5c77-9042-0d9f3280465e' 24 | 25 | it('Requires API credentials', () => { 26 | expect(() => { 27 | const apiNoCreds = lib() 28 | }).toThrow() 29 | }) 30 | 31 | it('Custom', async () => { 32 | expect.assertions(4) 33 | const results = await api.custom('search/byterm', { 34 | q: SEARCH_TERM, 35 | }) 36 | expect(results.status).toEqual('true') 37 | expect(results.feeds.length).toBeGreaterThan(0) 38 | expect(results).toHaveProperty('query', SEARCH_TERM) 39 | expect(results).toHaveProperty('feeds') 40 | }) 41 | 42 | it('Search by term (async)', async () => { 43 | expect.assertions(4) 44 | const results = await api.searchByTerm(SEARCH_TERM) 45 | expect(results.status).toEqual('true') 46 | expect(results.feeds.length).toBeGreaterThan(0) 47 | expect(results).toHaveProperty('query', SEARCH_TERM) 48 | expect(results).toHaveProperty('feeds') 49 | // expect(results.feeds[0].id).toEqual(FEED_ID) 50 | // expect(results.feeds[0].title).toEqual(FEED_TITLE) 51 | }) 52 | 53 | it('Search by term (promise)', async () => { 54 | expect.assertions(4) 55 | return api.searchByTerm(SEARCH_TERM).then((results) => { 56 | expect(results.status).toEqual('true') 57 | expect(results.feeds.length).toBeGreaterThan(0) 58 | expect(results).toHaveProperty('query', SEARCH_TERM) 59 | expect(results).toHaveProperty('feeds') 60 | // expect(results.feeds[0].id).toEqual(FEED_ID) 61 | // expect(results.feeds[0].title).toEqual(FEED_TITLE) 62 | }) 63 | }) 64 | 65 | it('Search by term (value)', async () => { 66 | expect.assertions(4) 67 | const searchTerm = 'no agenda' 68 | const results = await api.searchByTerm(searchTerm, 'lightning') 69 | expect(results.status).toEqual('true') 70 | expect(results.feeds.length).toBeGreaterThan(0) 71 | expect(results).toHaveProperty('query', searchTerm) 72 | expect(results).toHaveProperty('feeds') 73 | // expect(results.feeds[0].id).toEqual(FEED_ID) 74 | // expect(results.feeds[0].title).toEqual(FEED_TITLE) 75 | }) 76 | 77 | it('Search by title', async () => { 78 | expect.assertions(6) 79 | const results = await api.searchByTitle(FEED_TITLE) 80 | expect(results.status).toEqual('true') 81 | expect(results.feeds.length).toBeGreaterThan(0) 82 | expect(results).toHaveProperty('query', FEED_TITLE) 83 | expect(results).toHaveProperty('feeds') 84 | expect(results.feeds[0].id).toEqual(FEED_ID) 85 | expect(results.feeds[0].title).toEqual(FEED_TITLE) 86 | }) 87 | 88 | it('Search episodes by person', async () => { 89 | expect.assertions(4) 90 | const results = await api.searchEpisodesByPerson(SEARCH_PERSON) 91 | expect(results.status).toEqual('true') 92 | expect(results.items.length).toBeGreaterThan(0) 93 | expect(results).toHaveProperty('query', SEARCH_PERSON) 94 | expect(results).toHaveProperty('items') 95 | }) 96 | 97 | // it('Add feed by URL', async () => { 98 | // const results = await api.addByFeedUrl(FEED_URL) 99 | // expect.assertions(1) 100 | // expect(results.status).toEqual('true') 101 | // }) 102 | 103 | // it('Add feed by iTunes ID', async () => { 104 | // const results = await api.addByItunesId(FEED_ITUNES_ID) 105 | // console.log(results) 106 | // expect.assertions(1) 107 | // expect(results.status).toEqual('true') 108 | // }) 109 | 110 | it('Episodes By Feed Id', async () => { 111 | expect.assertions(2) 112 | const results = await api.episodesByFeedId(FEED_ID) 113 | // console.log(results) 114 | expect(results.items.length).toBeGreaterThan(0) 115 | expect(results).toHaveProperty('query', FEED_ID.toString()) 116 | // expect(results.items[0].feedId).toEqual(FEED_ID.toString()) // TODO is it feedid or feedId? 117 | }) 118 | 119 | it('Episodes By Feed URL', async () => { 120 | expect.assertions(3) 121 | const results = await api.episodesByFeedUrl(FEED_URL) 122 | expect(results.items.length).toBeGreaterThan(0) 123 | expect(results).toHaveProperty('query', FEED_URL) 124 | expect(results.items[0].feedId).toEqual(FEED_ID) 125 | }) 126 | 127 | it('Episodes By Feed iTunes ID', async () => { 128 | expect.assertions(3) 129 | const results = await api.episodesByItunesId(FEED_ITUNES_ID) 130 | expect(results.items.length).toBeGreaterThan(0) 131 | expect(results).toHaveProperty('query', FEED_ITUNES_ID.toString()) 132 | expect(results.items[0].feedId).toEqual(FEED_ID) 133 | }) 134 | 135 | it('Episodes By ID', async () => { 136 | expect.assertions(1) 137 | const results = await api.episodesById(EPISODE_ID) 138 | // expect(results).toHaveProperty('query', EPISODE_ID.toString()) 139 | expect(results.episode.id).toEqual(EPISODE_ID) 140 | }) 141 | 142 | it('Episodes random', async () => { 143 | expect.assertions(2) 144 | const results = await api.episodesRandom(2) 145 | // expect(results).toHaveProperty('query', EPISODE_ID.toString()) 146 | expect(results.count).toEqual(2) 147 | expect(results.episodes.length).toEqual(2) 148 | }) 149 | 150 | it('Podcasts By Feed URL', async () => { 151 | expect.assertions(3) 152 | const results = await api.podcastsByFeedUrl(FEED_URL) 153 | expect(results).toHaveProperty('query.url', FEED_URL) 154 | expect(results.feed.id).toEqual(FEED_ID) 155 | expect(results.feed.itunesId).toEqual(FEED_ITUNES_ID) 156 | }) 157 | 158 | it('Podcasts By Feed URL not found', async () => { 159 | expect.assertions(1) 160 | try { 161 | const results = await api.podcastsByFeedUrl(FEED_URL_NOT_FOUND) 162 | } catch (e) { 163 | expect(e.code).toEqual(400) 164 | } 165 | }) 166 | 167 | it('Podcasts By Feed ID', async () => { 168 | expect.assertions(3) 169 | const results = await api.podcastsByFeedId(FEED_ID) 170 | expect(results).toHaveProperty('query.id', FEED_ID.toString()) 171 | expect(results.feed.id).toEqual(FEED_ID) 172 | expect(results.feed.itunesId).toEqual(FEED_ITUNES_ID) 173 | }) 174 | 175 | it('Podcasts By Feed iTunes ID', async () => { 176 | expect.assertions(3) 177 | const results = await api.podcastsByFeedItunesId(FEED_ITUNES_ID) 178 | expect(results).toHaveProperty('query.id', FEED_ITUNES_ID.toString()) 179 | expect(results.feed.id).toEqual(FEED_ID) 180 | expect(results.feed.itunesId).toEqual(FEED_ITUNES_ID) 181 | }) 182 | 183 | it('Podcasts By GUID', async () => { 184 | expect.assertions(3) 185 | const results = await api.podcastsByGUID(FEED_GUID) 186 | expect(results).toHaveProperty('query.id', FEED_ID) 187 | expect(results.feed.id).toEqual(FEED_ID) 188 | expect(results.feed.itunesId).toEqual(FEED_ITUNES_ID) 189 | }) 190 | 191 | it('Podcasts By tag', async () => { 192 | expect.assertions(3) 193 | const results = await api.podcastsByTag() 194 | expect(results.status).toEqual('true') 195 | expect(results.feeds.length).toBeGreaterThan(1) 196 | expect(results.count).toBeGreaterThan(1) 197 | }) 198 | 199 | it('Podcasts trending', async () => { 200 | expect.assertions(3) 201 | const results = await api.podcastsTrending() 202 | expect(results.status).toEqual('true') 203 | expect(results.feeds.length).toEqual(10) 204 | expect(results.count).toEqual(10) 205 | }) 206 | 207 | it('Podcasts dead', async () => { 208 | expect.assertions(3) 209 | const results = await api.podcastsDead() 210 | expect(results.status).toEqual('true') 211 | expect(results.feeds.length).toBeGreaterThan(1) 212 | expect(results.count).toBeGreaterThan(1) 213 | }) 214 | 215 | it('Recent Feeds', async () => { 216 | expect.assertions(1) 217 | const results = await api.recentFeeds(RECENT_FEEDS_COUNT, null, 'news') 218 | // console.log(results) 219 | // expect(results).toHaveProperty('count', RECENT_FEEDS_COUNT) 220 | // expect(results).toHaveProperty('max', RECENT_FEEDS_COUNT.toString()) 221 | expect(results.feeds.length).toEqual(RECENT_FEEDS_COUNT) 222 | }) 223 | 224 | it('Recent Feeds in language', async () => { 225 | expect.assertions(2) 226 | const results = await api.recentFeeds(RECENT_FEEDS_COUNT, null, null, 'ja') 227 | // console.log(results) 228 | // expect(results).toHaveProperty('count', RECENT_FEEDS_COUNT) 229 | // expect(results).toHaveProperty('max', RECENT_FEEDS_COUNT.toString()) 230 | expect(results.feeds.length).toEqual(RECENT_FEEDS_COUNT) 231 | expect(results.feeds[0].language).toEqual('ja') 232 | }) 233 | 234 | it('Recent Episodes', async () => { 235 | expect.assertions(3) 236 | const results = await api.recentEpisodes(RECENT_FEEDS_COUNT) 237 | expect(results).toHaveProperty('count', RECENT_FEEDS_COUNT) 238 | expect(results).toHaveProperty('max', RECENT_FEEDS_COUNT.toString()) 239 | expect(results.items.length).toEqual(RECENT_FEEDS_COUNT) 240 | }) 241 | 242 | it('Recent Episodes', async () => { 243 | expect.assertions(6) 244 | const results = await api.recentEpisodes( 245 | RECENT_EPISODES_COUNT, 246 | RECENT_EPISODES_EXCLUDE 247 | ) 248 | expect(results).toHaveProperty('count', RECENT_EPISODES_COUNT) 249 | expect(results).toHaveProperty('max', RECENT_EPISODES_COUNT.toString()) 250 | expect(results.items.length).toEqual(RECENT_EPISODES_COUNT) 251 | expect(results.items[0].title).toEqual( 252 | expect.not.stringContaining(RECENT_EPISODES_EXCLUDE) 253 | ) 254 | expect(results.items[1].title).toEqual( 255 | expect.not.stringContaining(RECENT_EPISODES_EXCLUDE) 256 | ) 257 | expect(results.items[2].title).toEqual( 258 | expect.not.stringContaining(RECENT_EPISODES_EXCLUDE) 259 | ) 260 | }) 261 | 262 | it('Recent New Feeds', async () => { 263 | expect.assertions(1) 264 | const results = await api.recentNewFeeds() 265 | expect(results).toHaveProperty('status', 'true') 266 | }) 267 | 268 | it('Recent soundbites', async () => { 269 | expect.assertions(3) 270 | const results = await api.recentSoundbites(20) 271 | expect(results).toHaveProperty('status', 'true') 272 | expect(results.items.length).toBeGreaterThan(1) 273 | expect(results.count).toBeGreaterThan(1) 274 | }) 275 | 276 | it('Value By Feed URL', async () => { 277 | expect.assertions(2) 278 | const results = await api.valueByFeedUrl(FEED_URL_VALUE) 279 | expect(results).toHaveProperty('query.url', FEED_URL_VALUE) 280 | expect(results).toHaveProperty('value') 281 | }) 282 | 283 | it('Value By Feed ID', async () => { 284 | expect.assertions(2) 285 | const results = await api.valueByFeedId(FEED_ID_VALUE) 286 | expect(results).toHaveProperty('query.id', FEED_ID_VALUE.toString()) 287 | expect(results).toHaveProperty('value') 288 | }) 289 | 290 | it('Categories list', async () => { 291 | expect.assertions(5) 292 | const results = await api.categoriesList() 293 | expect(results).toHaveProperty('status', 'true') 294 | expect(results.feeds.length).toBeGreaterThan(10) 295 | expect(results.count).toBeGreaterThan(10) 296 | expect(results.feeds[0]).toHaveProperty('id', 1) 297 | expect(results.feeds[0]).toHaveProperty('name', 'Arts') 298 | }) 299 | 300 | // it('Hub pun notify', async () => { 301 | // expect.assertions(2) 302 | // const results = await api.hubPubNotify(75075) 303 | // expect(results).toHaveProperty('status', 'true') 304 | // expect(results).toHaveProperty('description', 'Feed marked for immediate update.') 305 | // }) 306 | --------------------------------------------------------------------------------