-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube_md.py
76 lines (61 loc) · 1.82 KB
/
youtube_md.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
69
70
71
72
73
74
75
76
# youtube_md
import sys
import subprocess
import json
into_jsondata = {}
class metadata:
def __init__(self, link_url):
global into_jsondata
try:
self.link = link_url
except:
pass
try:
proc = subprocess.Popen(["youtube-dl", "--cookies", "cookies.txt","-j", self.link],stdout=subprocess.PIPE,)
out = proc.communicate()[0]
except:
print("Error, update youtube-dl and check cookies.txt is in current directory")
try:
into_jsondata = json.loads(out.decode('utf-8')) #Format into JSON
except:
pass
def showall(self):
pass
def thumbnail(self):
try:
return into_jsondata["thumbnails"][3]["url"]
except:
pass
def title(self):
try:
return into_jsondata["title"]
except:
pass
def url(self):
""" Finds Number Of Videos Formats, then sets count to minus 3, as this is HD with audio (needs more testing on range of videos formats)"""
count = 0
while True:
try:
stream_link = into_jsondata["formats"][count]["url"]
count = count + 1
except:
break
count = count - 1
try:
return into_jsondata["formats"][count]["url"]
except:
pass
#return into_jsondata
def find_number_of_formats():
""" Finds Number Of Videos Formats and Minus one (needs more testing on range of videos formats)"""
count = 0
while True:
try:
stream_link = into_jsondata["formats"][count]["url"]
count = count + 1
except:
break
try:
return count - 1
except:
pass