Skip to main content

A Python package for searching and retrieving YouTube data using py_yt.

Project description

YouTube Data Extraction with PY-YT

This project demonstrates how to use the py-yt library to interact with YouTube's data, including searching for videos, channels, playlists, retrieving video details, extracting comments, transcripts, and fetching search suggestions.

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 using:

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

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).
  • yt-py 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_yt_search-0.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_yt_search-0.1-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file py_yt_search-0.1.tar.gz.

File metadata

  • Download URL: py_yt_search-0.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for py_yt_search-0.1.tar.gz
Algorithm Hash digest
SHA256 532f839b1a1288496e4ab355218fd4e1ac5dd96c1b1edf60ec711a04f94620b1
MD5 1e0b7646253141acec411028024ace35
BLAKE2b-256 da26f93ac9cb7132760b6a9e645a73b38a42823a96660a124a06d2fc0f1700f6

See more details on using hashes here.

File details

Details for the file py_yt_search-0.1-py3-none-any.whl.

File metadata

  • Download URL: py_yt_search-0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for py_yt_search-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 608d04cad67e9e68cef762712629fea93304fca211c74cc931e62e76a0c74c67
MD5 ec5214ae0b0b8bd4ce9c5dc7de1067a0
BLAKE2b-256 9e9838112c2f120ebc911851158ce8359d2efdb4a9583ef4da07cb2905e66b02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page