Exemplo n.º 1
0
 def onMenuNew(self, evt):
     answer = wx.MessageBox(
         "Any unsaved data will be lost! Are you sure you want to continue?",
         "Confirm", wx.OK | wx.CANCEL, self)
     if answer == wx.OK:
         self.ml = metalink.Metalink()
         self.txtctrl_filename.Clear()
         self.txtctrl_identity.Clear()
         self.txtctrl_version.Clear()
         self.txtctrl_pub_name.Clear()
         self.txtctrl_pub_url.Clear()
         self.txtctrl_copy.Clear()
         self.txtctrl_desc.Clear()
         self.combo_license_name.SetValue("Unknown")
         self.txtctrl_license_url.Clear()
         self.txtctrl_size.Clear()
         self.txtctrl_md5.Clear()
         self.txtctrl_sha1.Clear()
         self.txtctrl_sha256.Clear()
         self.combo_os.SetValue("Unknown")
         self.txtctrl_lang.Clear()
         self.combo_maxconn_total.SetValue("-")
         self.txtctrl_url.Clear()
         self.txtctrl_loc.Clear()
         self.txtctrl_pref.Clear()
         self.combo_maxconn.SetValue("-")
         self.init_filelist()
         self.filename = ""
         self.new_file = True
         self.locked = False
         self.update()
Exemplo n.º 2
0
 def __init__(self, parent, title):
     wx.Frame.__init__(self, parent, -1, title)
     self.create_gui()
     self.filename = ""
     self.new_file = True
     self.locked = False
     self.ml = metalink.Metalink()
     self.mlfile = metalink.MetalinkFile(self.filename)
     self.ml.files.append(self.mlfile)
     self.update()
Exemplo n.º 3
0
def run():
    # Command line parser options.
    parser = optparse.OptionParser(usage="usage: %prog [options] urls")
    parser.add_option("--open",
                      dest="open",
                      help="Metalink file to open and modify")
    parser.add_option("-o", dest="output", help="Binary file name")
    parser.add_option("-d",
                      dest="download",
                      action="store_true",
                      help="Don't download the file again")
    parser.add_option("--merge",
                      "-m",
                      dest="merge",
                      action="store_true",
                      help="Use merge mode, urls are .metalink files to merge")
    parser.add_option("--clear_urls",
                      dest="clear_urls",
                      action="store_true",
                      help="Remove any existing urls when opening a file")
    parser.add_option("-4",
                      dest="v4",
                      action="store_true",
                      help="Force output to Metalink v4")
    parser.add_option("-i", dest="identity", help="Identity")
    parser.add_option("-v", dest="version", help="Version Number")
    #parser.add_option("--os", dest="os", help="Operating System")
    parser.add_option("--publisher-name",
                      dest="publisher_name",
                      help="Publisher Name")
    parser.add_option("--publisher-url",
                      dest="publisher_url",
                      help="Publisher URL")
    parser.add_option("-c", "--copyright", dest="copyright", help="Copyright")
    parser.add_option("--description", dest="description", help="Description")
    parser.add_option("--license-name",
                      dest="license_name",
                      help="License Name")
    parser.add_option("--license-url", dest="license_url", help="License URL")
    #parser.add_option("--magnet", dest="magnet", action="store_false", help="Do not add a magnet URL")
    parser.add_option("--ed2k",
                      dest="ed2k",
                      action="store_false",
                      help="Do not add a ed2k URL")
    #parser.add_option("-l", "--language", dest="language", help="The language the file is in, per ISO-639/3166. \"en-US\" for Standard American English")
    #parser.add_option("--maxconn", dest="maxconn_total", help="Maximum number of connections for downloading")
    parser.add_option(
        "--origin",
        dest="origin",
        help="URL for the finished metalink file to check for updates")
    #parser.add_option("--logo", dest="logo", help="URL for a related logo")
    #parser.add_option("-d", dest="pubdate", action="store_true", help="Set publication date to now")

    #parser.add_option("-s", "--size", dest="size", help="File size")

    parser.set_defaults(identity=None,
                        version=None,
                        os=None,
                        publisher_name=None,
                        publisher_url=None,
                        copyright=None,
                        description=None,
                        license_name=None,
                        license_url=None,
                        language=None,
                        maxconn_total=None,
                        origin=None,
                        magnet=False,
                        ed2k=True,
                        v4=False)
    (options, args) = parser.parse_args()
    if len(args) <= 0:
        print "ERROR: Specify a URL."
        parser.print_help()
        return

    #if options.pubdate:
    # RFC 822 format
    #    options.pubdate = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())

    xml = metalink.Metalink()
    #options.ed2k, options.magnet)

    if options.open != None:
        xml = metalink.parsefile(options.open)
        if options.clear_urls:
            xml.clear_res()

    for option in dir(options):
        if not option.startswith("_") and getattr(options, option) != None:
            try:
                getattr(xml, option)
            except AttributeError:
                continue
            setattr(xml, option, getattr(options, option))

    if options.merge != None:
        if len(args) < 2:
            print "ERROR: You should specify at least two files to merge."
            parser.print_help()
            return

        print merge(xml, args, options.v4)
        return

    download = True
    if options.download:
        download = False

    build(xml, args, None, options.output, download, options.ed2k,
          options.magnet, options.v4)
