3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2011-2013 Cool Dude 2k - http://idb.berlios.de/
12 Copyright 2011-2013 Game Maker 2k - http://intdb.sourceforge.net/
13 Copyright 2011-2013 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
15 $FileInfo: xv.py - Last Update: 04/01/2013 Ver. 1.0.0 - Author: cooldude2k $
17 from __future__
import absolute_import
, division
, print_function
34 parser
= argparse
.ArgumentParser()
35 parser
.add_argument("-name", help="title name")
36 parser
.add_argument("file", nargs
="*", help="file name")
40 default
="Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0",
41 help="specify a custom user agent")
42 parser
.add_argument("--referer", nargs
="?", default
="http://motherless.com/",
43 help="specify a custom referer, use if the video access")
44 getargs
= parser
.parse_args()
45 fakeua
= getargs
.user_agent
46 geturls_cj
= cookielib
.CookieJar()
47 geturls_opener
= urllib2
.build_opener(urllib2
.HTTPCookieProcessor(geturls_cj
))
48 geturls_opener
.addheaders
= [
56 "en-US,en;q=0.8,en-CA,en-GB;q=0.6"),
58 "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"),
60 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"),
63 if (getargs
.file is None or len(getargs
.file) == 0):
67 numurlarg
= len(getargs
.file)
69 while (cururlarg
< numurlarg
):
70 geturls_text
= geturls_opener
.open(getargs
.file[cururlarg
])
71 if (geturls_text
.info().get("Content-Encoding") ==
72 "gzip" or geturls_text
.info().get("Content-Encoding") == "deflate"):
73 strbuf
= StringIO
.StringIO(geturls_text
.read())
74 gzstrbuf
= gzip
.GzipFile(fileobj
=strbuf
)
75 outbuf
= StringIO
.StringIO(gzstrbuf
.read()[:])
76 if (geturls_text
.info().get("Content-Encoding") !=
77 "gzip" and geturls_text
.info().get("Content-Encoding") != "deflate"):
78 outbuf
= StringIO
.StringIO(geturls_text
.read()[:])
80 pyres
= (pygame
.display
.Info().current_h
, pygame
.display
.Info().current_w
)
81 ppmimg
= pygame
.image
.load(outbuf
)
82 width
, height
= ppmimg
.get_size()
83 if (width
> pyres
[0] or height
> pyres
[1]):
84 dest_w
= float(pyres
[0])
85 dest_h
= float(pyres
[1])
86 scale
= dest_w
/ width
87 if (height
* scale
> dest_h
):
88 scale
= dest_h
/ height
89 size
= (int(width
* scale
), int(height
* scale
))
92 ppmimg
= pygame
.transform
.scale(ppmimg
, (width
, height
))
93 screen
= pygame
.display
.set_mode((width
, height
))
94 if (getargs
.name
is not None):
95 pygame
.display
.set_caption("PyXV - " + str(getargs
.name
))
96 if (getargs
.name
is None):
97 pygame
.display
.set_caption("PyXV - " + str(getargs
.file[cururlarg
]))
98 pygame
.display
.get_active()
99 pygame
.mouse
.set_visible(0)
100 screen
.blit(ppmimg
, (0, 0))
101 pygame
.display
.flip()
102 pygame
.display
.toggle_fullscreen()
105 for event
in pygame
.event
.get():
106 if (event
.type == pygame
.QUIT
):
108 if (event
.type == pygame
.KEYDOWN
):
109 if (event
.key
== pygame
.K_t
) or (event
.key
== pygame
.K_w
):
110 pygame
.display
.toggle_fullscreen()
111 if (event
.key
== pygame
.K_i
) or (event
.key
== pygame
.K_m
):
112 pygame
.display
.iconify()
113 if (event
.key
== pygame
.K_ESCAPE
) or (event
.key
== pygame
.K_q
):
115 pygame
.display
.quit()
117 cururlarg
= cururlarg
+ 1