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 division
, absolute_import
, print_function
;
18 import re
, os
, sys
, urllib
, urllib2
, cookielib
, StringIO
, gzip
, time
, datetime
, argparse
, urlparse
, pygame
;
20 parser
= argparse
.ArgumentParser();
21 parser
.add_argument("-name", help="title name");
22 parser
.add_argument("file", nargs
="*", help="file name");
23 parser
.add_argument("--user-agent", nargs
="?", default
="Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0", help="specify a custom user agent");
24 parser
.add_argument("--referer", nargs
="?", default
="http://motherless.com/", help="specify a custom referer, use if the video access");
25 getargs
= parser
.parse_args();
26 fakeua
= getargs
.user_agent
;
27 geturls_cj
= cookielib
.CookieJar();
28 geturls_opener
= urllib2
.build_opener(urllib2
.HTTPCookieProcessor(geturls_cj
));
29 geturls_opener
.addheaders
= [("Referer", getargs
.referer
), ("User-Agent", fakeua
), ("Accept-Encoding", "gzip, deflate"), ("Accept-Language", "en-US,en;q=0.8,en-CA,en-GB;q=0.6"), ("Accept-Charset", "ISO-8859-1,ISO-8859-15,utf-8;q=0.7,*;q=0.7"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), ("Connection", "close")];
30 if(getargs
.file==None or len(getargs
.file)==0):
31 pygame
.display
.quit();
34 numurlarg
= len(getargs
.file);
36 while(cururlarg
<numurlarg
):
37 geturls_text
= geturls_opener
.open(getargs
.file[cururlarg
]);
38 if(geturls_text
.info().get("Content-Encoding")=="gzip" or geturls_text
.info().get("Content-Encoding")=="deflate"):
39 strbuf
= StringIO
.StringIO(geturls_text
.read());
40 gzstrbuf
= gzip
.GzipFile(fileobj
=strbuf
);
41 outbuf
= StringIO
.StringIO(gzstrbuf
.read()[:]);
42 if(geturls_text
.info().get("Content-Encoding")!="gzip" and geturls_text
.info().get("Content-Encoding")!="deflate"):
43 outbuf
= StringIO
.StringIO(geturls_text
.read()[:]);
44 pygame
.display
.init();
45 pyres
= (pygame
.display
.Info().current_h
, pygame
.display
.Info().current_w
);
46 ppmimg
=pygame
.image
.load(outbuf
);
47 width
, height
= ppmimg
.get_size();
48 if(width
> pyres
[0] or height
> pyres
[1]):
49 dest_w
= float(pyres
[0]);
50 dest_h
= float(pyres
[1]);
51 scale
= dest_w
/ width
;
52 if(height
*scale
> dest_h
):
53 scale
= dest_h
/ height
;
54 size
= (int(width
* scale
), int(height
* scale
));
57 ppmimg
= pygame
.transform
.scale(ppmimg
, (width
, height
));
58 screen
= pygame
.display
.set_mode((width
, height
));
59 if(getargs
.name
!=None):
60 pygame
.display
.set_caption("PyXV - "+str(getargs
.name
));
61 if(getargs
.name
==None):
62 pygame
.display
.set_caption("PyXV - "+str(getargs
.file[cururlarg
]));
63 pygame
.display
.get_active();
64 pygame
.mouse
.set_visible(0);
65 screen
.blit(ppmimg
, (0, 0));
66 pygame
.display
.flip();
67 pygame
.display
.toggle_fullscreen();
70 for event
in pygame
.event
.get():
71 if (event
.type == pygame
.QUIT
):
73 if (event
.type == pygame
.KEYDOWN
):
74 if (event
.key
== pygame
.K_t
) or (event
.key
== pygame
.K_w
):
75 pygame
.display
.toggle_fullscreen();
76 if (event
.key
== pygame
.K_i
) or (event
.key
== pygame
.K_m
):
77 pygame
.display
.iconify();
78 if (event
.key
== pygame
.K_ESCAPE
) or (event
.key
== pygame
.K_q
):
80 pygame
.display
.quit();
82 cururlarg
= cururlarg
+ 1;