youtubepafy


Nameyoutubepafy JSON
Version 0.5.5 PyPI version JSON
download
home_pagehttps://github.com/hetsaraiya/youtubepafy
SummaryRetrieve YouTube content and metadata
upload_time2024-11-09 19:04:32
maintainerNone
docs_urlNone
authorHet Saraiya
requires_pythonNone
licenseLGPLv3
keywords youtubepafy api youtube youtube download video het saraiya hetsaraiya
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Features
--------

- Retreive metadata such as viewcount, duration, rating, author, thumbnail, keywords
- Download video or audio at requested resolution / bitrate / format / filesize
- Command line tool (ytdl) for downloading directly from the command line
- Retrieve the URL to stream the video in a player such as vlc or mplayer
- Works with age-restricted videos and non-embeddable videos
- Small, standalone, single importable module file (pafy.py)
- Select highest quality stream for download or streaming
- Download video only (no audio) in m4v or webm format
- Download audio only (no video) in ogg or m4a format
- Retreive playlists and playlist metadata
- Works with Python 2.6+ and 3.3+
- Optionally depends on youtube-dl (recommended; more stable)


Documentation
-------------

To be announced.

Usage Examples
--------------

Here is how to use the module in your own python code.  For command line tool
(ytdl) instructions, see further below

.. code-block:: pycon

    >>> import pafy

create a video instance from a YouTube url:

.. code-block:: pycon

    >>> url = "https://www.youtube.com/watch?v=bMt47wvK6u0"
    >>> video = pafy.new(url)

get certain attributes:

.. code-block:: pycon
    
    >>> video.title
    'Richard Jones: Introduction to game programming - PyCon 2014'

    >>> video.rating
    5.0

    >>> video.viewcount, video.author, video.length
    (1916, 'PyCon 2014', 10394)

    >>> video.duration, video.likes, video.dislikes
    ('02:53:14', 25, 0)

    >>> print(video.description)
    Speaker: Richard Jones

    This tutorial will walk the attendees through development of a simple game using PyGame with time left over for some experimentation and exploration of different types of games.

    Slides can be found at: https://speakerdeck.com/pycon2014 and https://github.com/PyCon/2014-slides


list available streams for a video:

.. code-block:: pycon

    >>> streams = video.streams
    >>> for s in streams:
    ...     print(s)
    ...
    normal:mp4@1280x720
    normal:webm@640x360
    normal:mp4@640x360
    normal:flv@320x240
    normal:3gp@320x240
    normal:3gp@176x144


show all formats, file-sizes and their download url:

.. code-block:: pycon

    >>> for s in streams:
    ...    print(s.resolution, s.extension, s.get_filesize(), s.url)
    ...
    1280x720 mp4 2421958510 https://r1---sn-aiglln7e.googlevideo.com/videoplayba[...]
    640x360 webm 547015732 https://r1---sn-aiglln7e.googlevideo.com/videoplaybac[...]
    640x360 mp4 470655850 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]
    320x240 flv 345455674 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]
    320x240 3gp 208603447 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]
    176x144 3gp 60905732 https://r1---sn-aiglln7e.googlevideo.com/videoplayback?[...]


get best resolution regardless of file format:

.. code-block:: pycon

    >>> best = video.getbest()
    >>> best.resolution, best.extension
    ('1280x720', 'mp4')


get best resolution for a particular file format:
(mp4, webm, flv or 3gp)

.. code-block:: pycon

    >>> best = video.getbest(preftype="webm")
    >>> best.resolution, best.extension
    ('640x360', 'webm')

get url, for download or streaming in mplayer / vlc etc:

.. code-block:: pycon
    
    >>> best.url
    'http://r12---sn-aig7kner.c.youtube.com/videoplayback?expire=1369...

Download video and show progress:

.. code-block:: pycon

    >>> best.download(quiet=False)
    3,734,976 Bytes [0.20%] received. Rate: [ 719 KB/s].  ETA: [3284 secs]

