File size: 649 Bytes
787a507
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pytube as pt


def second_to_timecode(x: float) -> str:
    """Float x second to HH:MM:SS.DDD format."""
    hour, x = divmod(x, 3600)
    minute, x = divmod(x, 60)
    second, x = divmod(x, 1)
    millisecond = int(x * 1000.)

    return '%.1d:%.2d:%.2d.%.3d' % (hour, minute, second, millisecond)


def download_from_youtube(youtube_link: str) -> str:
    yt = pt.YouTube(youtube_link)
    available_streams = yt.streams.filter(only_audio=True)
    print('available streams:')
    print(available_streams)
    stream = available_streams.first()
    # , audio_codec='wav'
    
    stream.download(filename="audio.wav")
    return "audio.wav"