1
0
Fork
You've already forked ytxt
0
📹 Convert YouTube video subtitles to clean text! Downloads and processes .vtt files into readable .txt.
  • Python 100%
2023年04月17日 21:05:27 +02:00
img Sucessfully updated the font in agg.gif 2023年01月28日 17:19:07 +01:00
samples Added samples 2023年01月28日 17:40:55 +01:00
src Small change to dest='url' in argument_parsing 2023年01月28日 11:56:42 +01:00
tests Finished testing SubTxt class 2023年01月22日 00:05:58 +01:00
.gitignore Deleted ignoring txt and vtt files 2023年01月28日 17:41:26 +01:00
LICENSE God... it is working again 2022年12月17日 14:23:05 +01:00
poetry.lock Updated depedencies 2023年04月11日 23:44:29 +02:00
pyproject.toml Version 0.1.1 2023年01月28日 12:41:57 +01:00
README.md Changed PowerShell commands and capatalize the title 2023年01月28日 18:15:46 +01:00

ytxt

YTXT

asciinemagifgenerator

This module downloads subtitles in .vtt file format, then it opens it as a regular .txt file, removes unneeded stuff and finally saves it to a clean looking .txt file with the same name.

Table of contents

  1. Main features
  2. Requirements
  3. Installation
  4. Troubleshooting
  5. Usage with examples
  6. Contributing
  7. License

Main features

  • Downloads .vtt subtitle files and saves them to a clean looking .txt file with the same name as the subtitle file.
  • Easy to customise using flags. (e.g. easy selection of different subtitle languages)
  • Easy to use command line interface thanks to argparse.

To understand how it works, see the samples folder.

Requirements

For installation

python-pip - pip is the package installer for Python. You can use it to install packages from the Python Package Index and other indexes.

For building

python-poetry - Python packaging and dependency management made easy.

Installing dependencies

poetry install

Installing dependencies

poetry install

Activating the virtual environment

poetry shell

Deactivating the virtual environment leaving the shell

exit

or CTRL + D

Deactivate the virtual environment without leaving the shell

deactivate

Update dependencies (in the same folder with pyproject.toml and poetry.lock)

poetry update

For more commands, see Python Poetry's Basic Usage.

Installation

Locally:

pip install ytxt-0.1.1-py3-none-any.whl

From PyPi: Coming soon!

Troubleshooting

Windows: pip / ytxt is not recognized as an internal or external command, operable program or batch file.

  1. Make sure that you have installed python-pip and ytxt correctly.
  2. If so, then the problem lies in the Path environment variable, which is needed to see where Python's scripts are installed and how they can be run.

Solution for system's environment variable using admin privileges in PowerShell

[Environment]::SetEnvironmentVariable("Path", "$env:Path;$HOME\AppData\Local\Programs\Python\Python311\Scripts", "Machine")

Where Python311 is your version of Python.

Solution for user's environment variable without admin privileges in PowerShell

[Environment]::SetEnvironmentVariable("Path", "$env:Path;$HOME\AppData\Roaming\Python\Python311\Scripts", "User")

Where Python311 is your version of Python.

GNU/Linux / MacOS: bash: pip / ytxt: command not found

  1. Make sure that you have installed python-pip and ytxt correctly.
  2. If so, MacOS users are doomed and Linux users will figure it out.

Usage with examples

Getting help

Syntax

ytxt -h, --help

Example

ytxt -h

Console output

usage: YTXT - YouTube Video to TXT [-h] [-l [LANG ...]] [-sl] URL [URL ...]
positional arguments:
 URL YouTube video URLs
options:
 -h, --help show this help message and exit
 -l [LANG ...], --languages [LANG ...]
 subtitles languages (default=['en', 'en-GB']) (list)
 -sl, --sub-langs prints all available subtitles languages

List subtitles' languages

Syntax

ytxt URL [URL ...] -sl, --sub-langs

Example

ytxt https://youtu.be/h6fcK_fRYaI -sl

Console output (without automatic caption output)

