You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

py-yt-search

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

py-yt-search

A Python package for searching and retrieving YouTube data using py-yt-search.

0.3
Source
pipPyPI
Maintainers
1

Features

  • Search YouTube for videos, channels, and playlists
  • Retrieve video information and available formats
  • Extract comments from videos
  • Get video transcripts in different languages
  • Fetch search suggestions from YouTube
  • Retrieve details of YouTube channels and their playlists

Installation

Make sure you have Python installed (>=3.8). Install py-yt-search using:

pip install git+https://github.com/AshokShau/py-yt-search@master
pip install py-yt-search

Usage

The script uses asyncio to execute YouTube queries asynchronously. Below is an overview of the main functions:

Search YouTube

_search = Search('NoCopyrightSounds', limit=1, language='en', region='US')
result = await _search.next()
print(result)

Search for Videos Only

videosSearch = VideosSearch('NoCopyrightSounds', limit=10, language='en', region='US')
videosResult = await videosSearch.next()
print(videosResult)

Search for Channels Only

channelsSearch = ChannelsSearch('NoCopyrightSounds', limit=1, language='en', region='US')
channelsResult = await channelsSearch.next()
print(channelsResult)

Search for Playlists Only

playlistsSearch = PlaylistsSearch('NoCopyrightSounds', limit=1, language='en', region='US')
playlistsResult = await playlistsSearch.next()
print(playlistsResult)

Get Video Details

video = await Video.get('z0GKGpObgPY')
print(video)

Get Playlist Details

playlist = await Playlist.get('https://www.youtube.com/playlist?list=PLRBp0Fe2GpgmsW46rJyudVFlY6IYjFBIK')
print(playlist)

Fetch Comments from a Video

comments = Comments('_ZdsmLgCVdU')
await comments.getNextComments()
print(len(comments.comments['result']))

Retrieve Video Transcript

transcript = await Transcript.get('https://www.youtube.com/watch?v=L7kF4MXXCoA')
print(transcript)

Get YouTube Search Suggestions

suggestions = await Suggestions.get('NoCopyrightSounds', language='en', region='US')
print(suggestions)

Running the Script

To run the script, execute:

python script.py

Ensure asyncio.run(main()) is at the end of the script to handle async execution.

Notes

  • The script uses asyncio for efficient asynchronous operations.
  • Some operations may require multiple calls to retrieve all available data (e.g., pagination for comments and playlists).
  • py-yt-search provides various search filters to refine results, such as sorting by upload date or filtering by duration.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Credits

This project is based on youtube-search-python by Alex Mercer.

Keywords

youtube youtube-api video-search playlist channel search py_yt py-yt-search py-yt

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts