Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anyesh/youtube

:mortar_board: A simple and fast Python module to retrieve data from YouTube.
https://github.com/anyesh/youtube

Last synced: 3 days ago
JSON representation

:mortar_board: A simple and fast Python module to retrieve data from YouTube.

Awesome Lists containing this project

README

        

# youtube

[![Python](https://img.shields.io/badge/Python-3.6-blue.svg)](https://docs.python.org/3/whatsnew/3.6.html)
[![Travis CI](https://travis-ci.org/Fallmay/youtube.svg?branch=master)](https://travis-ci.org/Fallmay/youtube)

A simple and fast Python module to retrieve data from YouTube.

- Does not use third-party dependencies and YouTube Data API.
- Uses a pool of threads to execute asynchronously requests.
- Can receive data from multiple videos at once.

## Installation

Install from source:

```
$ git clone https://github.com/Fallmay/youtube.git
$ cd youtube
$ python setup.py install
```

You can also use `pip`:

```
$ pip install --upgrade pip setuptools
$ pip install https://github.com/Fallmay/youtube/archive/master.tar.gz
```

## Usage

Get information about a video:

```python
import youtube

video = youtube.Video('https://www.youtube.com/watch?v=nKIu9yen5nc')
print(video.title, video.duration, video.date, sep='\n')
# What Most Schools Don't Teach
# 05:44
# 2013-02-26

print(video.description)
# Learn about a new "superpower" that isn't being taught in 90% of US schools ...

print(video.statistics)
# {'likes': '115618', 'dislikes': '3549', 'rating': '4.88', 'views': '14134818'}

print(video.channel)
# {'title': 'Code.org', 'subscribers': '203K', ...

print(video.streams['adaptive']['audio'])
# {'140': {'bitrate': '128056', 'type': 'audio/mp4', ...

print(video.streams['adaptive']['video'])
# {'137': {'quality': '1080p', 'bitrate': '4276030', 'fps': '24', ...

print(video.streams['multiplexed'])
# {'22': {'quality': 'hd720', 'type': 'video/mp4', ...

if 'English' in video.captions:
print(video.captions['English'])
# {'languageCode': 'en', 'url': ...
```

Serialize information about your favorite videos to a JSON formatted string:

```python
import json
import youtube

favorite = ['nKIu9yen5nc', 'n_KghQP86Sw', 'kccUxGDsMAQ', 'QQmFyybzon0',
'U6hkOAnFJxM', 'qDbsiVWA2Ag', '6mbFO0ZLMW8']

data = youtube.load(favorite, video=True)
for _identifier, _data in data.items():
video = youtube.Video(identifier=_identifier, data=_data)
print(json.dumps(video.__dict__))

# {"title": "What Most Schools Don't Teach", ...
# {"title": "Internet - Understanding Technology - by CS50 at Harvard", ...
# {"title": "Multimedia - Understanding Technology - by CS50 at Harvard", ...
# {"title": "Security - Understanding Technology - by CS50 at Harvard", ...
# {"title": "Web Development - Understanding Technology - by CS50 at Harvard", ...
# {"title": "Programming - Understanding Technology - by CS50 at Harvard", ...
# {"title": "Hardware - Understanding Technology - by CS50 at Harvard", ...
```

Please see [JSON output example](docs/video.json).