[youtube] Extracting URL: https://youtu.be/I9hJ_Rux9y0
[youtube] I9hJ_Rux9y0: Downloading webpage
[youtube] I9hJ_Rux9y0: Downloading android player API JSON
[info] Available subtitles for h6fcK_fRYaI:
Language Name Formats
ar Arabic vtt, ttml, srv3, srv2, srv1, json3
az Azerbaijani vtt, ttml, srv3, srv2, srv1, json3
bn Bangla vtt, ttml, srv3, srv2, srv1, json3
be Belarusian vtt, ttml, srv3, srv2, srv1, json3
bs Bosnian vtt, ttml, srv3, srv2, srv1, json3
bg Bulgarian vtt, ttml, srv3, srv2, srv1, json3
my Burmese vtt, ttml, srv3, srv2, srv1, json3
ca Catalan vtt, ttml, srv3, srv2, srv1, json3
zh Chinese vtt, ttml, srv3, srv2, srv1, json3
zh-CN Chinese (China) vtt, ttml, srv3, srv2, srv1, json3
zh-Hans Chinese (Simplified) vtt, ttml, srv3, srv2, srv1, json3
zh-TW Chinese (Taiwan) vtt, ttml, srv3, srv2, srv1, json3
hr Croatian vtt, ttml, srv3, srv2, srv1, json3
cs Czech vtt, ttml, srv3, srv2, srv1, json3
da Danish vtt, ttml, srv3, srv2, srv1, json3
nl Dutch vtt, ttml, srv3, srv2, srv1, json3
en-GB English (United Kingdom) vtt, ttml, srv3, srv2, srv1, json3
eo Esperanto vtt, ttml, srv3, srv2, srv1, json3
et Estonian vtt, ttml, srv3, srv2, srv1, json3
fil Filipino vtt, ttml, srv3, srv2, srv1, json3
fi Finnish vtt, ttml, srv3, srv2, srv1, json3
fr French vtt, ttml, srv3, srv2, srv1, json3
fr-CA French (Canada) vtt, ttml, srv3, srv2, srv1, json3
fr-FR French (France) vtt, ttml, srv3, srv2, srv1, json3
ka Georgian vtt, ttml, srv3, srv2, srv1, json3
de German vtt, ttml, srv3, srv2, srv1, json3
el Greek vtt, ttml, srv3, srv2, srv1, json3
iw Hebrew vtt, ttml, srv3, srv2, srv1, json3
hi Hindi vtt, ttml, srv3, srv2, srv1, json3
hu Hungarian vtt, ttml, srv3, srv2, srv1, json3
id Indonesian vtt, ttml, srv3, srv2, srv1, json3
it Italian vtt, ttml, srv3, srv2, srv1, json3
ja Japanese vtt, ttml, srv3, srv2, srv1, json3
kk Kazakh vtt, ttml, srv3, srv2, srv1, json3
ko Korean vtt, ttml, srv3, srv2, srv1, json3
ku Kurdish vtt, ttml, srv3, srv2, srv1, json3
lv Latvian vtt, ttml, srv3, srv2, srv1, json3
lt Lithuanian vtt, ttml, srv3, srv2, srv1, json3
ms Malay vtt, ttml, srv3, srv2, srv1, json3
mn Mongolian vtt, ttml, srv3, srv2, srv1, json3
no Norwegian vtt, ttml, srv3, srv2, srv1, json3
fa Persian vtt, ttml, srv3, srv2, srv1, json3
pl Polish vtt, ttml, srv3, srv2, srv1, json3
pt Portuguese vtt, ttml, srv3, srv2, srv1, json3
pt-BR Portuguese (Brazil) vtt, ttml, srv3, srv2, srv1, json3
pt-PT Portuguese (Portugal) vtt, ttml, srv3, srv2, srv1, json3
ro Romanian vtt, ttml, srv3, srv2, srv1, json3
ru Russian vtt, ttml, srv3, srv2, srv1, json3
sr Serbian vtt, ttml, srv3, srv2, srv1, json3
sr-Latn Serbian (Latin) vtt, ttml, srv3, srv2, srv1, json3
sk Slovak vtt, ttml, srv3, srv2, srv1, json3
sl Slovenian vtt, ttml, srv3, srv2, srv1, json3
es Spanish vtt, ttml, srv3, srv2, srv1, json3
es-419 Spanish (Latin America) vtt, ttml, srv3, srv2, srv1, json3
es-MX Spanish (Mexico) vtt, ttml, srv3, srv2, srv1, json3
es-ES Spanish (Spain) vtt, ttml, srv3, srv2, srv1, json3
sv Swedish vtt, ttml, srv3, srv2, srv1, json3
ta Tamil vtt, ttml, srv3, srv2, srv1, json3
th Thai vtt, ttml, srv3, srv2, srv1, json3
tr Turkish vtt, ttml, srv3, srv2, srv1, json3
uz Uzbek vtt, ttml, srv3, srv2, srv1, json3
vi Vietnamese vtt, ttml, srv3, srv2, srv1, json3

