| [2] | 1 | #!/usr/bin/env python
|
|---|
| 2 | # -*- coding: utf-8 -*-
|
|---|
| 3 | #
|
|---|
| 4 | # Copyright (C) 2011 Andrea Milazzo aka mancausoft <me@mancausoft.org>
|
|---|
| 5 | #
|
|---|
| 6 | # This Program is free software. It comes without any warranty, to
|
|---|
| 7 | # the extent permitted by applicable law. You can redistribute it
|
|---|
| 8 | # and/or modify it under the terms of the Do What The Fuck You Want
|
|---|
| 9 | # To Public License, Version 2, as published by Sam Hocevar. See
|
|---|
| 10 | # http://sam.zoy.org/wtfpl/COPYING for more details.
|
|---|
| 11 |
|
|---|
| 12 | from threading import Thread
|
|---|
| 13 | import urllib
|
|---|
| 14 | import sys, os
|
|---|
| 15 | from BeautifulSoup import BeautifulSoup
|
|---|
| 16 |
|
|---|
| 17 | def convert(namefile, rtsp_url):
|
|---|
| 18 | os.system("mplayer -dumpstream " + rtsp_url + " -dumpfile " + namefile)
|
|---|
| 19 | os.system("ffmpeg2theora -o " + namefile.split('.')[0] + ".ogg " + namefile)
|
|---|
| 20 | os.system("rm " + namefile)
|
|---|
| 21 |
|
|---|
| 22 | args = sys.argv
|
|---|
| 23 |
|
|---|
| 24 | try:
|
|---|
| 25 | url = args[1]
|
|---|
| 26 | except IndexError:
|
|---|
| 27 | print "Use: " + args[0] + " <urls>"
|
|---|
| 28 | sys.exit(2)
|
|---|
| 29 |
|
|---|
| 30 | if url[:7] != "http://":
|
|---|
| 31 | url = "http://" + url
|
|---|
| 32 |
|
|---|
| 33 | html = urllib.urlopen(url).read()
|
|---|
| 34 | soup = BeautifulSoup(html)
|
|---|
| 35 |
|
|---|
| 36 | data = soup.findAll('div', {'class' : 'scroll-pane'})
|
|---|
| 37 | data = data[0].findAll('a')
|
|---|
| 38 | data.reverse()
|
|---|
| 39 |
|
|---|
| 40 | tr =[]
|
|---|
| 41 | for i in data:
|
|---|
| 42 | rtsp_url = urllib.urlopen(i['href']).read().replace('\n','')
|
|---|
| 43 | namefile = rtsp_url.split('/')[-1]
|
|---|
| 44 | #print "mplayer -dumpstream " + rtsp_url + " -dumpfile " + namefile
|
|---|
| 45 | t = Thread(None, convert, None, (namefile, rtsp_url))
|
|---|
| 46 | t.start()
|
|---|
| 47 | tr.append(t)
|
|---|
| 48 |
|
|---|
| 49 | for i in tr:
|
|---|
| 50 | i.join()
|
|---|
| 51 |
|
|---|