Amazing-Python-Scripts icon indicating copy to clipboard operation
Amazing-Python-Scripts copied to clipboard

M3u link scamner

Open Salehin-07 opened this issue 4 weeks ago • 1 comments

Description

Added a new m3u links scanner which can say if a m3u link is broken or not

Fixes #(issue_no)

#3270

Type of change

Please delete options that are not relevant.

  • [ ] New feature (non-breaking change which adds functionality)

Checklist:

  • [ ] My code follows the style guidelines(Clean Code) of this project
  • [ ] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have created a helpful and easy to understand README.md
  • [ ] My documentation follows Template for README.md
  • [ ] I have added the project meta data in the PR template.
  • [ ] I have created the requirements.txt file if needed.

Category:

  • [ ] Scrappers
  • [ ] Others

Title: <m3u links scanner >

Folder: <M3U_link_scanner>

Requirements: <M3U_link_scanner/requirements.txt >

Script: <M3U_link_scanner/iptv_tester.py>

Arguments: <none> Contributor: <Salehin-07 >

Description: <made a script that throughly checks an iptv .m3u link and gives results. Takes approximately 1 min per link>

Summary by Sourcery

Add a new script for comprehensively testing IPTV M3U links and classifying them as working or broken based on multiple connectivity and streaming checks.

New Features:

  • Introduce an IPTV link tester script that validates M3U stream URLs using multiple HTTP, socket, and ffmpeg-based checks and writes results to separate output files.

Documentation:

  • Add a README explaining installation, configuration, usage, and behavior of the IPTV M3U link tester tool.

Salehin-07 avatar Dec 04 '25 19:12 Salehin-07

Reviewer's Guide

Adds a new IPTV M3U link scanner script that reads IPTV URLs from a file, performs multiple network- and ffmpeg-based health checks per link, and writes working vs broken links with success rates to separate output files, documented by a dedicated README and backed by a minimal requirements file.

Sequence diagram for comprehensive testing of a single IPTV link

sequenceDiagram
    actor User
    participant CLI as main
    participant Tester as IPTVLinkTester
    participant FileSystem
    participant HTTP as requests
    participant Net as socket
    participant FFprobe as ffprobe_subprocess

    User->>CLI: run iptv_tester.py
    CLI->>Tester: instantiate IPTVLinkTester()
    CLI->>Tester: process_links()
    Tester->>FileSystem: open input_file
    FileSystem-->>Tester: list of links

    loop for each link
        Tester->>Tester: test_link_comprehensive(url, index, total)

        loop HTTP HEAD attempts
            Tester->>HTTP: head(url, headers, timeout)
            HTTP-->>Tester: status_code
        end

        loop HTTP GET partial attempts
            Tester->>HTTP: get(url, range 0-1024, stream=True)
            HTTP-->>Tester: response
            Tester->>Tester: read small chunk
        end

        loop HTTP streaming attempts
            Tester->>HTTP: get(url, stream=True)
            HTTP-->>Tester: response
            Tester->>Tester: read multiple chunks
        end

        loop socket attempts
            Tester->>Net: connect_ex(host, port)
            Net-->>Tester: result
        end

        loop ffprobe attempts
            Tester->>FFprobe: subprocess.run(ffprobe, url, timeout)
            FFprobe-->>Tester: returncode
        end

        Tester->>Tester: aggregate results
        alt any test passed
            Tester->>Tester: mark link as working
        else all tests failed
            Tester->>Tester: mark link as broken
        end
    end

    Tester->>FileSystem: write working_links.txt
    Tester->>FileSystem: write broken_links.txt
    Tester-->>CLI: summary printed
    CLI-->>User: display results

Class diagram for the IPTV M3U link scanner

classDiagram
    class IPTVLinkTester {
        +str input_file
        +str working_file
        +str broken_file
        +int timeout
        +int attempts
        +dict headers
        +__init__(input_file, working_file, broken_file)
        +test_http_head(url)
        +test_http_get_partial(url)
        +test_http_streaming(url)
        +test_socket_connection(url)
        +test_with_ffmpeg(url)
        +test_link_comprehensive(url, link_number, total_links)
        +process_links()
    }

    class ModuleLevel {
        +main()
    }

    ModuleLevel ..> IPTVLinkTester : creates

Flow diagram for IPTV link processing and classification

flowchart TD
    A_start([Start]) --> B_init[Create IPTVLinkTester instance]
    B_init --> C_read[Read iptv_links.txt]
    C_read -->|file not found or empty| Z_end_error([Exit with error message])
    C_read -->|links loaded| D_iterate[[For each link]]

    D_iterate --> E_test["test_link_comprehensive(url, link_number, total_links)"]

    subgraph Comprehensive_testing_per_link
        direction TB
        E_test --> F1[HTTP HEAD tests<br/>1..attempts]
        F1 --> F2[HTTP GET partial tests<br/>1..attempts]
        F2 --> F3[HTTP streaming tests<br/>1..attempts]
        F3 --> F4[Socket connection tests<br/>1..attempts]
        F4 --> F5[FFmpeg probe tests<br/>1..attempts]
        F5 --> G_agg[Aggregate all test results<br/>compute success_percentage]
        G_agg --> H_decision{Any test passed?}
        H_decision -->|yes| I_work[Append link with success rate<br/>to working_links]
        H_decision -->|no| J_broken[Append link with note<br/>to broken_links]
    end

    I_work --> K_next[Optional delay before<br/>next link]
    J_broken --> K_next

    K_next -->|more links| D_iterate
    K_next -->|no more links| L_write[Write working_links.txt<br/>and broken_links.txt]
    L_write --> M_summary[Print testing summary]
    M_summary --> N_end([End])

    Z_end_error --> N_end

File-Level Changes

Change Details Files
Introduce IPTVLinkTester script that performs comprehensive multi-method health checks on IPTV/M3U links read from an input file and writes categorized results.
  • Define IPTVLinkTester class with configurable input, working, and broken link file paths plus timeout, attempts, and HTTP headers.
  • Implement multiple test methods (HTTP HEAD, partial HTTP GET, streaming GET, raw socket connect, optional ffprobe) each returning boolean availability.
  • Add comprehensive per-link test orchestration that runs all methods for multiple attempts, tracks success metrics, prints detailed progress, and classifies links as working or broken.
  • Implement process_links to load links from a text file, iterate and test each link with delays, and write annotated results to working_links.txt and broken_links.txt, with a console summary.
  • Provide a main entry point that instantiates IPTVLinkTester with defaults and starts the processing when executed as a script.
M3U_link_scanner/iptv_tester.py
Document the IPTV link tester usage, behavior, configuration, and output for end users.
  • Describe the tool’s purpose, feature set, and testing methods, including retry behavior and success-rate computation.
  • Provide installation steps, including optional ffmpeg setup guidance for different platforms.
  • Explain how to prepare the iptv_links.txt input, run the script, interpret working/broken output files, and tweak configuration parameters.
  • Detail the testing process, estimated runtime, troubleshooting tips, and caveats/limitations, along with license and disclaimer notes.
M3U_link_scanner/README.md
Declare Python dependencies required by the IPTV link tester script.
  • Add requests library with a modern minimum version for HTTP operations.
  • Add urllib3 with a modern minimum version, aligning with requests’ HTTP stack.
M3U_link_scanner/requirements.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Dec 04 '25 19:12 sourcery-ai[bot]