clickviewvids.py
· 1.7 KiB · Python
Raw
import requests
import sys
import os
from bs4 import BeautifulSoup as Soup
if len(sys.argv) < 2:
print sys.argv[0] + " <IP of server / ID of video> [ID of video] - Second arg is needed if first arg is IP"
sys.exit(2)
CVSERVER = "10.232.66.197"
if "." in sys.argv[1]:
CVSERVER = sys.argv[1]
sys.argv[1] = sys.argv[2]
print "server: " + CVSERVER
if not server:
print "Invalid server provided."
sys.exit(2)
request = """<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetVideo xmlns="http://ClickView.Web.CentralWebServices.ClickViewWebPlayer"><tokenId>{id}</tokenId></GetVideo></s:Body></s:Envelope>""".format(id=sys.argv[1])
headers = {"Content-Length": len(request), "Content-Type": "text/xml", "SOAPAction": "http://ClickView.Web.CentralWebServices.ClickViewWebPlayer/IWebPlayerService/GetVideo"}
data = requests.post("http://{addr}:9053/WebPlayerService.svc".format(addr=CVSERVER), headers=headers, data=request)
soup = Soup(data.text)
chapters = soup.findAll('a:video.videochapter')
files = {}
for a in chapters:
files[a.find('a:number').text] = {'url': a.find('a:file').text,
'title': a.find('a:title').text,
'ext': a.find('a:filetype').text.split(".")[-1],
"vid": sys.argv[1],
"fid": a.find('a:number').text}
print "got {} files".format(len(files))
with open("{}.bat".format(sys.argv[1]), "w") as f:
for v in files.values():
try:
os.mkdir(v["vid"])
except:
pass
f.write("wget {url} -O {vid}/{vid}-{fid}.{ext}\n".format(**v))
print "Done {vid}/{vid}-{fid}.{ext}".format(**v)
print "done"
| 1 | import requests |
| 2 | import sys |
| 3 | import os |
| 4 | from bs4 import BeautifulSoup as Soup |
| 5 | |
| 6 | if len(sys.argv) < 2: |
| 7 | print sys.argv[0] + " <IP of server / ID of video> [ID of video] - Second arg is needed if first arg is IP" |
| 8 | sys.exit(2) |
| 9 | |
| 10 | CVSERVER = "10.232.66.197" |
| 11 | if "." in sys.argv[1]: |
| 12 | CVSERVER = sys.argv[1] |
| 13 | sys.argv[1] = sys.argv[2] |
| 14 | print "server: " + CVSERVER |
| 15 | if not server: |
| 16 | print "Invalid server provided." |
| 17 | sys.exit(2) |
| 18 | |
| 19 | request = """<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetVideo xmlns="http://ClickView.Web.CentralWebServices.ClickViewWebPlayer"><tokenId>{id}</tokenId></GetVideo></s:Body></s:Envelope>""".format(id=sys.argv[1]) |
| 20 | |
| 21 | headers = {"Content-Length": len(request), "Content-Type": "text/xml", "SOAPAction": "http://ClickView.Web.CentralWebServices.ClickViewWebPlayer/IWebPlayerService/GetVideo"} |
| 22 | |
| 23 | data = requests.post("http://{addr}:9053/WebPlayerService.svc".format(addr=CVSERVER), headers=headers, data=request) |
| 24 | soup = Soup(data.text) |
| 25 | |
| 26 | chapters = soup.findAll('a:video.videochapter') |
| 27 | files = {} |
| 28 | for a in chapters: |
| 29 | files[a.find('a:number').text] = {'url': a.find('a:file').text, |
| 30 | 'title': a.find('a:title').text, |
| 31 | 'ext': a.find('a:filetype').text.split(".")[-1], |
| 32 | "vid": sys.argv[1], |
| 33 | "fid": a.find('a:number').text} |
| 34 | print "got {} files".format(len(files)) |
| 35 | with open("{}.bat".format(sys.argv[1]), "w") as f: |
| 36 | for v in files.values(): |
| 37 | try: |
| 38 | os.mkdir(v["vid"]) |
| 39 | except: |
| 40 | pass |
| 41 | f.write("wget {url} -O {vid}/{vid}-{fid}.{ext}\n".format(**v)) |
| 42 | print "Done {vid}/{vid}-{fid}.{ext}".format(**v) |
| 43 | print "done" |