Download video, use specific directory and/or filename:

.. code-block:: pycon

    >>> filename = best.download(filepath="/tmp/")

    >>> filename = best.download(filepath="/tmp/Game." + best.extension)

Get audio-only streams (m4a and/or ogg vorbis):

.. code-block:: pycon

    >>> audiostreams = video.audiostreams
    >>> for a in audiostreams:
    ...     print(a.bitrate, a.extension, a.get_filesize())
    ...
    256k m4a 331379079
    192k ogg 172524223
    128k m4a 166863001
    128k ogg 108981120
    48k m4a 62700449


Download the 2nd audio stream from the above list:

.. code-block:: pycon

    >>> audiostreams[1].download()

Get the best quality audio stream:

.. code-block:: pycon

    >>> bestaudio = video.getbestaudio()
    >>> bestaudio.bitrate
    '256'

Download the best quality audio file:

.. code-block:: pycon

    >>> bestaudio.download()

show all media types for a video (video+audio, video-only and audio-only):

.. code-block:: pycon

    >>> allstreams = video.allstreams
    >>> for s in allstreams:
    ...     print(s.mediatype, s.extension, s.quality)
    ...

    normal mp4 1280x720
    normal webm 640x360
    normal mp4 640x360
    normal flv 320x240
    normal 3gp 320x240
    normal 3gp 176x144
    video m4v 1280x720
    video webm 1280x720
    video m4v 854x480
    video webm 854x480
    video m4v 640x360
    video webm 640x360
    video m4v 426x240
    video webm 426x240
    video m4v 256x144
    video webm 256x144
    audio m4a 256k
    audio ogg 192k
    audio m4a 128k
    audio ogg 128k
    audio m4a 48k


Installation
------------

pafy can be installed using `pip <http://www.pip-installer.org>`_:

.. code-block:: bash

    $ [sudo] pip install pafy

or use a `virtualenv <http://virtualenv.org>`_ if you don't want to install it system-wide:

.. code-block:: bash

    $ virtualenv venv
    $ source venv/bin/activate
    $ pip install pafy


Command Line Tool (ytdl) Usage
------------------------------


.. code-block:: bash

    usage: ytdl [-h] [-i] [-s]
                [-t {audio,video,normal,all} [{audio,video,normal,all} ...]]
                [-n N] [-b] [-a]
                url

    YouTube Download Tool

    positional arguments:
      url                   YouTube video URL to download

    optional arguments:
      -h, --help            show this help message and exit
      -i                    Display vid info
      -s                    Display available streams
      -t {audio,video,normal,all} [{audio,video,normal,all} ...]
                            Stream types to display
      -n N                  Specify stream to download by stream number (use -s to
                            list available streams)
      -b                    Download the best quality video (ignores -n)
      -a                    Download the best quality audio (ignores -n)


ytdl Examples
-------------

Download best available resolution (-b):

.. code-block:: bash

    $ ytdl -b "http://www.youtube.com/watch?v=cyMHZVT91Dw"

Download best available audio stream (-a)
(note; the full url is not required, just the video id will suffice):

.. code-block:: bash

    $ ytdl -a cyMHZVT91Dw


get video info (-i):

.. code-block:: bash

    $ ytdl -i cyMHZVT91Dw

list available dowload streams:

.. code-block:: bash

    $ ytdl cyMHZVT91Dw
 
    Stream Type    Format Quality         Size            
    ------ ----    ------ -------         ----            
    1      normal  webm   [640x360]       33 MB
    2      normal  mp4    [640x360]       23 MB
    3      normal  flv    [320x240]       14 MB
    4      normal  3gp    [320x240]        9 MB
    5      normal  3gp    [176x144]        3 MB
    6      audio   m4a    [48k]            2 MB
    7      audio   m4a    [128k]           5 MB
    8      audio   ogg    [128k]           5 MB
    9      audio   ogg    [192k]           7 MB
    10     audio   m4a    [256k]          10 MB

 