Basic usage

Syntax

ytxt URL [URL ...]

Example

ytxt https://youtu.be/h6fcK_fRYaI

Console output

[youtube] Extracting URL: https://youtu.be/h6fcK_fRYaI
[youtube] h6fcK_fRYaI: Downloading webpage
[youtube] h6fcK_fRYaI: Downloading android player API JSON
[info] h6fcK_fRYaI: Downloading subtitles: en-GB
[info] h6fcK_fRYaI: Downloading 1 format(s): 248+251
[info] Writing video subtitles to: The Egg - A Short Story [h6fcK_fRYaI].en-GB.vtt
[download] Destination: The Egg - A Short Story [h6fcK_fRYaI].en-GB.vtt
[download] 100% of 9.44KiB in 00:00:00 at 83.42KiB/s
Deleting subtitles heading...
Done 1/5
Deleting subtitles timestamps...
Done 2/5
Deleting subtitles newlines...
Done 3/5
Deleting start and end whitespace...
Done 4/5
Deleting double or more whitespace...
Done. 5/5
Creating the txt file...
Finished saving The Egg - A Short Story [h6fcK_fRYaI].en-GB.txt

See also the 2 files that are stored in your relative path:

The Egg - A Short Story [h6fcK_fRYaI].en-GB.txt
The Egg - A Short Story [h6fcK_fRYaI].en-GB.vtt

Changing default languages

Syntax

ytxt URL [URL ...] -l LANG [LANG ...], --languages LANG [LANG ...]

Example

ytxt https://youtu.be/h6fcK_fRYaI -l de pl

Console output

[youtube] Extracting URL: https://youtu.be/h6fcK_fRYaI
[youtube] h6fcK_fRYaI: Downloading webpage
[youtube] h6fcK_fRYaI: Downloading android player API JSON
[info] h6fcK_fRYaI: Downloading subtitles: de, pl
[info] h6fcK_fRYaI: Downloading 1 format(s): 248+251
Deleting existing file The Egg - A Short Story [h6fcK_fRYaI].de.vtt
[info] Writing video subtitles to: The Egg - A Short Story [h6fcK_fRYaI].de.vtt
[download] Destination: The Egg - A Short Story [h6fcK_fRYaI].de.vtt
[download] 100% of 11.30KiB in 00:00:00 at 98.05KiB/s
Deleting existing file The Egg - A Short Story [h6fcK_fRYaI].pl.vtt
[info] Writing video subtitles to: The Egg - A Short Story [h6fcK_fRYaI].pl.vtt
[download] Destination: The Egg - A Short Story [h6fcK_fRYaI].pl.vtt
[download] 100% of 10.02KiB in 00:00:00 at 85.40KiB/s
Deleting subtitles heading...
Done 1/5
Deleting subtitles timestamps...
Done 2/5
Deleting subtitles newlines...
Done 3/5
Deleting start and end whitespace...
Done 4/5
Deleting double or more whitespace...
Done. 5/5
Creating the txt file...
Finished saving The Egg - A Short Story [h6fcK_fRYaI].de.txt
Deleting subtitles heading...
Done 1/5
Deleting subtitles timestamps...
Done 2/5
Deleting subtitles newlines...
Done 3/5
Deleting start and end whitespace...
Done 4/5
Deleting double or more whitespace...
Done. 5/5
Creating the txt file...
Finished saving The Egg - A Short Story [h6fcK_fRYaI].pl.txt

See also the 4 files that are stored in your relative path:

The Egg - A Short Story [h6fcK_fRYaI].de.txt
The Egg - A Short Story [h6fcK_fRYaI].de.vtt
The Egg - A Short Story [h6fcK_fRYaI].pl.txt
The Egg - A Short Story [h6fcK_fRYaI].pl.vtt

Contributing

Contribution guidelines are under development. However, I am already open for pull requests.

License

GNU GPLv3 Image

Software licensed under the GNU GPLv3.