Skip to main content

A simple library and/or CLI tool for downloading a past Twitch.tv broadcast's (VOD) chat comments.

Project description

pyvod-chat

GitHub release (latest by date) PyPI PyPI - Downloads Downloads

Get the stream chat for a given Twitch VOD.

pyvod can be used within your own programs via pip install pyvod-chat. See Usages for how to use it.

pyvod can additionally be used as a CLI (command line interface) script (cmd/terminal). See Usages for more information.

See the documentation section for more information on the available methods.

Requirements

Also see requirements.txt.

If you want to run pyvod from a command line interface, you can install the required packages via pip install -r requirements.txt.

Optional

  • an optional .env file containing your own Twitch.tv Client-ID insde the root directory of your project (or if used via the CLI inside the pyvod-chat directory).

    Add the env-variable inside the .env file like so: twitch-client-id="CLIENT_ID"

A 'Client-ID' (public) is NOT the same as a 'Client-Secret', the latter which is not used here.

Note: if you don't specify a Client-ID, a default Client-ID will be used.

Installation (PyPI)

Available on PyPI.

pip install pyvod-chat

Usage

Note: many comments == taking quite a while. With some barebone testing, around 130.000 comments can take up to roughly 12-ish minutes (around 2400 requests in total, 200-ish per minute).

This is a result of how the Twitch API (v5) is providing the comments (each request comes with a _next param which its value HAS to be used in the next request to fetch the correct next comments), the more comments there are in the VOD, the more requests we have to make, which in turn takes more time.

Currently trying multithreading/multiprocessing out, to see if it is possible to keep the "state" steady and speeding things up.

1. within your own program

import pyvod  # or -> from pyvod import VOD

vod_id = "111111111"
vod = pyvod.VOD(vod_id=vod_id)  # VOD instance, the main entry point

vodchat = vod.get_vodchat()  # get a VODChat instance, contains the VOD chat

# fetches the comments from the VOD
# this returns a list containing VODSimpleComment (NamedTuple) objects,
# which only contain the 'name', 'timestamp', when the message has been posted and
# the 'message' content of a comment
comments = vodchat.get_comments()

# if the raw comment data (JSON) is needed, simply fetch them like so
# and process the JSON as you need it
raw_comments = vodchat.raw

# since VODSimpleComment objects are NamedTuples
# (can do anything a normal tuple does),
# there are 2 distinct ways to extract their data from the comments list

# 1. by calling the class attributes
for comment in comments:
   name = comment.name
   timestamp = comment.timestamp
   posted_at = comment.posted_at
   message = comment.message

# 2. via simple tuple unpacking
for timestamp, posted_at, name, message in comments:
   # process comment data
   print(timestamp, posted_at, name, message)

# if you want to access the VODChat comments again at a later date,
# but do not want to fetch them again from the API,
# simply use the property attribute like so
comments = vodchat.comments

# if you want to save the extracted comments and the raw JSON, simply do:
vodchat.to_file(dirpath="OPTIONAL\PATH\HERE", save_json=True)  # defaults to the current working directory via `os.getcwd()`

2. as a CLI tool in a terminal/cmd

Download the available GitHub folder by clicking on "Code" in the top right (or simply clone the repository).

Open your terminal and navigate to the root directory of: pyvod-chat

cd pyvod-chat
python -m pyvod --help

-h [--help] shows you the usage and the optional -d [-dir] parameter allows you to specify your own output directory. This defaults to the current working directory, i.e. wherever you saved the program: ..\..\pyvod-chat

A full command line could be structured like so:

python -m pyvod -v 979245105 -d C:\Users\MyUser\Documents\Scripts

Documentation

See the documentation here on GitHub: documentation page.

Changelog

See the changelog here on GitHub: changelog page.

License

MIT License. See LICENSE.

Task list

  • Potentially implement multithreading/multiprocessing for the comment fetch requests

  • Make documentation available via readthedocs.

  • Future features like filtering and sorting the comments by user, message (contains X word, etc.) and more

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvod-chat-0.2.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

pyvod_chat-0.2.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file pyvod-chat-0.2.1.tar.gz.

File metadata

  • Download URL: pyvod-chat-0.2.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pyvod-chat-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fe4e91274a1a34cf5a51f5d2f8e19a881064967584e66bafd94d6fc90826475b
MD5 94a82b3e695a63b4c17a430e66211677
BLAKE2b-256 c2c3ce622d805bd7dc087b9ae1c87ddbdcb80cb5e3e004c4d35b3feb8ba4c979

See more details on using hashes here.

File details

Details for the file pyvod_chat-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyvod_chat-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pyvod_chat-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd46d74a12f3bcb69a552798b5d0a81cbbdd521fc443724b2c1a09c8321ed237
MD5 e92bc9afeed3ded9e694add1461bb57e
BLAKE2b-256 de9a75379d80c649ed849edcb37a18041308801c56efef5abae4a4149a14cf8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page