-
Notifications
You must be signed in to change notification settings - Fork 2
/
youtube.py
47 lines (40 loc) · 1.39 KB
/
youtube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from __future__ import unicode_literals
import youtube_dl
import os
def extractFromYoutube(url_id, output_path):
ydl_opts = {
'writesubtitles' : True,
'writeautomaticsub' : True,
'format': 'bestaudio/best',
'outtmpl' : output_path+'/%(id)s.%(ext)s',
'forcefilename' : True,
'subtitleslangs' : ['en'],
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'm4a',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
address = 'https://www.youtube.com/watch?v='+url_id
print address
ydl.download([address])
def extractFromMyYoutube(url_id, output_path):
YOUTUBE_USERNAME = os.environ['YOUTUBE_USERNAME']
YOUTUBE_PASSWORD = os.environ['YOUTUBE_PASSWORD']
ydl_opts = {
'username' : YOUTUBE_USERNAME,
'password' : YOUTUBE_PASSWORD,
# 'writesubtitles' : True,
'writeautomaticsub' : True,
'format': 'bestaudio/best',
'outtmpl' : output_path+'/%(id)s.%(ext)s',
'forcefilename' : True,
'subtitleslangs' : ['en'],
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'm4a',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
address = 'https://www.youtube.com/watch?v='+url_id
ydl.download([address])