Skip to content

Instantly share code, notes, and snippets.

@speccy88
Created September 17, 2015 14:13
Show Gist options
  • Select an option

  • Save speccy88/bf651dc5d5d696d03bb4 to your computer and use it in GitHub Desktop.

Select an option

Save speccy88/bf651dc5d5d696d03bb4 to your computer and use it in GitHub Desktop.
from PySide import QtGui, QtCore
from lxml import html
import requests
import urllib
import sys
def toStr(data):
if data:
return str(data)
else:
return ""
def getVideoData(row):
elements = row.getchildren()
# Video Name
link = elements[1][0]
name = link.attrib["href"]
# Check if file is a video
if not ".MP4" in name:
return None
# Get video URL
url = GOPRO_URL+name
# Video Size
size_e = elements[2]
s0 = size_e[0].text
s1 = size_e[1].text
size = toStr(s0)+toStr(s1)
return dict(name=name, url=url, size=size)
GOPRO_URL = "http://10.5.5.9:8080/videos/DCIM/100GOPRO/"
page = requests.get(GOPRO_URL)
tree = html.fromstring(page.text)
XPATH = '//*[@id="dirlist"]/table/tbody'
table = tree.xpath(XPATH)[0]
rows = table.getchildren()
video_list_raw = [getVideoData(row) for row in rows]
video_list = [video for video in video_list_raw if video!=None]
#print video_list
# QT Part
app = QtGui.QApplication(sys.argv)
# Init Widget
wid = QtGui.QWidget()
wid.setWindowTitle('GoPro Do2')
# Label
class ClickQLabel(QtGui.QLabel):
clicked = QtCore.Signal(str, str)
def __init(self, parent):
QtGui.QLabel.__init__(self, parent)
def setURL(self, url):
self.url = url
def setName(self, name):
self.name = name
def mouseReleaseEvent(self, ev):
self.clicked.emit(self.url, self.name)
@QtCore.Slot(str, str)
def downloadVideo(url, name):
urllib.urlretrieve(url, name)
quit()
font = QtGui.QFont("Times", 12, QtGui.QFont.Bold)
for i, video in enumerate(video_list):
lbl = ClickQLabel(wid)
lbl.setURL(video["url"])
lbl.setName(video["name"])
lbl.setFont(font)
lbl.setText(video["name"])
lbl.move(5,i*30+5)
lbl.clicked.connect(downloadVideo)
wid.resize(160,i*30+30)
# Show Window
wid.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment