~davidc3/onehundredscopes/youporn-precise

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
#! /usr/bin/python
# -*- coding: latin-1 -*-

from gi.repository import GLib
import gio
from lxml.html import fromstring
import urllib2
import sys

opener = urllib2.build_opener()
opener.addheaders.append(('Cookie', 'age_verified=1'))
urllib2.install_opener(opener)

vlc = gio.File('/usr/bin/vlc')
if vlc.query_exists():
    GLib.spawn_command_line_async("vlc --one-instance")
else:
    GLib.spawn_command_line_async("totem --replace")

print "########"
print "tiny-video-parser : start"
video= None
source = None

uri = sys.argv[1]
print "URI=%s" % uri
results = urllib2.urlopen(uri).read()
tree = fromstring(results)
for a in tree.cssselect('a'):
    if 'MP4 -' in a.text_content() or 'MPG -' in a.text_content():
        if a.get('href').startswith("http://"):
            video = a.get('href')
            source = a.text_content()

if video and source:
    print "TYPE=%s" % source
    print "STREAM=%s" % video
    if vlc.query_exists():
        GLib.spawn_command_line_async("vlc --one-instance '%s'" % video)
    else:
        GLib.spawn_command_line_async("totem --replace '%s'" % video)
else:
    print "Error in locating video"