forked from bbc/brave
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathyoutubedltest.py
68 lines (51 loc) · 1.47 KB
/
youtubedltest.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import unicode_literals
import youtube_dl
streamurl = 'https://www.youtube.com/watch?v=vQ8xjg7mcgE'
purl = 'notset'
# should be able to just pass a -g and get the url
# forceurl or --get-url
# extracting and examples https://www.bogotobogo.com/VideoStreaming/YouTube/youtube-dl-embedding.php
# sudo -H pip install --upgrade youtube-dl
# /usr/local/lib/python2.7/dist-packages/youtube_dl/
# need to look at the info dict.. f['url']
class MyLogger(object):
#purl = 'notset'
def debug(self, msg):
global purl
if "https" in msg:
#print(msg)
purl = msg
pass
def warning(self, msg):
# print(msg)
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
if d['status'] == 'downloading':
print(d)
ydl_opts_audio = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
ydl_opts = {
'simulate': True,
'noplaylist' : True,
'forceurl' : True,
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([streamurl])
#meta = ydl.extract_info([streamurl],download=False)
#print("url:",meta['title'])
print("url:", purl)
#print("url:", purl)