def wget(url,saveto):
    print "get",url,"to",saveto
    import urllib
    if url.endswith(".gif"):
        prefix=saveto.rsplit(".",1)[0]
        saveto = prefix+".png"
        txt_name = prefix+".txt"
        import gif2strip
        if not (os.path.exists(txt_name) or os.path.exists(saveto)):
            try:
                gif2strip.go(url,saveto)
            except (urllib2.HTTPError,urllib2.URLError):
                pass
    elif url.endswith(".mp3"):
        prefix=saveto.rsplit(".",1)[0]
        saveto=prefix+".ogg"
        if not os.path.exists(saveto):
            urllib.urlretrieve(url.replace(" ","%20"),"mp3ogg/input.mp3")
            subprocess.call(["mp3ogg\mpg123.exe","-w","mp3ogg\output.wav","mp3ogg\input.mp3"])
            subprocess.call(["mp3ogg\oggenc2.exe","mp3ogg\output.wav","mp3ogg\output.ogg","--resample=44100"])
            f = open("mp3ogg/output.ogg","rb")
            o = f.read()
            f.close()
            f = open(saveto,"wb")
            f.write(o)
            f.close()
    elif not os.path.exists(saveto):
        print "retrieving"
        urllib.urlretrieve(url.replace(" ","%20"),saveto)
    return saveto
Beispiel #2
0
def wget(url, saveto):
    saveto = saveto.replace("\\", "sl")
    print "get", url, "to", saveto
    import urllib
    if url.endswith(".gif"):
        print "convert gif"
        prefix = saveto.rsplit(".", 1)[0]
        saveto = prefix + ".png"
        txt_name = prefix + ".txt"
        if not (os.path.exists(txt_name) or os.path.exists(saveto)):
            try:
                gif2strip.go(url, saveto)
            except (urllib2.HTTPError, urllib2.URLError, IndexError):
                pass
    elif url.endswith(".mp3"):
        if not os.path.exists(saveto):

            def progress(a, b, c):
                print int(a) * int(b) / float(c)

            for t in range(5):
                try:
                    urllib.urlretrieve(url.replace(" ", "%20"),
                                       "input.mp3",
                                       reporthook=progress)
                except socket.error, urllib.ContentTooShortError:
                    print "retrying"
                    time.sleep(2)
                    continue
                break
            external.run({
                "command": "mpg123",
                "operation": "towav",
                "input": "input.mp3",
                "output": "output.wav"
            })
            external.run({
                "command": "oggenc2",
                "operation": "toogg",
                "input": "output.wav",
                "output": "output.ogg"
            })
            f = open("output.ogg", "rb")
            o = f.read()
            f.close()
            f = open(saveto, "wb")
            f.write(o)
            f.close()
            os.remove("input.mp3")
            os.remove("output.wav")
            os.remove("output.ogg")
Beispiel #3
0
 def update(self, *args):
     assets = self.assets
     self.rpos = [0, 0]
     self.pos = self.rpos
     self.children[:] = [
         x for x in self.children if not getattr(x, "kill", 0)
     ]
     for x in self.children:
         x.update()
     if getattr(self, "giffile", ""):
         sys.path.append("tools")
         import gif2strip
         try:
             path = gif2strip.go(self.giffile)
             m = msg("Converted " + path.rsplit("/", 1)[1] + ".png",
                     self.assets)
             self.children.append(m)
             graphic = pygame.transform.rotozoom(
                 pygame.image.load(path + ".png"), 0, 0.25)
             m.children.append(gui.button(None, "x"))
             m.children[-1].graphic = graphic
             setattr(m.children[-1], "x", m.click_down_over)
         except Exception:
             import traceback
             traceback.print_exc()
             self.children.append(
                 msg("File could not be converted.", self.assets))
         self.giffile = ""
     return True
Beispiel #4
0
def wget(url,saveto):
    saveto = saveto.replace("\\","sl")
    print "get",url,"to",saveto
    import urllib
    if url.endswith(".gif"):
        print "convert gif"
        prefix=saveto.rsplit(".",1)[0]
        saveto = prefix+".png"
        txt_name = prefix+".txt"
        if not (os.path.exists(txt_name) or os.path.exists(saveto)):
            try:
                gif2strip.go(url,saveto)
            except (urllib2.HTTPError,urllib2.URLError):
                pass
    elif url.endswith(".mp3"):
        if not os.path.exists(saveto):
            def progress(a,b,c):
                print int(a)*int(b)/float(c)
            for t in range(5):
                try:
                    urllib.urlretrieve(url.replace(" ","%20"),"input.mp3",reporthook=progress)
                except socket.error,urllib.ContentTooShortError:
                    print "retrying"
                    time.sleep(2)
                    continue
                break
            external.run({"command":"mpg123","operation":"towav","input":"input.mp3","output":"output.wav"})
            external.run({"command":"oggenc2","operation":"toogg","input":"output.wav","output":"output.ogg"})
            f = open("output.ogg","rb")
            o = f.read()
            f.close()
            f = open(saveto,"wb")
            f.write(o)
            f.close()
            os.remove("input.mp3")
            os.remove("output.wav")
            os.remove("output.ogg")
Beispiel #5
0
def wget(url, saveto):
    print "get", url, "to", saveto
    import urllib
    if url.endswith(".gif"):
        prefix = saveto.rsplit(".", 1)[0]
        saveto = prefix + ".png"
        txt_name = prefix + ".txt"
        import gif2strip
        if not (os.path.exists(txt_name) or os.path.exists(saveto)):
            try:
                gif2strip.go(url, saveto)
            except (urllib2.HTTPError, urllib2.URLError):
                pass
    elif url.endswith(".mp3"):
        prefix = saveto.rsplit(".", 1)[0]
        saveto = prefix + ".ogg"
        if not os.path.exists(saveto):
            urllib.urlretrieve(url.replace(" ", "%20"), "mp3ogg/input.mp3")
            subprocess.call([
                "mp3ogg\mpg123.exe", "-w", "mp3ogg\output.wav",
                "mp3ogg\input.mp3"
            ])
            subprocess.call([
                "mp3ogg\oggenc2.exe", "mp3ogg\output.wav", "mp3ogg\output.ogg",
                "--resample=44100"
            ])
            f = open("mp3ogg/output.ogg", "rb")
            o = f.read()
            f.close()
            f = open(saveto, "wb")
            f.write(o)
            f.close()
    elif not os.path.exists(saveto):
        print "retrieving"
        urllib.urlretrieve(url.replace(" ", "%20"), saveto)
    return saveto
Beispiel #6
0
 def update(self,*args):
     assets = self.assets
     self.rpos = [0,0]
     self.pos = self.rpos
     self.children[:] = [x for x in self.children if not getattr(x,"kill",0)]
     for x in self.children:
         x.update()
     if getattr(self,"giffile",""):
         sys.path.append("tools")
         import gif2strip
         try:
             path = gif2strip.go(self.giffile)
             m = msg("Converted "+path.rsplit("/",1)[1]+".png",self.assets)
             self.children.append(m)
             graphic = pygame.transform.rotozoom(pygame.image.load(path+".png"),0,0.25)
             m.children.append(gui.button(None,"x"))
             m.children[-1].graphic = graphic
             setattr(m.children[-1],"x",m.click_down_over)
         except Exception:
             import traceback
             traceback.print_exc()
             self.children.append(msg("File could not be converted.",self.assets))
         self.giffile = ""
     return True