PornHub API

The PornHub API allows you to search for sex videos based on specified parameters.

Base URL

"https://openapi-idk8.onrender.com"

Endpoint

GET `/pornhub/search`

Query Parameters

  • category (optional): The category of videos to search for. Can be a string or an array of strings.
  • page (optional): The page number for pagination. Should be a number greater than or equal to 0.
  • search (optional): The search query as a string.
  • stars (optional): The stars to filter by. Can be a string or an array of strings.
  • tags (optional): The tags to filter by. Can be a string or an array of strings.
  • ordering (optional): The ordering of the results as a string.
  • period (optional): The period for filtering results as a string.
  • thumbsize (optional, default: 'small'): The size of the thumbnails as a string.

Sample Request

GET `https://openapi-idk8.onrender.com/pornhub/search?category=amateur`

Sample Response

{
  "videos": [
    {
      "duration": "7:36",
      "views": 96363,
      "video_id": "665887db99dd8",
      "rating": 86.2559,
      "ratings": 211,
      "title": "real public mature groupsex sport orgy",
      "url": "https://www.pornhub.org/view_video.php?viewkey=665887db99dd8",
      "default_thumb": "https://ei.phncdn.com/videos/202405/30/453166842/original/(m=e0YHGgaaaa)(mh=PiUbim9lweH1b5ms)12.jpg",
      "thumb": "https://ei.phncdn.com/videos/202405/30/453166842/original/(m=q641YLZbe0YHGgaaaa)(mh=Tib0-pagoE0W39sD)0.jpg",
      "publish_date": "2024-06-12 22:30:26",
      "thumbs": [
        {
          "size": "180x135",
          "width": "180",
          "height": "135",
          "src": "https://ei.phncdn.com/videos/202405/30/453166842/original/(m=e0YHGgaaaa)(mh=PiUbim9lweH1b5ms)1.jpg"
        },
        ...
      ]
    },
    ...
  ]
}

Error Handling

If an error occurs while fetching data, the API will respond with a 500 status code and an error message.

Helper Functions

prepareSearchURL
const prepareSearchURL = (params) => {
    let url = `${PORNHUB_API_BASE_URL}/search?`;

    if (typeof params.category === 'string') {
        url += `&categories[]=${params.category}`;
    } else if (Array.isArray(params.category)) {
        url += `&categories[]=${params.category.join(",")}`;
    }

    if (typeof params.page === 'number' && params.page >= 0) {
        url += `&page=${params.page}`;
    }

    if (typeof params.search === 'string') {
        url += `&search=${params.search}`;
    }

    if (typeof params.stars === 'string') {
        url += `&stars[]=${params.stars}`;
    } else if (Array.isArray(params.stars)) {
        url += `&stars[]=${params.stars.join(",")}`;
    }

    if (typeof params.tags === 'string') {
        url += `&tags[]=${params.tags}`;
    } else if (Array.isArray(params.tags)) {
        url += `&tags[]=${params.tags.join(",")}`;
    }

    if (typeof params.ordering === 'string') {
        url += `&ordering=${params.ordering}`;
    }

    if (typeof params.period === 'string') {
        url += `&period=${params.period}`;
    }

    if (typeof params.thumbsize === 'string') {
        url += `&thumbsize=${params.thumbsize}`;
    } else {
        url += `&thumbsize=small`;
    }

    return url;
};
sendRequest
const sendRequest = async (url) => {
    try {
        const response = await axios.get(url);
        return response.data;
    } catch (error) {
        console.error('Error fetching data:', error.message);
        throw error;
    }
};

Route Handler

app.get('/pornhub/search', async (req, res) => {
    const { category, page, search, stars, tags, ordering, period, thumbsize } = req.query;

    const params = {
        category,
        page: page ? parseInt(page) : undefined,
        search,
        stars,
        tags,
        ordering,
        period,
        thumbsize
    };

    try {
        const url = prepareSearchURL(params);
        const data = await sendRequest(url);
        res.json(data);
    } catch (error) {
        res.status(500).json({ error: 'Failed to fetch data' });
    }
});