Download mp4 640x360 (ie. stream number 2):

.. code-block:: bash

    $ ytdl -n2 cyMHZVT91Dw

Download m4a audio stream at 256k bitrate:

.. code-block:: bash

    $ ytdl -n10 cyMHZVT91Dw

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hetsaraiya/youtubepafy",
    "name": "youtubepafy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "youtubepafy, API, YouTube, youtube, download, video, Het Saraiya, hetsaraiya",
    "author": "Het Saraiya",
    "author_email": "hetsaraiya06@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/23/15/ec564e525c29755745b9ca2ee307088bd255bb363204d5a3222d41c9cb3c/youtubepafy-0.5.5.tar.gz",
    "platform": null,
    "description": "Features\n--------\n\n- Retreive metadata such as viewcount, duration, rating, author, thumbnail, keywords\n- Download video or audio at requested resolution / bitrate / format / filesize\n- Command line tool (ytdl) for downloading directly from the command line\n- Retrieve the URL to stream the video in a player such as vlc or mplayer\n- Works with age-restricted videos and non-embeddable videos\n- Small, standalone, single importable module file (pafy.py)\n- Select highest quality stream for download or streaming\n- Download video only (no audio) in m4v or webm format\n- Download audio only (no video) in ogg or m4a format\n- Retreive playlists and playlist metadata\n- Works with Python 2.6+ and 3.3+\n- Optionally depends on youtube-dl (recommended; more stable)\n\n\nDocumentation\n-------------\n\nTo be announced.\n\nUsage Examples\n--------------\n\nHere is how to use the module in your own python code.  For command line tool\n(ytdl) instructions, see further below\n\n.. code-block:: pycon\n\n    >>> import pafy\n\ncreate a video instance from a YouTube url:\n\n.. code-block:: pycon\n\n    >>> url = \"https://www.youtube.com/watch?v=bMt47wvK6u0\"\n    >>> video = pafy.new(url)\n\nget certain attributes:\n\n.. code-block:: pycon\n    \n    >>> video.title\n    'Richard Jones: Introduction to game programming - PyCon 2014'\n\n    >>> video.rating\n    5.0\n\n    >>> video.viewcount, video.author, video.length\n    (1916, 'PyCon 2014', 10394)\n\n    >>> video.duration, video.likes, video.dislikes\n    ('02:53:14', 25, 0)\n\n    >>> print(video.description)\n    Speaker: Richard Jones\n\n    This tutorial will walk the attendees through development of a simple game using PyGame with time left over for some experimentation and exploration of different types of games.\n\n    Slides can be found at: https://speakerdeck.com/pycon2014 and https://github.com/PyCon/2014-slides\n\n\nlist available streams for a video:\n\n.. code-block:: pycon\n\n    >>> streams = video.streams\n    >>> for s in streams:\n    ...     print(s)\n    ...\n    normal:mp4@1280x720\n    normal:webm@640x360\n    normal:mp4@640x360\n    normal:flv@320x240\n    normal:3gp@320x240\n    normal:3gp@176x144\n\n\nshow all formats, file-sizes and their download url:\n\n.. code-block:: pycon\n\n    >>> for s in streams:\n    ...    print(s.resolution, s.extension, s.get_filesize(), s.url)\n    ...\n    1280x720 mp4 2421958510 https://r1---sn-aiglln7e.googlevideo.com/videoplayba[...]\n    640x360 webm 547015732 https://r1---sn-aiglln7e.googlevideo.com/videoplaybac[...]\n    640x360 mp4 470655850 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]\n    320x240 flv 345455674 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]\n    320x240 3gp 208603447 https://r1---sn-aiglln7e.googlevideo.com/videoplayback[...]\n    176x144 3gp 60905732 https://r1---sn-aiglln7e.googlevideo.com/videoplayback?[...]\n\n\nget best resolution regardless of file format:\n\n.. code-block:: pycon\n\n    >>> best = video.getbest()\n    >>> best.resolution, best.extension\n    ('1280x720', 'mp4')\n\n\nget best resolution for a particular file format:\n(mp4, webm, flv or 3gp)\n\n.. code-block:: pycon\n\n    >>> best = video.getbest(preftype=\"webm\")\n    >>> best.resolution, best.extension\n    ('640x360', 'webm')\n\nget url, for download or streaming in mplayer / vlc etc:\n\n.. code-block:: pycon\n    \n    >>> best.url\n    'http://r12---sn-aig7kner.c.youtube.com/videoplayback?expire=1369...\n\nDownload video and show progress:\n\n.. code-block:: pycon\n\n    >>> best.download(quiet=False)\n    3,734,976 Bytes [0.20%] received. Rate: [ 719 KB/s].  ETA: [3284 secs]\n\nDownload video, use specific directory and/or filename:\n\n.. code-block:: pycon\n\n    >>> filename = best.download(filepath=\"/tmp/\")\n\n    >>> filename = best.download(filepath=\"/tmp/Game.\" + best.extension)\n\nGet audio-only streams (m4a and/or ogg vorbis):\n\n.. code-block:: pycon\n\n    >>> audiostreams = video.audiostreams\n    >>> for a in audiostreams:\n    ...     print(a.bitrate, a.extension, a.get_filesize())\n    ...\n    256k m4a 331379079\n    192k ogg 172524223\n    128k m4a 166863001\n    128k ogg 108981120\n    48k m4a 62700449\n\n\nDownload the 2nd audio stream from the above list:\n\n.. code-block:: pycon\n\n    >>> audiostreams[1].download()\n\nGet the best quality audio stream:\n\n.. code-block:: pycon\n\n    >>> bestaudio = video.getbestaudio()\n    >>> bestaudio.bitrate\n    '256'\n\nDownload the best quality audio file:\n\n.. code-block:: pycon\n\n    >>> bestaudio.download()\n\nshow all media types for a video (video+audio, video-only and audio-only):\n\n.. code-block:: pycon\n\n    >>> allstreams = video.allstreams\n    >>> for s in allstreams:\n    ...     print(s.mediatype, s.extension, s.quality)\n    ...\n\n    normal mp4 1280x720\n    normal webm 640x360\n    normal mp4 640x360\n    normal flv 320x240\n    normal 3gp 320x240\n    normal 3gp 176x144\n    video m4v 1280x720\n    video webm 1280x720\n    video m4v 854x480\n    video webm 854x480\n    video m4v 640x360\n    video webm 640x360\n    video m4v 426x240\n    video webm 426x240\n    video m4v 256x144\n    video webm 256x144\n    audio m4a 256k\n    audio ogg 192k\n    audio m4a 128k\n    audio ogg 128k\n    audio m4a 48k\n\n\nInstallation\n------------\n\npafy can be installed using `pip <http://www.pip-installer.org>`_:\n\n.. code-block:: bash\n\n    $ [sudo] pip install pafy\n\nor use a `virtualenv <http://virtualenv.org>`_ if you don't want to install it system-wide:\n\n.. code-block:: bash\n\n    $ virtualenv venv\n    $ source venv/bin/activate\n    $ pip install pafy\n\n\nCommand Line Tool (ytdl) Usage\n------------------------------\n\n\n.. code-block:: bash\n\n    usage: ytdl [-h] [-i] [-s]\n                [-t {audio,video,normal,all} [{audio,video,normal,all} ...]]\n                [-n N] [-b] [-a]\n                url\n\n    YouTube Download Tool\n\n    positional arguments:\n      url                   YouTube video URL to download\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -i                    Display vid info\n      -s                    Display available streams\n      -t {audio,video,normal,all} [{audio,video,normal,all} ...]\n                            Stream types to display\n      -n N                  Specify stream to download by stream number (use -s to\n                            list available streams)\n      -b                    Download the best quality video (ignores -n)\n      -a                    Download the best quality audio (ignores -n)\n\n\nytdl Examples\n-------------\n\nDownload best available resolution (-b):\n\n.. code-block:: bash\n\n    $ ytdl -b \"http://www.youtube.com/watch?v=cyMHZVT91Dw\"\n\nDownload best available audio stream (-a)\n(note; the full url is not required, just the video id will suffice):\n\n.. code-block:: bash\n\n    $ ytdl -a cyMHZVT91Dw\n\n\nget video info (-i):\n\n.. code-block:: bash\n\n    $ ytdl -i cyMHZVT91Dw\n\nlist available dowload streams:\n\n.. code-block:: bash\n\n    $ ytdl cyMHZVT91Dw\n \n    Stream Type    Format Quality         Size            \n    ------ ----    ------ -------         ----            \n    1      normal  webm   [640x360]       33 MB\n    2      normal  mp4    [640x360]       23 MB\n    3      normal  flv    [320x240]       14 MB\n    4      normal  3gp    [320x240]        9 MB\n    5      normal  3gp    [176x144]        3 MB\n    6      audio   m4a    [48k]            2 MB\n    7      audio   m4a    [128k]           5 MB\n    8      audio   ogg    [128k]           5 MB\n    9      audio   ogg    [192k]           7 MB\n    10     audio   m4a    [256k]          10 MB\n\n \nDownload mp4 640x360 (ie. stream number 2):\n\n.. code-block:: bash\n\n    $ ytdl -n2 cyMHZVT91Dw\n\nDownload m4a audio stream at 256k bitrate:\n\n.. code-block:: bash\n\n    $ ytdl -n10 cyMHZVT91Dw\n",
    "bugtrack_url": null,
    "license": "LGPLv3",
    "summary": "Retrieve YouTube content and metadata",
    "version": "0.5.5",
    "project_urls": {
        "Download": "https://github.com/hetsaraiya/youtubepafy/tags",
        "Homepage": "https://github.com/hetsaraiya/youtubepafy"
    },
    "split_keywords": [
        "youtubepafy",
        " api",
        " youtube",
        " youtube",
        " download",
        " video",
        " het saraiya",
        " hetsaraiya"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "accbbe375c31eab066f6568a6c19f1c503e1001051218b8d0bd3f93d7703f886",
                "md5": "ed88ed3bd36bb9e6b940757b4cbf9868",
                "sha256": "5452acdc5c9780ae328ceb1e8b0d9b5c3ebdcfd1e6ed4764a0b32966be355e89"
            },
            "downloads": -1,
            "filename": "youtubepafy-0.5.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ed88ed3bd36bb9e6b940757b4cbf9868",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 33004,
            "upload_time": "2024-11-09T19:04:30",
            "upload_time_iso_8601": "2024-11-09T19:04:30.432971Z",
            "url": "https://files.pythonhosted.org/packages/ac/cb/be375c31eab066f6568a6c19f1c503e1001051218b8d0bd3f93d7703f886/youtubepafy-0.5.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2315ec564e525c29755745b9ca2ee307088bd255bb363204d5a3222d41c9cb3c",
                "md5": "6a9e049829703f89abc337f65cdecadc",
                "sha256": "5051c3ca13fdbb887bd2477bf3c8e446a0ce89e61259ba3f69d38ade3778279d"
            },
            "downloads": -1,
            "filename": "youtubepafy-0.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "6a9e049829703f89abc337f65cdecadc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 31120,
            "upload_time": "2024-11-09T19:04:32",
            "upload_time_iso_8601": "2024-11-09T19:04:32.277157Z",
            "url": "https://files.pythonhosted.org/packages/23/15/ec564e525c29755745b9ca2ee307088bd255bb363204d5a3222d41c9cb3c/youtubepafy-0.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-09 19:04:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hetsaraiya",
    "github_project": "youtubepafy",
    "github_not_found": true,
    "lcname": "youtubepafy"
}
        
Elapsed time: 1.39777s