PanSou Cloud Drive Resource Search API

repository·main·Indexed 11 days ago

https://github.com/fish2018/pansou

A high-performance API service that aggregates cloud drive resource search results from Telegram channels and custom plugins. It features intelligent sorting, asynchronous processing, and includes specialized plugins like Gying and QQPD for searching specific platforms and channels.

Tokens
113.1K
Snippets
246
Records
423
Agent score
96%

What's inside PanSou

  1. Overview of PanSou 网盘搜索API

    main

    PanSou is a high-performance cloud drive resource search API service. It supports searching via Telegram (TG) channels and custom plugins. Key features include:

    • High-Performance Search: Concurrent execution of multiple TG channels and asynchronous plugin searches using a worker pool design.
    • Cloud Drive Classification: Automatically identifies and categorizes various cloud drive links.
    • Intelligent Sorting: A multi-dimensional algorithm based on plugin levels, time freshness, and priority keywords.
    • Asynchronous Plugin System: Allows extending search sources via plugins with a "respond quickly, process continuously" model to handle slow search sources.
    • Two-Level Caching: Uses a combination of sharded memory and sharded disk caching to improve repeat query speed and concurrency performance.
  2. Overview of the SuSu Search Plugin

    main

    The SuSu search plugin is a component of the PanSou network disk search system. It is specifically designed to search and extract network disk resource links from the SuSu website (susuifa.com).

    Key features include:

    • Asynchronous Search: Implements a "respond quickly, process continuously" pattern based on BaseAsyncPlugin.
    • Multi-level Caching: Reduces redundant network requests and computations.
    • Concurrency Control: Uses goroutines and semaphores for efficient parallel searching.
    • Smart Filtering: Filters irrelevant results early in the process.
    • Resilience: Includes an exponential backoff retry strategy and fault-tolerant design that returns partial results even if some requests fail.
  3. Overview of PanSou core components

    main

    The PanSou system is organized into several functional layers:

    • HTTP Service Layer (api/): Handles routing (router.go), request processing (handler.go), and middleware like logging and CORS (middleware.go).
    • Search Service Layer (service/): Contains the core search logic and the mergeSearchResults function used to combine results from different sources.
    • Plugin System Layer (plugin/): Defines the AsyncSearchPlugin interface and provides the BaseAsyncPlugin base class. Individual plugins reside in their own subdirectories (e.g., jikepan, pan666).
    • Utility Layer (util/): Provides foundational services including the Two-Level Cache System (cache/), the Worker Pool for concurrency control (pool/), and various HTTP and parsing tools.
  4. How Gying handles anti-bot challenges (PoW)

    main

    When the target site presents a challenge (identified by specific JS snippets or text like 正在进行浏览器计算验证), the plugin solves it using one of three methods depending on the site's structure:

    1. Remote PoW: The plugin fetches challenge data from {baseURL}/res/pow, calculates the solution, and submits it via POST with the parameter y={hex(y)}.
    2. Embedded PoW: The plugin parses id, N, x, and t from the page's JSON. It performs the calculation y = (y * y) % N repeated t times using Go's math/big library, then submits action=verify&id={id}&y={hex(y)} to the current URL.
    3. Old Hash Enumeration: The plugin iterates through 0..diff to find a nonce such that sha256(nonce + salt) matches the target, then submits action=verify&id={id}&nonce[]={n1}....

    Successful verification results in a browser_verified cookie, which the plugin saves to minimize future challenges.

  5. Implement the Nyaa plugin search flow

    main

    The Nyaa plugin follows this execution lifecycle:

    1. Build Search URL: Construct the URL using the parameters described in the guide.
    2. HTTP Request: Send the request with appropriate headers (User-Agent, Referer, etc.) and implement retries with exponential backoff.
    3. Parse HTML: Use goquery to locate table.torrent-list and iterate through tbody > tr.
    4. Extract Information: Map HTML fields to the SearchResult schema.
    5. Magnet Link Extraction: Specifically target a[href^="magnet:"].
    6. Keyword Filtering: Apply plugin-level filtering to the results.
    7. Return Results: Output the mapped data.

    Data Mapping (Nyaa $\rightarrow$ SearchResult)

    Nyaa FieldSearchResult FieldDescription
    TitleTitleResource title
    Category + Size + StatsContentConcatenated description string
    Magnet LinkLinks[0].URLThe magnet link
    Release TimeDatetimeUnix timestamp conversion
    CategoryTags[0]Resource category
    Seeders/Leechers/DownloadsTags[1-3]Statistical info
    Unique IDUniqueIDFormat: nyaa-{ID}
    (N/A)ChannelEmpty string
    Link{
        Type:     "magnet",
        URL:      magnetURL,
        Password: "",
    }
  6. Implement the Bixin search workflow

    main

    To correctly process Bixin forum data into PanSou standard format, follow this sequence:

    1. Search Request: Send a request to the discussions API to get the list of discussions and included replies.
    2. Parse Discussion Data: Extract metadata like title and time.
    3. Associate Replies: Use IDs to link discussion posts with their corresponding replies (found in the included array).
    4. Clean HTML: Use a cleanHTML function (similar to pan666) to remove HTML tags and entities, leaving only pure text.
    5. Extract Links: Extract Mobile Cloud Drive links (caiyun.139.com) from the cleaned text.
    6. Match Passwords: Use a position-based association strategy to match passwords/access codes with the extracted links.
    7. Validate: Filter out invalid or broken links.
    8. Format: Convert the final data into the PanSou standard result format.
  7. Authenticate with PanSou API using JWT

    main

    When authentication is enabled (AUTH_ENABLED=true), all API endpoints except /api/auth/login and /api/health require a valid JWT Token.

    To authenticate:

    1. Call the login endpoint to receive a token.
    2. Include the token in the Authorization header of subsequent requests using the Bearer <token> format.
    3. Re-authenticate if the token expires.
    # Example of an authenticated request
    curl -X POST http://localhost:8888/api/search \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
      -d '{"kw":"速度与激情"}'
  8. Fox4K Scraping Implementation Notes

    main

    When implementing a scraper for Fox4K, adhere to these technical requirements:

    • URL Construction:
      • Search: https://www.4kfox.com/search/{keyword}-------------.html (Keyword must be URL encoded).
      • Detail: https://www.4kfox.com/video/{ID}.html.
    • Image Handling: The site uses lazy loading; always target the data-original attribute instead of src to get the actual image URL.
    • Anti-Scraping: Set appropriate User-Agent and request headers to avoid being blocked.
    • Encoding: The website uses UTF-8.
    • ID Extraction: Use the regex /video/(\d+)\.html to parse the unique resource ID from URLs.
  9. How the PanTa search plugin works

    main

    The PanTa search plugin is a Go-based crawler designed to search 91panta.cn and extract cloud drive (网盘) links. It follows a modular architecture consisting of:

    1. Initialization & Registration: Automatically registers with the global plugin manager.
    2. HTTP Client Management: Uses an optimized client with connection pooling, retry mechanisms, and adaptive concurrency control.
    3. Search Execution: Constructs search requests and fetches result pages.
    4. Result Parsing: Parses HTML to extract search result lists.
    5. Link & Password Extraction: Identifies various cloud drive link types and uses an intelligent scoring algorithm to associate them with their corresponding extraction codes (提取码).
    6. Multi-level Caching: Uses sync.Map to cache regex results, link types, passwords, and topic IDs to improve performance and reduce redundant computation.
    Data Flow:
    User Keyword → Search Request → HTTP Request
    → HTML Response → Parse Results → Concurrent Processing
    → Extract Links & Passwords → Intelligent Association → Final Results
  10. Implementation requirements for daishudj plugin

    main

    When implementing the daishudj plugin, ensure the following logic is applied:

    • Search Logic: Request the HTML list and parse .item-jx for base info.
    • Detail Logic: Scrape .article-body for <a> links and parse naked URLs from text.
    • Extraction Code: Use keyword matching (提取码/密码/pwd/code) in the vicinity of the link.
    • Date Formatting: Convert Chinese date formats (e.g., 2025年11月16日) to YYYY-MM-DD.
    • Deduplication: Use the article ID (e.g., from /1047/) as part of the UniqueID to prevent duplicate results.
  11. Parse Ouge download links and sources

    main

    Ouge provides download information using two fields: vod_down_from (source identifiers) and vod_down_url (the actual URLs). These fields use $$$ as a delimiter to support multiple sources.

    Parsing Logic

    1. Split vod_down_from by $$$.
    2. Split vod_down_url by $$$.
    3. Map the identifiers to cloud types based on their position in the array.

    Identifier Mapping

    API IdentifierCloud TypeExample Domain
    bdbaidupan.baidu.com
    KGquarkpan.quark.cn
    UCucdrive.uc.cn

    Supported Cloud Types

    • baidu: https://pan.baidu.com/s/{share_code}?pwd={password}
    • quark: https://pan.quark.cn/s/{share_code}
    • aliyun: https://aliyundrive.com/s/{share_code} or https://www.alipan.com/s/{share_code}
    • uc: https://drive.uc.cn/s/{share_code}
    • xunlei: https://pan.xunlei.com/s/{share_code}
    • tianyi: https://cloud.189.cn/t/{share_code}
    • mobile: https://caiyun.feixin.10086.cn/{share_code}
    • 115: https://115.com/s/{share_code}
    • weiyun: https://share.weiyun.com/{share_code}
    • lanzou: https://lanzou.com/{share_code}
    • jianguoyun: https://jianguoyun.com/{share_code}
    • 123: https://123pan.com/s/{share_code}
    • pikpak: https://mypikpak.com/s/{share_code}
    • magnet: magnet:?xt=urn:btih:{hash}
    • ed2k: ed2k://|file|{filename}|{size}|{hash}|/