示例#1
0
        void ReadSpine()
        {
            XFragment f = XFragment.FindFragment("manifest", OPF.text);

            _manifest = new Dictionary <string, ManifestItem>();
            foreach (var e in f.root.childs)
            {
                if (e.tag.tagname != "item")
                {
                    continue;
                }
                var i = new ManifestItem(e, this);
                _manifest.Add(i.id, i);
            }
            foreach (var a in _manifest)
            {
                if (a.Value.href[0] != '/')
                {
                    string dir = Path.GetDirectoryName(OPF.fullName);
                    if (dir != "")
                    {
                        a.Value.href = Path.GetDirectoryName(OPF.fullName) + "/" + a.Value.href;
                    }
                }
            }

            f      = XFragment.FindFragment("spine", OPF.text);
            _spine = new Spine(f, _manifest);
        }
示例#2
0
        public override void Process(Epub epub)
        {
            TextItem  opf = epub.OPF;
            XFragment f   = XFragment.FindFragment("metadata", opf.data);
            int       a   = f.root.tagEndRef;
            int       b   = f.IndexInSource(a);

            opf.data = opf.data.Insert(b, string.Format("\n    <meta name=\"AeroEpubProc\" content=\"{0}\" />\n", metaValue));
        }
示例#3
0
    public static TextEpubItemFile KakuyomuEpisode(string url)
    {
        Log.Note("Kakuyomu Episode");
        string raw     = GetSource(url);
        string sidebar = GetSource(url + "/episode_sidebar");

        Log.Info("Got text.");
        Regex     regex      = new Regex("<div class=\"widget-episodeBody js-episode-body[\\s\\S]*?</div>");
        string    part       = regex.Match(raw).Value;
        XFragment info       = XFragment.FindFragment("dl", sidebar);
        string    title      = info.root.childs[1].innerXHTML;
        string    uploadDate = info.root.childs[5].childs[0].tag.GetAttribute("datetime");
        string    updateDate = info.root.childs[7].childs[0].tag.GetAttribute("datetime");

        Log.Info($"{title}, Upload:{uploadDate}, Update:{updateDate}");
        string meta = $"    <title>{title}</title>\n    <meta name=\"Source\" content=\"{url}\" />\n    <meta name=\"Upload Date\" content=\"{uploadDate}\"/>\n    <meta name=\"Update Date\" content=\"{updateDate}\"/>";

        return(new TextEpubItemFile(Util.FilenameCheck(title) + ".xhtml", string.Format(xhtml, meta, part)));
    }
示例#4
0
    public void ReadMeta()
    {
        XFragment f = XFragment.FindFragment("metadata", OPF.data);

        _creator = "";

        foreach (var e in f.root.childs)
        {
            switch (e.tag.tagname)
            {
            case "dc:title": _title = e.innerXHTML; break;

            case "dc:creator": _creator += e.innerXHTML + ","; break;
            }
        }
        if (_creator.EndsWith(','))
        {
            _creator = _creator.Substring(0, _creator.Length - 1);
        }
    }
示例#5
0
        public override void Process(Epub epub)
        {
            Log.log("[Start]" + ToString());
            Log.level = " ";
            TextItem  opf = epub.OPF;
            XFragment f   = XFragment.FindFragment("metadata", opf.data);

            foreach (var e in f.root.childs)
            {
                if (e.tag.tagname == "dc:creator")
                {
                    string a = e.tag.GetAttribute("opf:file-as");
                    bool   r = e.tag.RemoveAttribute("opf:file-as");
                    Log.log("[Info ]Removed meta info opf:file-as=" + a);
                }
            }
            f.Apply(ref opf.data);
            Log.level = "";
            Log.log("[End]" + ToString());
            Log.log("");
        }
