pornsearch

repository·master·Indexed 19 days ago

https://github.com/lucasleandro1204/pornsearch

A TypeScript-supported library for searching pornographic video and gif content across multiple websites. Version 2.4.3 supports drivers for pornhub, sex, motherless, redtube, xvideos, and youporn. It provides methods for video and gif retrieval, global driver and query management, and a ModuleInterface for implementing custom search providers.

Tokens
2K
Snippets
10
Records
15
Agent score
66%

What's inside pornsearch

  1. Initialize Pornsearch

    master

    You can initialize a new Pornsearch instance using the constructor or the static search factory method. By default, the instance uses the pornhub driver. You can specify a custom driver and query during initialization.

    Using the constructor

    const searcher = new Pornsearch('query', 'pornhub');

    Using the static search method

    This is a shorthand for creating a new instance with the default driver.

    const searcher = Pornsearch.search('amateur');
    // Create a searcher
    const searcher = new Pornsearch('query', 'pornhub');
    
    // OR using the static factory
    const searcher = Pornsearch.search('amateur');
  2. Search for videos and gifs

    master

    Once initialized, you can call .videos() or .gifs() to perform searches. These methods return Promises.

    • .videos(): Returns an array of video objects.
    • .gifs(page): Returns an array of gif objects for a specific page number.
    import Pornsearch, { Video, Gif } from 'pornsearch';
    
    const searcher = new Pornsearch('tits');
    
    // Search for videos
    searcher.videos().then((videos: Video[]) => {
      console.log(videos);
    });
    
    // Search for gifs on a specific page
    searcher.gifs(3).then((gifs: Gif[]) => {
      console.log(gifs);
    });
  3. Use the static search method

    master

    For a more concise syntax, you can use the static .search(query) method. This returns a search instance pre-configured with the provided query and the default 'pornhub' driver.

    const Pornsearch = require('pornsearch').search('ass');
    
    // Then call search methods
    Pornsearch.gifs()
      .then(gifs => console.log(gifs));
  4. Manage drivers and queries globally

    master

    If using the static interface, you can change the active driver or the search query for subsequent calls.

    import Pornsearch from 'pornsearch';
    
    // Change the current driver
    Pornsearch.driver('xvideos');
    
    // Check the current driver
    console.log(Pornsearch.current());
    
    // Change the query for the next search
    Pornsearch.search('pussy').gifs().then(console.log);
  5. Initialize Pornsearch with a query and driver

    master

    You can create a new instance of Pornsearch by providing a search query and an optional driver. If no driver is provided, it defaults to 'pornhub'.

    Supported drivers include: pornhub, sex, motherless, redtube, xvideos, and youporn.

    const Pornsearch = require('pornsearch');
    // query: string, driver: string (default: 'pornhub')
    const Searcher = new Pornsearch('tits', 'pornhub');
  6. Video and Gif data structures

    master

    The shape of the returned objects depends on the driver and the search type.

    Video Search Structure: Most supported sites (pornhub, sex, redtube, xvideos, youporn, motherless) return objects with:

    • title
    • url
    • thumbnail
    • duration

    Gif Search Structure:

    • pornhub: Returns title, url, and webm.
    • sex: Returns title and url.
  7. Inspect module support and status

    master

    Use these methods to inspect the capabilities of the current Pornsearch instance:

    • support(): Returns an array of all supported module names (e.g., ['pornhub', 'sex', 'redtube']).
    • current(): Returns the name of the currently active module.
    • query (getter): Returns the current search query string.
    • supportsVideos(): Returns true if the current module supports video searches.
    • supportsGifs(): Returns true if the current module supports GIF searches.
  8. Change the driver and query

    master

    You can switch the active module (driver) or update the search query using the driver and setQuery methods. Both methods support method chaining.

    driver(driver: string, query?: string)

    Switches the active module to the specified name (e.g., 'pornhub', 'sex', 'redtube'). If a query is provided, it updates the module's query.

    setQuery(query: string)

    Updates the search query for the currently active module.

    • Throws: Error if the query is empty or only whitespace.

    Example

    const searcher = new Pornsearch();
    
    // Change driver
    searcher.driver('sex');
    
    // Update query
    searcher.setQuery('amateur').videos();
    // Change driver
    searcher.driver('sex');
    
    // Update query
    searcher.setQuery('amateur').videos();
  9. Define a custom search module using ModuleInterface

    master

    To implement a new search provider (e.g., a new website), your module must satisfy the ModuleInterface. Modules are identified by a name and a firstpage index. Depending on the content type supported, you can optionally implement URL generation and parsing logic for videos or GIFs.

    Supported capabilities include:

    • Video Search: Implement videoUrl (a UrlGenerator) and videoParser (a VideoParser).
    • GIF Search: Implement gifUrl (a UrlGenerator) and gifParser (a GifParser).
    export interface ModuleInterface {
      readonly name: string;
      readonly firstpage: number;
      query: string;
      videoUrl?: UrlGenerator;
      gifUrl?: UrlGenerator;
      videoParser?: VideoParser;
      gifParser?: GifParser;
    }