Skip to content

Commit

Permalink
1.3-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanBindez committed Oct 2, 2023
1 parent 8dcaaef commit 368b028
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[bumpversion]
current_version = 1.2-rc1
current_version = 1.3-rc1
commit = True
tag = True

[bumpversion:file:pytube/version.py]
[bumpversion:file:pytubefix/version.py]
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@




### This python3 library is a solution to pytube's problem regarding update delays

### install:
## install:

pip install pytubefix
pip install pytubefix

----------
### usage:
## usage:

```python

Expand Down Expand Up @@ -51,7 +50,7 @@ ys.download(mp3=True) # pass the parameter mp3=Tre to save in .mp3

-----------

### if you want to download complete playlists:
## if you want to download complete playlists:

```python

Expand All @@ -70,7 +69,7 @@ for video in pl.videos:
```
----------

### Subtitle/Caption Tracks:
## Subtitle/Caption Tracks:

#### viewing available subtitles:

Expand Down Expand Up @@ -98,8 +97,22 @@ caption = yt.captions.get_by_language_code('en')
print(caption.generate_srt_captions())

```

#### now you can save subtitles to a txt file:

```python

from pytubefix import YouTube

yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')

caption = yt.captions.get_by_language_code('en')
caption.save_captions("captions.txt")

```

------------
### Using Channels:
## Using Channels:

#### get the channel name:

Expand Down
13 changes: 13 additions & 0 deletions pytubefix/captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ def generate_srt_captions(self) -> str:
recompiles them into the "SubRip Subtitle" format.
"""
return self.xml_caption_to_srt(self.xml_captions)

def save_captions(self, filename: str):
"""Generate and save "SubRip Subtitle" captions to a text file.
Takes the xml captions from :meth:`~pytubefix.Caption.xml_captions` and
recompiles them into the "SubRip Subtitle" format and saves it to a text file.
:param filename: The name of the file to save the captions.
"""
srt_captions = self.xml_caption_to_srt(self.xml_captions)

with open(filename, 'w', encoding='utf-8') as file:
file.write(srt_captions)

@staticmethod
def float_to_srt_time_format(d: float) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pytubefix/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.0"
__version__ = "1.3-rc1"

if __name__ == "__main__":
print(__version__)
12 changes: 5 additions & 7 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from pytubefix import Channel
from pytubefix import YouTube


c = Channel("https://www.youtube.com/@ProgrammingKnowledge")

print(f'Downloading videos by: {c.channel_name}')

for video in c.videos:
download = video.streams.get_highest_resolution().download()
yt = YouTube('http://youtube.com/watch?v=2lAe1cqCOXo')

caption = yt.captions.get_by_language_code('en')
caption.save_captions("captions.txt")

0 comments on commit 368b028

Please sign in to comment.