示例#6
0
        void ReadMeta3()
        {
            XFragment         f       = XFragment.FindFragment("metadata", OPF.text);
            List <MetaRecord> primary = new List <MetaRecord>();

            foreach (var e in f.root.childs)
            {
                switch (e.tag.tagname)
                {
                case "dc:language":
                case "dc:identifier":
                {
                    var t = new MetaRecord(e);
                    primary.Add(t);
                }
                break;

                case "meta":
                {
                    string name = e.tag.GetAttribute("name");
                    if (name != "")
                    {
                        var t = new MetaRecord();
                        t.name  = name;
                        t.value = e.tag.GetAttribute("content");
                        meta.Add(t);
                        continue;
                    }
                    string refines = e.tag.GetAttribute("refines");
                    if (refines != "")
                    {
                        if (refines.StartsWith("#") && refines.Length > 1)
                        {
                            string id = refines.Substring(1);
                            var    t  = new MetaRecord(e);
                            t.name = e.tag.GetAttribute("property");
                            t.AddIfExist(e, "scheme");
                            foreach (var r in primary)
                            {         //要是refine在primary前面我可不管……
                                if (r.id == id)
                                {
                                    r.refines.Add(t);
                                    break;
                                }
                            }
                            continue;
                        }
                    }
                    string property = e.tag.GetAttribute("property");
                    if (property != "")
                    {
                        var t = new MetaRecord(e);
                        t.name = property;
                        meta.Add(t);
                        continue;
                    }
                }
                break;

                default:
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "xml:lang");
                    t.AddIfExist(e, "dir");
                    primary.Add(t);
                }
                break;
                }
            }
            foreach (var a in primary)
            {
                switch (a.name)
                {
                case "dc:title": dc_titles.Add(a); break;

                case "dc:creator": dc_creators.Add(a); break;

                case "dc:identifier": dc_identifier.Add(a); break;

                case "dc:language": dc_language.Add(a); break;

                default: others.Add(a); break;
                }
            }
            foreach (var a in dc_identifier)
            {
                if (idref == a.id)
                {
                    uniqueIdentifier = a; break;
                }
            }
            foreach (var a in manifest)
            {
                switch (a.Value.properties)
                {
                case "nav": _toc = a.Value; break;

                case "cover-image": cover_img = a.Value.href; break;
                }
            }
            if (_toc == null)
            {
                _toc = spine.toc;
            }
            //check
            //if (dc_titles.Count == 0 || dc_identifier.Count == 0 || dc_language.Count == 0) { throw new EpubErrorException("Lack of some metadata."); }
        }
示例#7
0
        void ReadMeta2()
        {
            XFragment f = XFragment.FindFragment("metadata", OPF.text);

            foreach (var e in f.root.childs)
            {
                switch (e.tag.tagname)
                {
                case "dc:title":
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "opf:file-as");
                    dc_titles.Add(t);
                }
                break;

                case "dc:creator":
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "opf:file-as");
                    t.AddIfExist(e, "opf:role");
                    dc_creators.Add(t);
                }
                break;

                case "dc:language":
                {
                    var t = new MetaRecord(e);
                    dc_language.Add(t);
                }
                break;

                case "dc:identifier":
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "opf:scheme");
                    dc_identifier.Add(t);
                }
                break;

                case "dc:contributor":
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "opf:file-as");
                    t.AddIfExist(e, "opf:role");
                    others.Add(t);
                }
                break;

                case "dc:date":
                {
                    var t = new MetaRecord(e);
                    t.AddIfExist(e, "opf:event");
                    others.Add(t);
                }
                break;

                case "meta":
                {
                    var t = new MetaRecord();
                    t.name  = e.tag.GetAttribute("name");
                    t.value = e.tag.GetAttribute("content");
                    meta.Add(t);
                }
                break;

                default:
                {
                    var t = new MetaRecord(e);
                    others.Add(t);
                }
                break;
                }
            }
            foreach (var a in meta)
            {
                if (a.name == "cover")
                {
                    string id = a.value;
                    if (manifest.ContainsKey(id))
                    {
                        cover_img = manifest[id].href;
                    }
                    break;
                }
            }
            _toc = spine.toc;
        }