Skip to content

Searches YouTube video with specified duration by YouTube Data API

License

Notifications You must be signed in to change notification settings

WingTillDie/youtube-video-length

Repository files navigation

YouTube Video Length Search

Searches YouTube video with specified duration by YouTube Data API

Dependencies

Usage

  1. Obtain a YouTube API key: Replace "YOUR_YOUTUBE_API_KEY" in the script with your actual YouTube API key. If you don't have one, follow the instructions to create a new API key on the Google Developer Console.

  2. Command-line arguments:

    • -q or --search-query: Provide your desired search query (e.g., "cat funny").
    • -m or --max-results: Top m search results. Default: 100
    • -i or --iso-8601: Specify the target duration in ISO 8601 time format (e.g., PT14M7S).
    • -s or --seconds: Specify the target duration in seconds (e.g., 411).
    • -l or --list: Use this option for a list of videos without filtering by duration.
  3. Run the script: Execute the script with the desired command-line arguments. For example:

./youtube-video-length-w-key.py -q "cat funny" -i PT5S
  1. Output: The script will display YouTube video titles, IDs, ISO duration, and duration in seconds for videos that match the specified criteria.
flowchart TD
    Query[Search String: cat funny<br>-q #34;cat funny#34;]
    Top[Top 100 Search Results<br>-m 100]
    Query --> Top
    Top --> Is_Filter
    Is_Filter{Enable Filter by Video Length?}
    Is_Filter -->|No| list[/--list/]
    Is_Filter -->|Yes| Time_Format
    Time_Format{Filter Time Format}
    Time_Format -->|seconds| Seconds
    Seconds[/--seconds/]
    Time_Format -->|ISO 8601| ISO_8601
    ISO_8601[/--iso-8601/]
Loading

Example Application

An example application of this program is to solve the password game with rule 24, as described on Neal.fun.

Example output

$ ./youtube-video-length-w-key.py -q "cat funny" -i PT5S
Video Title: cute cat funny dance video 😹 || #funny #funnydance #ytshort #shortfeed #youtubeshorts  #shortviral
Video ID: gSI3nr5qwXs
Video Duration (ISO): PT5S
Video Duration (s): 5 seconds

Video Title: dancing cat🐱funny dance #shorts ytshorts #viralshorts
Video ID: dAKBqZrkuhc
Video Duration (ISO): PT5S
Video Duration (s): 5 seconds
$ ./youtube-video-length-w-key.py -q "cat funny" -l -m 5
Video Title: Funny Cat Fails | Funny Cat Compilation - FailArmy
Video ID: DHfRfU3XUEo
Video Duration (ISO): PT8M14S
Video Duration (s): 494 seconds

Video Title: Funniest Cats and Dogs 🐶🐱 | Funny Animal Videos #35
Video ID: tAcjl9S9exw
Video Duration (ISO): PT12M35S
Video Duration (s): 755 seconds

Video Title: 😹 FUNNIEST Cats Ever | Hilarious Cat Videos
Video ID: O4MV5BRv-ps
Video Duration (ISO): PT1H26S
Video Duration (s): 3626 seconds

Video Title: #75 Funny Cat videos 🐱🐱 #meowing #memes #cute
Video ID: ORTR9Jz-dCc
Video Duration (ISO): PT59S
Video Duration (s): 59 seconds

Video Title: UNEXPLAINABLE Behaviour of Orange Cats 🍊😹 Funny Cat Videos 2024
Video ID: Pcw8gDYEcGQ
Video Duration (ISO): PT9M8S
Video Duration (s): 548 seconds
$ ./youtube-video-length-w-key.py -q "cat funny" -i PT45M58S
ERROR: No match with specified filter time. Try change -q, -m arguments, or use -l to list search results without filtering by time
A search result without applying time filter:
Video Title: 🤣 FUNNIEST Pet Bloopers | Dog and Cat Videos
Video ID: 3TjDDrQ4Nig
Video Duration (ISO): PT1H53S
Video Duration (s): 3653 seconds

Entity Relationship Diagram

erDiagram
    "All YouTube Videos" ||..o| "YouTube Videos with Matched Length" : "contains"
    "All YouTube Videos" ||..o| "YouTube Videos with Specified Search String" : "contains"
    "YouTube Videos with Specified Search String" ||..o| "YouTube Videos with Specified Search String, Top 100 Results": "contains"
    "YouTube Videos with Specified Search String, Top 100 Results" ||..o| "YouTube Videos with Specified Search String, Top 100 Results, with Match Length" : "contains"
    "YouTube Videos with Specified Search String, Top 100 Results" ||..o| "YouTube Videos with Specified Search String, Top 100 Results, with Not Match Length" : "contains"
    "YouTube Videos with Matched Length" ||..o| "YouTube Videos with Specified Search String, Top 100 Results, with Match Length" : "contains"
Loading

Development

Use release.py to remove api key

Disclaimer

Please note that this script uses the YouTube Data API, and you need to abide by the API usage policies set by YouTube. It's recommended to refer to the YouTube API Terms of Service and ensure compliance with their requirements.

License

This script is provided as-is and is subject to the terms of the LICENSE file. Use it responsibly and at your own risk.

About

Searches YouTube video with specified duration by YouTube Data API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages