cap-from-youtube


Namecap-from-youtube JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryGet an OpenCV video capture from an YouTube video URL
upload_time2024-08-26 01:12:23
maintainerNone
docs_urlNone
authorIbai Gorordo
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cap_from_youtube
 Get an OpenCV video capture from an YouTube video URL

[![PyPI](https://img.shields.io/pypi/v/cap-from-youtube?color=2BAF2B)](https://pypi.org/project/cap-from-youtube/)
<p align="center">
  <img src="https://raw.githubusercontent.com/ibaiGorordo/cap_from_youtube/main/doc/img/cap_from_youtube_logo.png" />
</p>

# Why
- pafy is widely used to get the video URL from a YouTube video URL, but since it uses youtube-dl which has not been updated recently, it suffers from some issues (dislike_count not found...).
- This repository is a simplified version of what pafy does, by just getting the url of the video and creating an OpenCV video capture from it.
- It uses YT-DLP (https://github.com/yt-dlp/yt-dlp), which is a fork of youtube-dl that is updated frequently.

# Requirement
* YT-DLP
* OpenCV
* NumPy
 
# Installation
- The easiest way is to install it with pip:

```bash
pip install cap_from_youtube
```
- You can also install it from GitHub:

```bash
pip install git+https://github.com/ibaiGorordo/cap_from_youtube
```

# Usage

## cap_from_youtube()
- `cap_from_youtube()` is the main function to obtain a video capture from a YouTube video URL. 
- It requires the video URL as input and returns a `cv2.VideoCapture` object.
- By default, it returns the video with the highest resolution available.
- You can specify the resolution you want to get with the `resolution` parameter.
  - Available resolutions: '144p', '240p', '360p', '480p', '720p', '720p60', '1080p', '1080p60', 'best'
- Example:

```python
from datetime import timedelta
import cv2
from cap_from_youtube import cap_from_youtube

youtube_url = 'https://youtu.be/LXb3EKWsInQ'
start_time = timedelta(seconds=5)
cap = cap_from_youtube(youtube_url, 'best', start=start_time)

cv2.namedWindow('video', cv2.WINDOW_NORMAL)
while True:
    ret, frame = cap.read()
    if not ret:
        break
    cv2.imshow('video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
```

## list_video_streams()
- You can also use the `list_video_streams()` function to get the list of available video streams.
- It requires the video URL as input and returns two values: 
  - streams: a list of VideoStream with the information of the available video streams.
  - resolutions: a NumPy array with the available resolutions.
- Example:
```python
from cap_from_youtube import list_video_streams

youtube_url = 'https://youtu.be/LXb3EKWsInQ'
streams, resolutions = list_video_streams(youtube_url)

for stream in streams:
    print(stream)
```
 
# References
- pafy: https://github.com/mps-youtube/pafy
- yt-dlp: https://github.com/yt-dlp/yt-dlp
- imread_from_url: https://github.com/Kazuhito00/imread_from_url

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cap-from-youtube",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Ibai Gorordo",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/47/e4/cfbd571ac083a010f3372543c9b8a6c0c4df074a139a3787c70d061a8d67/cap_from_youtube-0.2.0.tar.gz",
    "platform": null,
    "description": "# cap_from_youtube\r\n Get an OpenCV video capture from an YouTube video URL\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/cap-from-youtube?color=2BAF2B)](https://pypi.org/project/cap-from-youtube/)\r\n<p align=\"center\">\r\n  <img src=\"https://raw.githubusercontent.com/ibaiGorordo/cap_from_youtube/main/doc/img/cap_from_youtube_logo.png\" />\r\n</p>\r\n\r\n# Why\r\n- pafy is widely used to get the video URL from a YouTube video URL, but since it uses youtube-dl which has not been updated recently, it suffers from some issues (dislike_count not found...).\r\n- This repository is a simplified version of what pafy does, by just getting the url of the video and creating an OpenCV video capture from it.\r\n- It uses YT-DLP (https://github.com/yt-dlp/yt-dlp), which is a fork of youtube-dl that is updated frequently.\r\n\r\n# Requirement\r\n* YT-DLP\r\n* OpenCV\r\n* NumPy\r\n \r\n# Installation\r\n- The easiest way is to install it with pip:\r\n\r\n```bash\r\npip install cap_from_youtube\r\n```\r\n- You can also install it from GitHub:\r\n\r\n```bash\r\npip install git+https://github.com/ibaiGorordo/cap_from_youtube\r\n```\r\n\r\n# Usage\r\n\r\n## cap_from_youtube()\r\n- `cap_from_youtube()` is the main function to obtain a video capture from a YouTube video URL. \r\n- It requires the video URL as input and returns a `cv2.VideoCapture` object.\r\n- By default, it returns the video with the highest resolution available.\r\n- You can specify the resolution you want to get with the `resolution` parameter.\r\n  - Available resolutions: '144p', '240p', '360p', '480p', '720p', '720p60', '1080p', '1080p60', 'best'\r\n- Example:\r\n\r\n```python\r\nfrom datetime import timedelta\r\nimport cv2\r\nfrom cap_from_youtube import cap_from_youtube\r\n\r\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\r\nstart_time = timedelta(seconds=5)\r\ncap = cap_from_youtube(youtube_url, 'best', start=start_time)\r\n\r\ncv2.namedWindow('video', cv2.WINDOW_NORMAL)\r\nwhile True:\r\n    ret, frame = cap.read()\r\n    if not ret:\r\n        break\r\n    cv2.imshow('video', frame)\r\n    if cv2.waitKey(1) & 0xFF == ord('q'):\r\n        break\r\n```\r\n\r\n## list_video_streams()\r\n- You can also use the `list_video_streams()` function to get the list of available video streams.\r\n- It requires the video URL as input and returns two values: \r\n  - streams: a list of VideoStream with the information of the available video streams.\r\n  - resolutions: a NumPy array with the available resolutions.\r\n- Example:\r\n```python\r\nfrom cap_from_youtube import list_video_streams\r\n\r\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\r\nstreams, resolutions = list_video_streams(youtube_url)\r\n\r\nfor stream in streams:\r\n    print(stream)\r\n```\r\n \r\n# References\r\n- pafy: https://github.com/mps-youtube/pafy\r\n- yt-dlp: https://github.com/yt-dlp/yt-dlp\r\n- imread_from_url: https://github.com/Kazuhito00/imread_from_url\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Get an OpenCV video capture from an YouTube video URL",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/ibaiGorordo/cap_from_youtube"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cffbb7860bf3592025b04309986c2815d459945c11b2cad64a833fc57d303a9f",
                "md5": "c6cc5e9cdaf534a79287b2ab4f802b04",
                "sha256": "38e6243310cb1e76b036ff82e8740781f7b492823ce5ad2a78f9ac470f16a22a"
            },
            "downloads": -1,
            "filename": "cap_from_youtube-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6cc5e9cdaf534a79287b2ab4f802b04",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4710,
            "upload_time": "2024-08-26T01:12:22",
            "upload_time_iso_8601": "2024-08-26T01:12:22.180235Z",
            "url": "https://files.pythonhosted.org/packages/cf/fb/b7860bf3592025b04309986c2815d459945c11b2cad64a833fc57d303a9f/cap_from_youtube-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47e4cfbd571ac083a010f3372543c9b8a6c0c4df074a139a3787c70d061a8d67",
                "md5": "d4aa2f524d17a030f9246a2aab3939f5",
                "sha256": "6bd803caebac878c1a75183a43f55636f3b252e993e3a08e86fc7fb084be2f97"
            },
            "downloads": -1,
            "filename": "cap_from_youtube-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d4aa2f524d17a030f9246a2aab3939f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4129,
            "upload_time": "2024-08-26T01:12:23",
            "upload_time_iso_8601": "2024-08-26T01:12:23.162069Z",
            "url": "https://files.pythonhosted.org/packages/47/e4/cfbd571ac083a010f3372543c9b8a6c0c4df074a139a3787c70d061a8d67/cap_from_youtube-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 01:12:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ibaiGorordo",
    "github_project": "cap_from_youtube",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cap-from-youtube"
}
        
Elapsed time: 0.43140s