-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathyoutube_maltego.py
More file actions
106 lines (76 loc) · 2.46 KB
/
youtube_maltego.py
File metadata and controls
106 lines (76 loc) · 2.46 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import sys
from googleapiclient import discovery
__author__ = "Jeff White [karttoon] @noottrak"
__email__ = "karttoon@gmail.com"
__version__ = "1.0.0"
__date__ = "17JUN2019"
# Google API Key
DEVELOPER_KEY = ""
def getResults(videoId, pageToken=""):
api_service_name = "youtube"
api_version = "v3"
youtube = discovery.build(
api_service_name,
api_version,
developerKey=DEVELOPER_KEY,
)
request = youtube.commentThreads().list(
part="snippet,replies",
videoId=videoId,
pageToken=pageToken,
maxResults=100
)
response = request.execute()
return response
def processResults(data, response):
for entry in response["items"]:
authorDisplayName = entry["snippet"]["topLevelComment"]["snippet"]["authorDisplayName"]
authorChannelUrl = entry["snippet"]["topLevelComment"]["snippet"]["authorChannelUrl"]
textDisplay = entry["snippet"]["topLevelComment"]["snippet"]["textDisplay"]
if authorChannelUrl not in data:
data[authorChannelUrl] = {"authorDisplayName": authorDisplayName,
"textDisplay": textDisplay}
return data
def CLIMessage(data):
for entry in data:
print("%s|||%s|||%s" % (entry,data[entry]["authorDisplayName"],data[entry]["textDisplay"]))
return
def maltegoMessage(data):
# Header
print("""<MaltegoMessage>
<MaltegoTransformResponseMessage>
<Entities>
""")
for entry in data:
print(""" <Entity Type="maltego.Alias">
<Value>%s</Value>
<Weight>100</Weight>
</Entity>
""" % (entry,
#data[entry]["textDisplay"],
#data[entry]["authorDisplayName"]
)
)
print(""" </Entities>
<UIMessages>
</UIMessages>
</MaltegoTransformResponseMessage>
</MaltegoMessage>
""")
return
def main():
videoId = sys.argv[1].split("=")[1]
data = {}
response = getResults(videoId)
data = processResults(data, response)
while "nextPageToken" in response:
response = getResults(videoId, response["nextPageToken"])
data = processResults(data, response)
# For Maltego ->
maltegoMessage(data)
# For general CLI (if too many nodes, this is ideal) ->
#CLIMessage(data)
return
if __name__ == "__main__":
main()