Exemplo n.º 4
0
    def run(self,
            dl_dir='dl',
            platform=None,
            links_fn=None,
            btlinks_fn=None,
            get_torrents=False):
        links = open(links_fn, 'w') if links_fn else None
        btlinks = open(btlinks_fn, 'w') if btlinks_fn else None

        if not os.path.exists(dl_dir):
            os.makedirs(dl_dir)

        import metalink

        m = metalink.Metalink()
        m.files = []
        metalink._opts['overwrite'] = True
        metalink._opts['create_torrent'] = False

        files = set()

        import progressbar
        progress = progressbar.ProgressBar()

        for gamekey in progress(self.client.get_gamekeys()):
            order = self.client.get_order(gamekey)
            #print(order.product.machine_name)
            if order.subproducts is not None:
                for subproduct in order.subproducts:
                    #print(subproduct)
                    #print(" " + subproduct.machine_name)
                    for download in subproduct.downloads:
                        #print download.platform
                        if platform is None or platform == download.platform:
                            for struct in download.download_struct:
                                found_link = False
                                if struct.url.bittorrent is not None:
                                    found_link = True
                                    if btlinks:
                                        btlinks.write(struct.url.bittorrent +
                                                      '\n')

                                    torrent_fn = dl_dir + '/' + struct.url.bittorrent.split(
                                        "?")[0].split("/")[-1]
                                    if get_torrents and not os.path.exists(
                                            torrent_fn):
                                        import urllib
                                        urllib.urlretrieve(
                                            struct.url.bittorrent, torrent_fn)

                                if struct.url.web is not None:
                                    found_link = True
                                    if links:
                                        links.write(struct.url.web + '\n')

                                if not found_link:
                                    #print(subproduct)
                                    #print(download)
                                    #print(struct)
                                    #print('----------------')
                                    continue

                                filename = struct.url.web.split("?")[0].split(
                                    "/")[-1]
                                if filename in files:
                                    continue
                                files.add(filename)

                                m.add_file()
                                m.file.filename = filename
                                m.file.os = download.platform
                                if struct.file_size is not None:
                                    m.file.size = str(struct.file_size)
                                if struct.sha1 and len(struct.sha1) == 40:
                                    m.file.hashes['sha1'] = struct.sha1
                                if struct.md5 and len(struct.md5) == 32:
                                    m.file.hashes['md5'] = struct.md5
                                if struct.url.web is not None:
                                    m.file.add_url(struct.url.web)
                                if struct.url.bittorrent is not None:
                                    m.file.add_url(struct.url.bittorrent,
                                                   'bittorrent')

        m.generate(dl_dir + '/hb.metalink')