pafy


Namepafy JSON
Version 0.5.4 PyPI version JSON
download
home_pagehttp://np1.github.io/pafy/
SummaryRetrieve YouTube content and metadata
upload_time2018-02-11 21:19:42
maintainer
docs_urlhttp://pythonhosted.org/pafy/
authornp1
requires_python
licenseLGPLv3
keywords pafy
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

            {
    "maintainer": "", 
    "docs_url": "http://pythonhosted.org/pafy/", 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "pafy", 
    "upload_time": "2018-02-11 21:19:42", 
    "author": "np1", 
    "home_page": "http://np1.github.io/pafy/", 
    "download_url": "https://pypi.python.org/packages/41/cb/ec840c79942fb0788982963b61a361ecd10e4e58ad3dcaef4f0e809ce2fe/pafy-0.5.4.tar.gz", 
    "platform": "", 
    "version": "0.5.4", 
    "cheesecake_documentation_id": null, 
    "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", 
    "lcname": "pafy", 
    "bugtrack_url": "", 
    "github": false, 
    "name": "pafy", 
    "license": "LGPLv3", 
    "summary": "Retrieve YouTube content and metadata", 
    "split_keywords": [
        "pafy"
    ], 
    "author_email": "np1nagev@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-02-11T21:20:35", 
            "comment_text": "", 
            "python_version": "3.6", 
            "url": "https://pypi.python.org/packages/b0/e8/3516f761558525b00d3eaf73744eed5c267db20650b7b660674547e3e506/pafy-0.5.4-py2.py3-none-any.whl", 
            "md5_digest": "a29cf9c3657f2fe143c068f0e001e2db", 
            "downloads": 0, 
            "filename": "pafy-0.5.4-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "b0/e8/3516f761558525b00d3eaf73744eed5c267db20650b7b660674547e3e506/pafy-0.5.4-py2.py3-none-any.whl", 
            "size": 35281
        }, 
        {
            "has_sig": false, 
            "upload_time": "2018-02-11T21:19:42", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/41/cb/ec840c79942fb0788982963b61a361ecd10e4e58ad3dcaef4f0e809ce2fe/pafy-0.5.4.tar.gz", 
            "md5_digest": "092930504c7e4fcea30b7446fa1878c7", 
            "downloads": 0, 
            "filename": "pafy-0.5.4.tar.gz", 
            "packagetype": "sdist", 
            "path": "41/cb/ec840c79942fb0788982963b61a361ecd10e4e58ad3dcaef4f0e809ce2fe/pafy-0.5.4.tar.gz", 
            "size": 27393
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}
        
np1