~davidc3/onehundredscopes/youporn-precise

« back to all changes in this revision

Viewing changes to src/tiny-video-parser

  • Committer: David Callé
  • Date: 2011-12-17 19:14:07 UTC
  • Revision ID: davidc@framli.eu-20111217191407-2cszgj46upa75ci0
Init + packaging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
# -*- coding: latin-1 -*-
 
3
 
 
4
from gi.repository import GLib
 
5
import gio
 
6
from lxml.html import fromstring
 
7
import urllib2
 
8
import sys
 
9
 
 
10
vlc = gio.File('/usr/bin/vlc')
 
11
if vlc.query_exists():
 
12
        GLib.spawn_command_line_async("vlc --one-instance")
 
13
else:
 
14
        GLib.spawn_command_line_async("totem --replace")
 
15
 
 
16
print "########"
 
17
print "tiny-video-parser : start"
 
18
video= ''
 
19
 
 
20
uri = sys.argv[1]
 
21
print "URI=%s" % uri
 
22
results = urllib2.urlopen(uri).read()
 
23
tree = fromstring(results)
 
24
for a in tree.cssselect('div ul li p a'):
 
25
        if a.get('href').startswith("http://download.youporn.com/download/") and 'MP4' in a.text_content():
 
26
                video = a.get('href')
 
27
                source = a.text_content()
 
28
        elif a.get('href').startswith("http://download.youporn.com/download/") and 'MPG' in a.text_content():
 
29
                video = a.get('href')
 
30
                source = a.text_content()
 
31
        else:
 
32
                pass
 
33
 
 
34
print "TYPE=%s" % source
 
35
print "STREAM=%s" % video
 
36
if vlc.query_exists():
 
37
        GLib.spawn_command_line_async("vlc --one-instance '%s'" % video)
 
38
else:
 
39
        GLib.spawn_command_line_async("totem --replace '%s'" % video)