cap-from-youtube


Namecap-from-youtube JSON
Version 0.0.10 PyPI version JSON
download
home_pagehttps://github.com/ibaiGorordo/cap_from_youtube
SummaryGet an OpenCV video capture from an YouTube video URL
upload_time2023-08-09 08:36:14
maintainer
docs_urlNone
authorIbai Gorordo
requires_python
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.
  - Resolution examples: '144p', '240p', '360p', '480p', '720p', '1080p', '1440p', '2160p', 'best'
- Example:

```python
import cv2
from cap_from_youtube import cap_from_youtube

youtube_url = 'https://youtu.be/LXb3EKWsInQ'
cap = cap_from_youtube(youtube_url, '1440p60')

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": "https://github.com/ibaiGorordo/cap_from_youtube",
    "name": "cap-from-youtube",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ibai Gorordo",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/fd/6c/560c96bdda56163c9bbfa46c77c3e50916d13a46c14dd9a5f46448aa09d9/cap_from_youtube-0.0.10.tar.gz",
    "platform": null,
    "description": "# cap_from_youtube\n Get an OpenCV video capture from an YouTube video URL\n\n[![PyPI](https://img.shields.io/pypi/v/cap-from-youtube?color=2BAF2B)](https://pypi.org/project/cap-from-youtube/)\n<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/ibaiGorordo/cap_from_youtube/main/doc/img/cap_from_youtube_logo.png\" />\n</p>\n\n# Why\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...).\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.\n- It uses YT-DLP (https://github.com/yt-dlp/yt-dlp), which is a fork of youtube-dl that is updated frequently.\n\n# Requirement\n* YT-DLP\n* OpenCV\n* NumPy\n \n# Installation\n- The easiest way is to install it with pip:\n\n```bash\npip install cap_from_youtube\n```\n- You can also install it from GitHub:\n\n```bash\npip install git+https://github.com/ibaiGorordo/cap_from_youtube\n```\n\n# Usage\n\n## cap_from_youtube()\n- `cap_from_youtube()` is the main function to obtain a video capture from a YouTube video URL. \n- It requires the video URL as input and returns a `cv2.VideoCapture` object.\n- By default, it returns the video with the highest resolution available.\n- You can specify the resolution you want to get with the `resolution` parameter.\n  - Resolution examples: '144p', '240p', '360p', '480p', '720p', '1080p', '1440p', '2160p', 'best'\n- Example:\n\n```python\nimport cv2\nfrom cap_from_youtube import cap_from_youtube\n\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\ncap = cap_from_youtube(youtube_url, '1440p60')\n\ncv2.namedWindow('video', cv2.WINDOW_NORMAL)\nwhile True:\n    ret, frame = cap.read()\n    if not ret:\n        break\n    cv2.imshow('video', frame)\n    if cv2.waitKey(1) & 0xFF == ord('q'):\n        break\n```\n\n## list_video_streams()\n- You can also use the `list_video_streams()` function to get the list of available video streams.\n- It requires the video URL as input and returns two values: \n  - streams: a list of VideoStream with the information of the available video streams.\n  - resolutions: a NumPy array with the available resolutions.\n- Example:\n```python\nfrom cap_from_youtube import list_video_streams\n\nyoutube_url = 'https://youtu.be/LXb3EKWsInQ'\nstreams, resolutions = list_video_streams(youtube_url)\n\nfor stream in streams:\n    print(stream)\n```\n \n# References\n- pafy: https://github.com/mps-youtube/pafy\n- yt-dlp: https://github.com/yt-dlp/yt-dlp\n- imread_from_url: https://github.com/Kazuhito00/imread_from_url\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Get an OpenCV video capture from an YouTube video URL",
    "version": "0.0.10",
    "project_urls": {
        "Homepage": "https://github.com/ibaiGorordo/cap_from_youtube"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c9b742d986c7a5950b139f2f841cc2827778f0e93cc585d64fef5e263469895",
                "md5": "8a2f327fbdcc14460c0bb55fcca27f00",
                "sha256": "60c0df8cd31cb2c79a3fdc359efc8e022df8d4f5559026de88f5fb7e4d91c527"
            },
            "downloads": -1,
            "filename": "cap_from_youtube-0.0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8a2f327fbdcc14460c0bb55fcca27f00",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3600,
            "upload_time": "2023-08-09T08:36:12",
            "upload_time_iso_8601": "2023-08-09T08:36:12.698804Z",
            "url": "https://files.pythonhosted.org/packages/0c/9b/742d986c7a5950b139f2f841cc2827778f0e93cc585d64fef5e263469895/cap_from_youtube-0.0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd6c560c96bdda56163c9bbfa46c77c3e50916d13a46c14dd9a5f46448aa09d9",
                "md5": "e932f70c10329f654135c8fa33c6b899",
                "sha256": "7e25b6fc55ac0569d043d289222714e9c2520ec1d27d8fccfda35662e800d785"
            },
            "downloads": -1,
            "filename": "cap_from_youtube-0.0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "e932f70c10329f654135c8fa33c6b899",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3261,
            "upload_time": "2023-08-09T08:36:14",
            "upload_time_iso_8601": "2023-08-09T08:36:14.302142Z",
            "url": "https://files.pythonhosted.org/packages/fd/6c/560c96bdda56163c9bbfa46c77c3e50916d13a46c14dd9a5f46448aa09d9/cap_from_youtube-0.0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-09 08:36:14",
    "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.10951s