pafy


Namepafy JSON
Version 0.5.5 PyPI version JSON
download
home_pagehttp://np1.github.io/pafy/
SummaryRetrieve YouTube content and metadata
upload_time2019-11-22 07:14:14
maintainer
docs_urlhttps://pythonhosted.org/pafy/
authornp1
requires_python
licenseLGPLv3
keywords pafy api youtube youtube download video
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/Pafy.svg
    :target: https://pypi.python.org/pypi/pafy
.. image:: https://img.shields.io/pypi/dm/Pafy.svg
    :target: https://pypi.python.org/pypi/pafy
.. image:: https://img.shields.io/coveralls/np1/pafy/develop.svg
    :target: https://coveralls.io/r/np1/pafy?branch=develop
.. image:: https://landscape.io/github/mps-youtube/pafy/develop/landscape.svg
    :target: https://landscape.io/github/mps-youtube/pafy/develop
    :alt: Code Health
.. image:: https://travis-ci.org/mps-youtube/pafy.svg?branch=develop
    :target: https://travis-ci.org/mps-youtube/pafy
.. image:: https://img.shields.io/pypi/wheel/Pafy.svg
    :target: http://pythonwheels.com/
    :alt: Wheel Status

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

Full documentation is available at http://pythonhosted.org/pafy

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

IRC
---

The mps-youtube irc channel (`#mps-youtube` on Freenode) can be used for discussion of pafy.



            

Raw data

            {
    "_id": null,
    "home_page": "http://np1.github.io/pafy/",
    "name": "pafy",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/pafy/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pafy,API,YouTube,youtube,download,video",
    "author": "np1",
    "author_email": "np1nagev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/02/b70f4d2ad64bbc7d2a00018c6545d9b9039208553358534e73e6dd5bbaf6/pafy-0.5.5.tar.gz",
    "platform": "",
    "description": ".. image:: https://img.shields.io/pypi/v/Pafy.svg\n    :target: https://pypi.python.org/pypi/pafy\n.. image:: https://img.shields.io/pypi/dm/Pafy.svg\n    :target: https://pypi.python.org/pypi/pafy\n.. image:: https://img.shields.io/coveralls/np1/pafy/develop.svg\n    :target: https://coveralls.io/r/np1/pafy?branch=develop\n.. image:: https://landscape.io/github/mps-youtube/pafy/develop/landscape.svg\n    :target: https://landscape.io/github/mps-youtube/pafy/develop\n    :alt: Code Health\n.. image:: https://travis-ci.org/mps-youtube/pafy.svg?branch=develop\n    :target: https://travis-ci.org/mps-youtube/pafy\n.. image:: https://img.shields.io/pypi/wheel/Pafy.svg\n    :target: http://pythonwheels.com/\n    :alt: Wheel Status\n\nFeatures\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\nFull documentation is available at http://pythonhosted.org/pafy\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\nIRC\n---\n\nThe mps-youtube irc channel (`#mps-youtube` on Freenode) can be used for discussion of pafy.\n\n\n",
    "bugtrack_url": null,
    "license": "LGPLv3",
    "summary": "Retrieve YouTube content and metadata",
    "version": "0.5.5",
    "split_keywords": [
        "pafy",
        "api",
        "youtube",
        "youtube",
        "download",
        "video"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7469829919eeadff695338f98fa12bb99e45490761a2010c8d688d88b6df194a",
                "md5": "dc36a7f13ac37940047412de733f623f",
                "sha256": "769e35aa6988686d47fa2ab235d15c9952c7873c470f6a6b05cf6bcd93e62515"
            },
            "downloads": -1,
            "filename": "pafy-0.5.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dc36a7f13ac37940047412de733f623f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 35503,
            "upload_time": "2019-11-22T07:14:11",
            "upload_time_iso_8601": "2019-11-22T07:14:11.592089Z",
            "url": "https://files.pythonhosted.org/packages/74/69/829919eeadff695338f98fa12bb99e45490761a2010c8d688d88b6df194a/pafy-0.5.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e02b70f4d2ad64bbc7d2a00018c6545d9b9039208553358534e73e6dd5bbaf6",
                "md5": "01430bb4876aec3b648b2f52c5ee7bd6",
                "sha256": "364f1d1312c89582d97dc7225cf6858cde27cb11dfd64a9c2bab1a2f32133b1e"
            },
            "downloads": -1,
            "filename": "pafy-0.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "01430bb4876aec3b648b2f52c5ee7bd6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 29769,
            "upload_time": "2019-11-22T07:14:14",
            "upload_time_iso_8601": "2019-11-22T07:14:14.122486Z",
            "url": "https://files.pythonhosted.org/packages/7e/02/b70f4d2ad64bbc7d2a00018c6545d9b9039208553358534e73e6dd5bbaf6/pafy-0.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-11-22 07:14:14",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pafy"
}
        
np1
Elapsed time: 0.03080s