forked from wbwarnerb/ExercisesFor_Python3_book
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_scraper.py
More file actions
33 lines (29 loc) · 1.11 KB
/
audio_scraper.py
File metadata and controls
33 lines (29 loc) · 1.11 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
import pyshark
class Audio_Scraper:
def __init__(self, pcap, filter, outfile):
self.pcap = pcap
self.filter = filter
self.outfile = outfile
def scraper(self):
rtp_list =[]
pcap_file = ("/Users/bwarner/PycharmProjects/Chapter2_Exercises/%s" % self.pcap)
out_file = ("/Users/bwarner/PycharmProjects/Chapter2_Exercises/%s" % self.outfile)
print("Scraping: " + pcap_file)
filter_type = self.filter
cap = pyshark.FileCapture(pcap_file,display_filter=filter_type)
raw_audio = open(out_file,'wb')
for i in cap:
try:
rtp = i[3]
if rtp.payload:
print(rtp.payload)
rtp_list.append(rtp.payload.split(":"))
except:
pass
for rtp_packet in rtp_list:
packet = " ".join(rtp_packet)
print(packet)
audio = bytearray.fromhex(packet)
raw_audio.write(audio)
print("\nFinished outputing raw audio: %s" % out_file)
# pcap_test = Audio_Scraper("my.pcap","rtp","my_audio.raw").scraper()