diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..ee94e42
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,27 @@
+module code.ivysaur.me/annie-miqt
+
+go 1.19
+
+require (
+ github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403
+ github.com/PuerkitoBio/goquery v1.5.1
+ github.com/andybalholm/cascadia v1.2.0
+ github.com/cheggaaa/pb v1.0.29-0.20200109123023-ca7ab1060666
+ github.com/cloudfoundry-attic/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
+ github.com/fatih/color v1.9.0
+ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
+ github.com/iawia002/annie v0.0.0-20200204103259-9f6dfcb99250
+ github.com/kr/pretty v0.1.0
+ github.com/kr/text v0.1.0
+ github.com/mattn/go-colorable v0.1.5-0.20200110010445-c742d6fb21c2
+ github.com/mattn/go-isatty v0.0.13-0.20200128103942-cb30d6282491
+ github.com/mattn/go-runewidth v0.0.9-0.20200125155203-588506649b41
+ github.com/rs/zerolog v1.17.3-0.20200115210151-505b18daf2bb
+ github.com/rylio/ytdl v0.6.3-0.20200102153401-9eb9d2cc8513
+ github.com/tidwall/gjson v1.4.0
+ github.com/tidwall/match v1.0.1
+ github.com/tidwall/pretty v1.0.1
+ golang.org/x/net v0.0.0-20200202094626-16171245cfb2
+ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5
+ golang.org/x/text v0.3.3-0.20191230102452-929e72ca90de
+)
diff --git a/vendor/github.com/MercuryEngineering/CookieMonster/LICENSE b/vendor/github.com/MercuryEngineering/CookieMonster/LICENSE
deleted file mode 100644
index cc937ee..0000000
--- a/vendor/github.com/MercuryEngineering/CookieMonster/LICENSE
+++ /dev/null
@@ -1,22 +0,0 @@
-MIT License
-
-Copyright (c) 2018 Henry Slawniak
-
-## License
-
-The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic].
-
-[jquery]: http://jquery.com/
-[go]: http://golang.org/
-[cascadia]: https://github.com/andybalholm/cascadia
-[cascadiacli]: https://github.com/suntong/cascadia
-[bsd]: http://opensource.org/licenses/BSD-3-Clause
-[golic]: http://golang.org/LICENSE
-[caslic]: https://github.com/andybalholm/cascadia/blob/master/LICENSE
-[doc]: http://godoc.org/github.com/PuerkitoBio/goquery
-[index]: http://api.jquery.com/index/
-[gonet]: https://github.com/golang/net/
-[html]: http://godoc.org/golang.org/x/net/html
-[wiki]: https://github.com/PuerkitoBio/goquery/wiki/Tips-and-tricks
-[thatguystone]: https://github.com/thatguystone
-[piotr]: https://github.com/piotrkowalczuk
-[goq]: https://github.com/andrewstuart/goq
diff --git a/vendor/github.com/PuerkitoBio/goquery/array.go b/vendor/github.com/PuerkitoBio/goquery/array.go
deleted file mode 100644
index 1b1f6cb..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/array.go
+++ /dev/null
@@ -1,124 +0,0 @@
-package goquery
-
-import (
- "golang.org/x/net/html"
-)
-
-const (
- maxUint = ^uint(0)
- maxInt = int(maxUint >> 1)
-
- // ToEnd is a special index value that can be used as end index in a call
- // to Slice so that all elements are selected until the end of the Selection.
- // It is equivalent to passing (*Selection).Length().
- ToEnd = maxInt
-)
-
-// First reduces the set of matched elements to the first in the set.
-// It returns a new Selection object, and an empty Selection object if the
-// the selection is empty.
-func (s *Selection) First() *Selection {
- return s.Eq(0)
-}
-
-// Last reduces the set of matched elements to the last in the set.
-// It returns a new Selection object, and an empty Selection object if
-// the selection is empty.
-func (s *Selection) Last() *Selection {
- return s.Eq(-1)
-}
-
-// Eq reduces the set of matched elements to the one at the specified index.
-// If a negative index is given, it counts backwards starting at the end of the
-// set. It returns a new Selection object, and an empty Selection object if the
-// index is invalid.
-func (s *Selection) Eq(index int) *Selection {
- if index < 0 {
- index += len(s.Nodes)
- }
-
- if index >= len(s.Nodes) || index < 0 {
- return newEmptySelection(s.document)
- }
-
- return s.Slice(index, index+1)
-}
-
-// Slice reduces the set of matched elements to a subset specified by a range
-// of indices. The start index is 0-based and indicates the index of the first
-// element to select. The end index is 0-based and indicates the index at which
-// the elements stop being selected (the end index is not selected).
-//
-// The indices may be negative, in which case they represent an offset from the
-// end of the selection.
-//
-// The special value ToEnd may be specified as end index, in which case all elements
-// until the end are selected. This works both for a positive and negative start
-// index.
-func (s *Selection) Slice(start, end int) *Selection {
- if start < 0 {
- start += len(s.Nodes)
- }
- if end == ToEnd {
- end = len(s.Nodes)
- } else if end < 0 {
- end += len(s.Nodes)
- }
- return pushStack(s, s.Nodes[start:end])
-}
-
-// Get retrieves the underlying node at the specified index.
-// Get without parameter is not implemented, since the node array is available
-// on the Selection object.
-func (s *Selection) Get(index int) *html.Node {
- if index < 0 {
- index += len(s.Nodes) // Negative index gets from the end
- }
- return s.Nodes[index]
-}
-
-// Index returns the position of the first element within the Selection object
-// relative to its sibling elements.
-func (s *Selection) Index() int {
- if len(s.Nodes) > 0 {
- return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length()
- }
- return -1
-}
-
-// IndexSelector returns the position of the first element within the
-// Selection object relative to the elements matched by the selector, or -1 if
-// not found.
-func (s *Selection) IndexSelector(selector string) int {
- if len(s.Nodes) > 0 {
- sel := s.document.Find(selector)
- return indexInSlice(sel.Nodes, s.Nodes[0])
- }
- return -1
-}
-
-// IndexMatcher returns the position of the first element within the
-// Selection object relative to the elements matched by the matcher, or -1 if
-// not found.
-func (s *Selection) IndexMatcher(m Matcher) int {
- if len(s.Nodes) > 0 {
- sel := s.document.FindMatcher(m)
- return indexInSlice(sel.Nodes, s.Nodes[0])
- }
- return -1
-}
-
-// IndexOfNode returns the position of the specified node within the Selection
-// object, or -1 if not found.
-func (s *Selection) IndexOfNode(node *html.Node) int {
- return indexInSlice(s.Nodes, node)
-}
-
-// IndexOfSelection returns the position of the first node in the specified
-// Selection object within this Selection object, or -1 if not found.
-func (s *Selection) IndexOfSelection(sel *Selection) int {
- if sel != nil && len(sel.Nodes) > 0 {
- return indexInSlice(s.Nodes, sel.Nodes[0])
- }
- return -1
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/doc.go b/vendor/github.com/PuerkitoBio/goquery/doc.go
deleted file mode 100644
index 71146a7..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/doc.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2012-2016, Martin Angers & Contributors
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or
-// other materials provided with the distribution.
-// * Neither the name of the author nor the names of its contributors may be used to
-// endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
-// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-/*
-Package goquery implements features similar to jQuery, including the chainable
-syntax, to manipulate and query an HTML document.
-
-It brings a syntax and a set of features similar to jQuery to the Go language.
-It is based on Go's net/html package and the CSS Selector library cascadia.
-Since the net/html parser returns nodes, and not a full-featured DOM
-tree, jQuery's stateful manipulation functions (like height(), css(), detach())
-have been left off.
-
-Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is
-the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML.
-See the repository's wiki for various options on how to do this.
-
-Syntax-wise, it is as close as possible to jQuery, with the same method names when
-possible, and that warm and fuzzy chainable interface. jQuery being the
-ultra-popular library that it is, writing a similar HTML-manipulating
-library was better to follow its API than to start anew (in the same spirit as
-Go's fmt package), even though some of its methods are less than intuitive (looking
-at you, index()...).
-
-It is hosted on GitHub, along with additional documentation in the README.md
-file: https://github.com/puerkitobio/goquery
-
-Please note that because of the net/html dependency, goquery requires Go1.1+.
-
-The various methods are split into files based on the category of behavior.
-The three dots (...) indicate that various "overloads" are available.
-
-* array.go : array-like positional manipulation of the selection.
- - Eq()
- - First()
- - Get()
- - Index...()
- - Last()
- - Slice()
-
-* expand.go : methods that expand or augment the selection's set.
- - Add...()
- - AndSelf()
- - Union(), which is an alias for AddSelection()
-
-* filter.go : filtering methods, that reduce the selection's set.
- - End()
- - Filter...()
- - Has...()
- - Intersection(), which is an alias of FilterSelection()
- - Not...()
-
-* iteration.go : methods to loop over the selection's nodes.
- - Each()
- - EachWithBreak()
- - Map()
-
-* manipulation.go : methods for modifying the document
- - After...()
- - Append...()
- - Before...()
- - Clone()
- - Empty()
- - Prepend...()
- - Remove...()
- - ReplaceWith...()
- - Unwrap()
- - Wrap...()
- - WrapAll...()
- - WrapInner...()
-
-* property.go : methods that inspect and get the node's properties values.
- - Attr*(), RemoveAttr(), SetAttr()
- - AddClass(), HasClass(), RemoveClass(), ToggleClass()
- - Html()
- - Length()
- - Size(), which is an alias for Length()
- - Text()
-
-* query.go : methods that query, or reflect, a node's identity.
- - Contains()
- - Is...()
-
-* traversal.go : methods to traverse the HTML document tree.
- - Children...()
- - Contents()
- - Find...()
- - Next...()
- - Parent[s]...()
- - Prev...()
- - Siblings...()
-
-* type.go : definition of the types exposed by goquery.
- - Document
- - Selection
- - Matcher
-
-* utilities.go : definition of helper functions (and not methods on a *Selection)
-that are not part of jQuery, but are useful to goquery.
- - NodeName
- - OuterHtml
-*/
-package goquery
diff --git a/vendor/github.com/PuerkitoBio/goquery/expand.go b/vendor/github.com/PuerkitoBio/goquery/expand.go
deleted file mode 100644
index 7caade5..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/expand.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-// Add adds the selector string's matching nodes to those in the current
-// selection and returns a new Selection object.
-// The selector string is run in the context of the document of the current
-// Selection object.
-func (s *Selection) Add(selector string) *Selection {
- return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...)
-}
-
-// AddMatcher adds the matcher's matching nodes to those in the current
-// selection and returns a new Selection object.
-// The matcher is run in the context of the document of the current
-// Selection object.
-func (s *Selection) AddMatcher(m Matcher) *Selection {
- return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...)
-}
-
-// AddSelection adds the specified Selection object's nodes to those in the
-// current selection and returns a new Selection object.
-func (s *Selection) AddSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.AddNodes()
- }
- return s.AddNodes(sel.Nodes...)
-}
-
-// Union is an alias for AddSelection.
-func (s *Selection) Union(sel *Selection) *Selection {
- return s.AddSelection(sel)
-}
-
-// AddNodes adds the specified nodes to those in the
-// current selection and returns a new Selection object.
-func (s *Selection) AddNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil))
-}
-
-// AndSelf adds the previous set of elements on the stack to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the previous one.
-// Deprecated: This function has been deprecated and is now an alias for AddBack().
-func (s *Selection) AndSelf() *Selection {
- return s.AddBack()
-}
-
-// AddBack adds the previous set of elements on the stack to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the previous one.
-func (s *Selection) AddBack() *Selection {
- return s.AddSelection(s.prevSel)
-}
-
-// AddBackFiltered reduces the previous set of elements on the stack to those that
-// match the selector string, and adds them to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the filtered previous one
-func (s *Selection) AddBackFiltered(selector string) *Selection {
- return s.AddSelection(s.prevSel.Filter(selector))
-}
-
-// AddBackMatcher reduces the previous set of elements on the stack to those that match
-// the mateher, and adds them to the curernt set.
-// It returns a new Selection object containing the current Selection combined
-// with the filtered previous one
-func (s *Selection) AddBackMatcher(m Matcher) *Selection {
- return s.AddSelection(s.prevSel.FilterMatcher(m))
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/filter.go b/vendor/github.com/PuerkitoBio/goquery/filter.go
deleted file mode 100644
index 9138ffb..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/filter.go
+++ /dev/null
@@ -1,163 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-// Filter reduces the set of matched elements to those that match the selector string.
-// It returns a new Selection object for this subset of matching elements.
-func (s *Selection) Filter(selector string) *Selection {
- return s.FilterMatcher(compileMatcher(selector))
-}
-
-// FilterMatcher reduces the set of matched elements to those that match
-// the given matcher. It returns a new Selection object for this subset
-// of matching elements.
-func (s *Selection) FilterMatcher(m Matcher) *Selection {
- return pushStack(s, winnow(s, m, true))
-}
-
-// Not removes elements from the Selection that match the selector string.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) Not(selector string) *Selection {
- return s.NotMatcher(compileMatcher(selector))
-}
-
-// NotMatcher removes elements from the Selection that match the given matcher.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotMatcher(m Matcher) *Selection {
- return pushStack(s, winnow(s, m, false))
-}
-
-// FilterFunction reduces the set of matched elements to those that pass the function's test.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection {
- return pushStack(s, winnowFunction(s, f, true))
-}
-
-// NotFunction removes elements from the Selection that pass the function's test.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection {
- return pushStack(s, winnowFunction(s, f, false))
-}
-
-// FilterNodes reduces the set of matched elements to those that match the specified nodes.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, winnowNodes(s, nodes, true))
-}
-
-// NotNodes removes elements from the Selection that match the specified nodes.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, winnowNodes(s, nodes, false))
-}
-
-// FilterSelection reduces the set of matched elements to those that match a
-// node in the specified Selection object.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, winnowNodes(s, nil, true))
- }
- return pushStack(s, winnowNodes(s, sel.Nodes, true))
-}
-
-// NotSelection removes elements from the Selection that match a node in the specified
-// Selection object. It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, winnowNodes(s, nil, false))
- }
- return pushStack(s, winnowNodes(s, sel.Nodes, false))
-}
-
-// Intersection is an alias for FilterSelection.
-func (s *Selection) Intersection(sel *Selection) *Selection {
- return s.FilterSelection(sel)
-}
-
-// Has reduces the set of matched elements to those that have a descendant
-// that matches the selector.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) Has(selector string) *Selection {
- return s.HasSelection(s.document.Find(selector))
-}
-
-// HasMatcher reduces the set of matched elements to those that have a descendant
-// that matches the matcher.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasMatcher(m Matcher) *Selection {
- return s.HasSelection(s.document.FindMatcher(m))
-}
-
-// HasNodes reduces the set of matched elements to those that have a
-// descendant that matches one of the nodes.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasNodes(nodes ...*html.Node) *Selection {
- return s.FilterFunction(func(_ int, sel *Selection) bool {
- // Add all nodes that contain one of the specified nodes
- for _, n := range nodes {
- if sel.Contains(n) {
- return true
- }
- }
- return false
- })
-}
-
-// HasSelection reduces the set of matched elements to those that have a
-// descendant that matches one of the nodes of the specified Selection object.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.HasNodes()
- }
- return s.HasNodes(sel.Nodes...)
-}
-
-// End ends the most recent filtering operation in the current chain and
-// returns the set of matched elements to its previous state.
-func (s *Selection) End() *Selection {
- if s.prevSel != nil {
- return s.prevSel
- }
- return newEmptySelection(s.document)
-}
-
-// Filter based on the matcher, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnow(sel *Selection, m Matcher, keep bool) []*html.Node {
- // Optimize if keep is requested
- if keep {
- return m.Filter(sel.Nodes)
- }
- // Use grep
- return grep(sel, func(i int, s *Selection) bool {
- return !m.Match(s.Get(0))
- })
-}
-
-// Filter based on an array of nodes, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node {
- if len(nodes)+len(sel.Nodes) < minNodesForSet {
- return grep(sel, func(i int, s *Selection) bool {
- return isInSlice(nodes, s.Get(0)) == keep
- })
- }
-
- set := make(map[*html.Node]bool)
- for _, n := range nodes {
- set[n] = true
- }
- return grep(sel, func(i int, s *Selection) bool {
- return set[s.Get(0)] == keep
- })
-}
-
-// Filter based on a function test, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnowFunction(sel *Selection, f func(int, *Selection) bool, keep bool) []*html.Node {
- return grep(sel, func(i int, s *Selection) bool {
- return f(i, s) == keep
- })
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/go.mod b/vendor/github.com/PuerkitoBio/goquery/go.mod
deleted file mode 100644
index 95826ad..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/go.mod
+++ /dev/null
@@ -1,8 +0,0 @@
-module github.com/PuerkitoBio/goquery
-
-require (
- github.com/andybalholm/cascadia v1.1.0
- golang.org/x/net v0.0.0-20200202094626-16171245cfb2
-)
-
-go 1.13
diff --git a/vendor/github.com/PuerkitoBio/goquery/go.sum b/vendor/github.com/PuerkitoBio/goquery/go.sum
deleted file mode 100644
index bc79107..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/go.sum
+++ /dev/null
@@ -1,8 +0,0 @@
-github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
-github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
-golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/vendor/github.com/PuerkitoBio/goquery/iteration.go b/vendor/github.com/PuerkitoBio/goquery/iteration.go
deleted file mode 100644
index e246f2e..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/iteration.go
+++ /dev/null
@@ -1,39 +0,0 @@
-package goquery
-
-// Each iterates over a Selection object, executing a function for each
-// matched element. It returns the current Selection object. The function
-// f is called for each element in the selection with the index of the
-// element in that selection starting at 0, and a *Selection that contains
-// only that element.
-func (s *Selection) Each(f func(int, *Selection)) *Selection {
- for i, n := range s.Nodes {
- f(i, newSingleSelection(n, s.document))
- }
- return s
-}
-
-// EachWithBreak iterates over a Selection object, executing a function for each
-// matched element. It is identical to Each except that it is possible to break
-// out of the loop by returning false in the callback function. It returns the
-// current Selection object.
-func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
- for i, n := range s.Nodes {
- if !f(i, newSingleSelection(n, s.document)) {
- return s
- }
- }
- return s
-}
-
-// Map passes each element in the current matched set through a function,
-// producing a slice of string holding the returned values. The function
-// f is called for each element in the selection with the index of the
-// element in that selection starting at 0, and a *Selection that contains
-// only that element.
-func (s *Selection) Map(f func(int, *Selection) string) (result []string) {
- for i, n := range s.Nodes {
- result = append(result, f(i, newSingleSelection(n, s.document)))
- }
-
- return result
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/manipulation.go b/vendor/github.com/PuerkitoBio/goquery/manipulation.go
deleted file mode 100644
index 34eb757..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/manipulation.go
+++ /dev/null
@@ -1,574 +0,0 @@
-package goquery
-
-import (
- "strings"
-
- "golang.org/x/net/html"
-)
-
-// After applies the selector from the root document and inserts the matched elements
-// after the elements in the set of matched elements.
-//
-// If one of the matched elements in the selection is not currently in the
-// document, it's impossible to insert nodes after it, so it will be ignored.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) After(selector string) *Selection {
- return s.AfterMatcher(compileMatcher(selector))
-}
-
-// AfterMatcher applies the matcher from the root document and inserts the matched elements
-// after the elements in the set of matched elements.
-//
-// If one of the matched elements in the selection is not currently in the
-// document, it's impossible to insert nodes after it, so it will be ignored.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterMatcher(m Matcher) *Selection {
- return s.AfterNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// AfterSelection inserts the elements in the selection after each element in the set of matched
-// elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterSelection(sel *Selection) *Selection {
- return s.AfterNodes(sel.Nodes...)
-}
-
-// AfterHtml parses the html and inserts it after the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterHtml(html string) *Selection {
- return s.AfterNodes(parseHtml(html)...)
-}
-
-// AfterNodes inserts the nodes after each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) {
- if sn.Parent != nil {
- sn.Parent.InsertBefore(n, sn.NextSibling)
- }
- })
-}
-
-// Append appends the elements specified by the selector to the end of each element
-// in the set of matched elements, following those rules:
-//
-// 1) The selector is applied to the root document.
-//
-// 2) Elements that are part of the document will be moved to the new location.
-//
-// 3) If there are multiple locations to append to, cloned nodes will be
-// appended to all target locations except the last one, which will be moved
-// as noted in (2).
-func (s *Selection) Append(selector string) *Selection {
- return s.AppendMatcher(compileMatcher(selector))
-}
-
-// AppendMatcher appends the elements specified by the matcher to the end of each element
-// in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendMatcher(m Matcher) *Selection {
- return s.AppendNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// AppendSelection appends the elements in the selection to the end of each element
-// in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendSelection(sel *Selection) *Selection {
- return s.AppendNodes(sel.Nodes...)
-}
-
-// AppendHtml parses the html and appends it to the set of matched elements.
-func (s *Selection) AppendHtml(html string) *Selection {
- return s.AppendNodes(parseHtml(html)...)
-}
-
-// AppendNodes appends the specified nodes to each node in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) {
- sn.AppendChild(n)
- })
-}
-
-// Before inserts the matched elements before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) Before(selector string) *Selection {
- return s.BeforeMatcher(compileMatcher(selector))
-}
-
-// BeforeMatcher inserts the matched elements before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeMatcher(m Matcher) *Selection {
- return s.BeforeNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// BeforeSelection inserts the elements in the selection before each element in the set of matched
-// elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeSelection(sel *Selection) *Selection {
- return s.BeforeNodes(sel.Nodes...)
-}
-
-// BeforeHtml parses the html and inserts it before the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeHtml(html string) *Selection {
- return s.BeforeNodes(parseHtml(html)...)
-}
-
-// BeforeNodes inserts the nodes before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) {
- if sn.Parent != nil {
- sn.Parent.InsertBefore(n, sn)
- }
- })
-}
-
-// Clone creates a deep copy of the set of matched nodes. The new nodes will not be
-// attached to the document.
-func (s *Selection) Clone() *Selection {
- ns := newEmptySelection(s.document)
- ns.Nodes = cloneNodes(s.Nodes)
- return ns
-}
-
-// Empty removes all children nodes from the set of matched elements.
-// It returns the children nodes in a new Selection.
-func (s *Selection) Empty() *Selection {
- var nodes []*html.Node
-
- for _, n := range s.Nodes {
- for c := n.FirstChild; c != nil; c = n.FirstChild {
- n.RemoveChild(c)
- nodes = append(nodes, c)
- }
- }
-
- return pushStack(s, nodes)
-}
-
-// Prepend prepends the elements specified by the selector to each element in
-// the set of matched elements, following the same rules as Append.
-func (s *Selection) Prepend(selector string) *Selection {
- return s.PrependMatcher(compileMatcher(selector))
-}
-
-// PrependMatcher prepends the elements specified by the matcher to each
-// element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependMatcher(m Matcher) *Selection {
- return s.PrependNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// PrependSelection prepends the elements in the selection to each element in
-// the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependSelection(sel *Selection) *Selection {
- return s.PrependNodes(sel.Nodes...)
-}
-
-// PrependHtml parses the html and prepends it to the set of matched elements.
-func (s *Selection) PrependHtml(html string) *Selection {
- return s.PrependNodes(parseHtml(html)...)
-}
-
-// PrependNodes prepends the specified nodes to each node in the set of
-// matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) {
- // sn.FirstChild may be nil, in which case this functions like
- // sn.AppendChild()
- sn.InsertBefore(n, sn.FirstChild)
- })
-}
-
-// Remove removes the set of matched elements from the document.
-// It returns the same selection, now consisting of nodes not in the document.
-func (s *Selection) Remove() *Selection {
- for _, n := range s.Nodes {
- if n.Parent != nil {
- n.Parent.RemoveChild(n)
- }
- }
-
- return s
-}
-
-// RemoveFiltered removes the set of matched elements by selector.
-// It returns the Selection of removed nodes.
-func (s *Selection) RemoveFiltered(selector string) *Selection {
- return s.RemoveMatcher(compileMatcher(selector))
-}
-
-// RemoveMatcher removes the set of matched elements.
-// It returns the Selection of removed nodes.
-func (s *Selection) RemoveMatcher(m Matcher) *Selection {
- return s.FilterMatcher(m).Remove()
-}
-
-// ReplaceWith replaces each element in the set of matched elements with the
-// nodes matched by the given selector.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWith(selector string) *Selection {
- return s.ReplaceWithMatcher(compileMatcher(selector))
-}
-
-// ReplaceWithMatcher replaces each element in the set of matched elements with
-// the nodes matched by the given Matcher.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection {
- return s.ReplaceWithNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// ReplaceWithSelection replaces each element in the set of matched elements with
-// the nodes from the given Selection.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection {
- return s.ReplaceWithNodes(sel.Nodes...)
-}
-
-// ReplaceWithHtml replaces each element in the set of matched elements with
-// the parsed HTML.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithHtml(html string) *Selection {
- return s.ReplaceWithNodes(parseHtml(html)...)
-}
-
-// ReplaceWithNodes replaces each element in the set of matched elements with
-// the given nodes.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection {
- s.AfterNodes(ns...)
- return s.Remove()
-}
-
-// SetHtml sets the html content of each element in the selection to
-// specified html string.
-func (s *Selection) SetHtml(html string) *Selection {
- return setHtmlNodes(s, parseHtml(html)...)
-}
-
-// SetText sets the content of each element in the selection to specified content.
-// The provided text string is escaped.
-func (s *Selection) SetText(text string) *Selection {
- return s.SetHtml(html.EscapeString(text))
-}
-
-// Unwrap removes the parents of the set of matched elements, leaving the matched
-// elements (and their siblings, if any) in their place.
-// It returns the original selection.
-func (s *Selection) Unwrap() *Selection {
- s.Parent().Each(func(i int, ss *Selection) {
- // For some reason, jquery allows unwrap to remove the
(.+?)
`) - if desc != nil { - title = desc[1] - } else { - title = "抖音短视频" - } - realURLs := utils.MatchOneOf(html, `playAddr: "(.+?)"`) - if realURLs == nil || len(realURLs) < 2 { - return nil, extractors.ErrURLParseFailed - } - realURL := realURLs[1] - - size, err := request.Size(realURL, url) - if err != nil { - return nil, err - } - urlData := downloader.URL{ - URL: realURL, - Size: size, - Ext: "mp4", - } - streams := map[string]downloader.Stream{ - "default": { - URLs: []downloader.URL{urlData}, - Size: size, - }, - } - return []downloader.Data{ - { - Site: "抖音 douyin.com", - Title: title, - Type: "video", - Streams: streams, - URL: url, - }, - }, nil -} diff --git a/vendor/github.com/iawia002/annie/extractors/douyu/douyu.go b/vendor/github.com/iawia002/annie/extractors/douyu/douyu.go deleted file mode 100644 index 4f512fc..0000000 --- a/vendor/github.com/iawia002/annie/extractors/douyu/douyu.go +++ /dev/null @@ -1,110 +0,0 @@ -package douyu - -import ( - "encoding/json" - "errors" - - "github.com/iawia002/annie/downloader" - "github.com/iawia002/annie/extractors" - "github.com/iawia002/annie/request" - "github.com/iawia002/annie/utils" -) - -type douyuData struct { - Error int `json:"error"` - Data struct { - VideoURL string `json:"video_url"` - } `json:"data"` -} - -type douyuURLInfo struct { - URL string - Size int64 -} - -func douyuM3u8(url string) ([]douyuURLInfo, int64, error) { - var ( - data []douyuURLInfo - temp douyuURLInfo - size, totalSize int64 - err error - ) - urls, err := utils.M3u8URLs(url) - if err != nil { - return nil, 0, err - } - for _, u := range urls { - size, err = request.Size(u, url) - if err != nil { - return nil, 0, err - } - totalSize += size - temp = douyuURLInfo{ - URL: u, - Size: size, - } - data = append(data, temp) - } - return data, totalSize, nil -} - -// Extract is the main function for extracting data -func Extract(url string) ([]downloader.Data, error) { - var err error - liveVid := utils.MatchOneOf(url, `https?://www.douyu.com/(\S+)`) - if liveVid != nil { - return nil, errors.New("暂不支持斗鱼直播") - } - - html, err := request.Get(url, url, nil) - if err != nil { - return nil, err - } - titles := utils.MatchOneOf(html, `block. - if d != "" && d[0] == '\r' { - d = d[1:] - } - if d != "" && d[0] == '\n' { - d = d[1:] - } - } - } - d = strings.Replace(d, "\x00", "", -1) - if d == "" { - return true - } - p.reconstructActiveFormattingElements() - p.addText(d) - if p.framesetOK && strings.TrimLeft(d, whitespace) != "" { - // There were non-whitespace characters inserted. - p.framesetOK = false - } - case StartTagToken: - switch p.tok.DataAtom { - case a.Html: - if p.oe.contains(a.Template) { - return true - } - copyAttributes(p.oe[0], p.tok) - case a.Base, a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Script, a.Style, a.Template, a.Title: - return inHeadIM(p) - case a.Body: - if p.oe.contains(a.Template) { - return true - } - if len(p.oe) >= 2 { - body := p.oe[1] - if body.Type == ElementNode && body.DataAtom == a.Body { - p.framesetOK = false - copyAttributes(body, p.tok) - } - } - case a.Frameset: - if !p.framesetOK || len(p.oe) < 2 || p.oe[1].DataAtom != a.Body { - // Ignore the token. - return true - } - body := p.oe[1] - if body.Parent != nil { - body.Parent.RemoveChild(body) - } - p.oe = p.oe[:1] - p.addElement() - p.im = inFramesetIM - return true - case a.Address, a.Article, a.Aside, a.Blockquote, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Main, a.Menu, a.Nav, a.Ol, a.P, a.Section, a.Summary, a.Ul: - p.popUntil(buttonScope, a.P) - p.addElement() - case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6: - p.popUntil(buttonScope, a.P) - switch n := p.top(); n.DataAtom { - case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6: - p.oe.pop() - } - p.addElement() - case a.Pre, a.Listing: - p.popUntil(buttonScope, a.P) - p.addElement() - // The newline, if any, will be dealt with by the TextToken case. - p.framesetOK = false - case a.Form: - if p.form != nil && !p.oe.contains(a.Template) { - // Ignore the token - return true - } - p.popUntil(buttonScope, a.P) - p.addElement() - if !p.oe.contains(a.Template) { - p.form = p.top() - } - case a.Li: - p.framesetOK = false - for i := len(p.oe) - 1; i >= 0; i-- { - node := p.oe[i] - switch node.DataAtom { - case a.Li: - p.oe = p.oe[:i] - case a.Address, a.Div, a.P: - continue - default: - if !isSpecialElement(node) { - continue - } - } - break - } - p.popUntil(buttonScope, a.P) - p.addElement() - case a.Dd, a.Dt: - p.framesetOK = false - for i := len(p.oe) - 1; i >= 0; i-- { - node := p.oe[i] - switch node.DataAtom { - case a.Dd, a.Dt: - p.oe = p.oe[:i] - case a.Address, a.Div, a.P: - continue - default: - if !isSpecialElement(node) { - continue - } - } - break - } - p.popUntil(buttonScope, a.P) - p.addElement() - case a.Plaintext: - p.popUntil(buttonScope, a.P) - p.addElement() - case a.Button: - p.popUntil(defaultScope, a.Button) - p.reconstructActiveFormattingElements() - p.addElement() - p.framesetOK = false - case a.A: - for i := len(p.afe) - 1; i >= 0 && p.afe[i].Type != scopeMarkerNode; i-- { - if n := p.afe[i]; n.Type == ElementNode && n.DataAtom == a.A { - p.inBodyEndTagFormatting(a.A, "a") - p.oe.remove(n) - p.afe.remove(n) - break - } - } - p.reconstructActiveFormattingElements() - p.addFormattingElement() - case a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U: - p.reconstructActiveFormattingElements() - p.addFormattingElement() - case a.Nobr: - p.reconstructActiveFormattingElements() - if p.elementInScope(defaultScope, a.Nobr) { - p.inBodyEndTagFormatting(a.Nobr, "nobr") - p.reconstructActiveFormattingElements() - } - p.addFormattingElement() - case a.Applet, a.Marquee, a.Object: - p.reconstructActiveFormattingElements() - p.addElement() - p.afe = append(p.afe, &scopeMarker) - p.framesetOK = false - case a.Table: - if !p.quirks { - p.popUntil(buttonScope, a.P) - } - p.addElement() - p.framesetOK = false - p.im = inTableIM - return true - case a.Area, a.Br, a.Embed, a.Img, a.Input, a.Keygen, a.Wbr: - p.reconstructActiveFormattingElements() - p.addElement() - p.oe.pop() - p.acknowledgeSelfClosingTag() - if p.tok.DataAtom == a.Input { - for _, t := range p.tok.Attr { - if t.Key == "type" { - if strings.ToLower(t.Val) == "hidden" { - // Skip setting framesetOK = false - return true - } - } - } - } - p.framesetOK = false - case a.Param, a.Source, a.Track: - p.addElement() - p.oe.pop() - p.acknowledgeSelfClosingTag() - case a.Hr: - p.popUntil(buttonScope, a.P) - p.addElement() - p.oe.pop() - p.acknowledgeSelfClosingTag() - p.framesetOK = false - case a.Image: - p.tok.DataAtom = a.Img - p.tok.Data = a.Img.String() - return false - case a.Textarea: - p.addElement() - p.setOriginalIM() - p.framesetOK = false - p.im = textIM - case a.Xmp: - p.popUntil(buttonScope, a.P) - p.reconstructActiveFormattingElements() - p.framesetOK = false - p.parseGenericRawTextElement() - case a.Iframe: - p.framesetOK = false - p.parseGenericRawTextElement() - case a.Noembed: - p.parseGenericRawTextElement() - case a.Noscript: - if p.scripting { - p.parseGenericRawTextElement() - return true - } - p.reconstructActiveFormattingElements() - p.addElement() - // Don't let the tokenizer go into raw text mode when scripting is disabled. - p.tokenizer.NextIsNotRawText() - case a.Select: - p.reconstructActiveFormattingElements() - p.addElement() - p.framesetOK = false - p.im = inSelectIM - return true - case a.Optgroup, a.Option: - if p.top().DataAtom == a.Option { - p.oe.pop() - } - p.reconstructActiveFormattingElements() - p.addElement() - case a.Rb, a.Rtc: - if p.elementInScope(defaultScope, a.Ruby) { - p.generateImpliedEndTags() - } - p.addElement() - case a.Rp, a.Rt: - if p.elementInScope(defaultScope, a.Ruby) { - p.generateImpliedEndTags("rtc") - } - p.addElement() - case a.Math, a.Svg: - p.reconstructActiveFormattingElements() - if p.tok.DataAtom == a.Math { - adjustAttributeNames(p.tok.Attr, mathMLAttributeAdjustments) - } else { - adjustAttributeNames(p.tok.Attr, svgAttributeAdjustments) - } - adjustForeignAttributes(p.tok.Attr) - p.addElement() - p.top().Namespace = p.tok.Data - if p.hasSelfClosingToken { - p.oe.pop() - p.acknowledgeSelfClosingTag() - } - return true - case a.Caption, a.Col, a.Colgroup, a.Frame, a.Head, a.Tbody, a.Td, a.Tfoot, a.Th, a.Thead, a.Tr: - // Ignore the token. - default: - p.reconstructActiveFormattingElements() - p.addElement() - } - case EndTagToken: - switch p.tok.DataAtom { - case a.Body: - if p.elementInScope(defaultScope, a.Body) { - p.im = afterBodyIM - } - case a.Html: - if p.elementInScope(defaultScope, a.Body) { - p.parseImpliedToken(EndTagToken, a.Body, a.Body.String()) - return false - } - return true - case a.Address, a.Article, a.Aside, a.Blockquote, a.Button, a.Center, a.Details, a.Dialog, a.Dir, a.Div, a.Dl, a.Fieldset, a.Figcaption, a.Figure, a.Footer, a.Header, a.Hgroup, a.Listing, a.Main, a.Menu, a.Nav, a.Ol, a.Pre, a.Section, a.Summary, a.Ul: - p.popUntil(defaultScope, p.tok.DataAtom) - case a.Form: - if p.oe.contains(a.Template) { - i := p.indexOfElementInScope(defaultScope, a.Form) - if i == -1 { - // Ignore the token. - return true - } - p.generateImpliedEndTags() - if p.oe[i].DataAtom != a.Form { - // Ignore the token. - return true - } - p.popUntil(defaultScope, a.Form) - } else { - node := p.form - p.form = nil - i := p.indexOfElementInScope(defaultScope, a.Form) - if node == nil || i == -1 || p.oe[i] != node { - // Ignore the token. - return true - } - p.generateImpliedEndTags() - p.oe.remove(node) - } - case a.P: - if !p.elementInScope(buttonScope, a.P) { - p.parseImpliedToken(StartTagToken, a.P, a.P.String()) - } - p.popUntil(buttonScope, a.P) - case a.Li: - p.popUntil(listItemScope, a.Li) - case a.Dd, a.Dt: - p.popUntil(defaultScope, p.tok.DataAtom) - case a.H1, a.H2, a.H3, a.H4, a.H5, a.H6: - p.popUntil(defaultScope, a.H1, a.H2, a.H3, a.H4, a.H5, a.H6) - case a.A, a.B, a.Big, a.Code, a.Em, a.Font, a.I, a.Nobr, a.S, a.Small, a.Strike, a.Strong, a.Tt, a.U: - p.inBodyEndTagFormatting(p.tok.DataAtom, p.tok.Data) - case a.Applet, a.Marquee, a.Object: - if p.popUntil(defaultScope, p.tok.DataAtom) { - p.clearActiveFormattingElements() - } - case a.Br: - p.tok.Type = StartTagToken - return false - case a.Template: - return inHeadIM(p) - default: - p.inBodyEndTagOther(p.tok.DataAtom, p.tok.Data) - } - case CommentToken: - p.addChild(&Node{ - Type: CommentNode, - Data: p.tok.Data, - }) - case ErrorToken: - // TODO: remove this divergence from the HTML5 spec. - if len(p.templateStack) > 0 { - p.im = inTemplateIM - return false - } - for _, e := range p.oe { - switch e.DataAtom { - case a.Dd, a.Dt, a.Li, a.Optgroup, a.Option, a.P, a.Rb, a.Rp, a.Rt, a.Rtc, a.Tbody, a.Td, a.Tfoot, a.Th, - a.Thead, a.Tr, a.Body, a.Html: - default: - return true - } - } - } - - return true -} - -func (p *parser) inBodyEndTagFormatting(tagAtom a.Atom, tagName string) { - // This is the "adoption agency" algorithm, described at - // https://html.spec.whatwg.org/multipage/syntax.html#adoptionAgency - - // TODO: this is a fairly literal line-by-line translation of that algorithm. - // Once the code successfully parses the comprehensive test suite, we should - // refactor this code to be more idiomatic. - - // Steps 1-2 - if current := p.oe.top(); current.Data == tagName && p.afe.index(current) == -1 { - p.oe.pop() - return - } - - // Steps 3-5. The outer loop. - for i := 0; i < 8; i++ { - // Step 6. Find the formatting element. - var formattingElement *Node - for j := len(p.afe) - 1; j >= 0; j-- { - if p.afe[j].Type == scopeMarkerNode { - break - } - if p.afe[j].DataAtom == tagAtom { - formattingElement = p.afe[j] - break - } - } - if formattingElement == nil { - p.inBodyEndTagOther(tagAtom, tagName) - return - } - - // Step 7. Ignore the tag if formatting element is not in the stack of open elements. - feIndex := p.oe.index(formattingElement) - if feIndex == -1 { - p.afe.remove(formattingElement) - return - } - // Step 8. Ignore the tag if formatting element is not in the scope. - if !p.elementInScope(defaultScope, tagAtom) { - // Ignore the tag. - return - } - - // Step 9. This step is omitted because it's just a parse error but no need to return. - - // Steps 10-11. Find the furthest block. - var furthestBlock *Node - for _, e := range p.oe[feIndex:] { - if isSpecialElement(e) { - furthestBlock = e - break - } - } - if furthestBlock == nil { - e := p.oe.pop() - for e != formattingElement { - e = p.oe.pop() - } - p.afe.remove(e) - return - } - - // Steps 12-13. Find the common ancestor and bookmark node. - commonAncestor := p.oe[feIndex-1] - bookmark := p.afe.index(formattingElement) - - // Step 14. The inner loop. Find the lastNode to reparent. - lastNode := furthestBlock - node := furthestBlock - x := p.oe.index(node) - // Step 14.1. - j := 0 - for { - // Step 14.2. - j++ - // Step. 14.3. - x-- - node = p.oe[x] - // Step 14.4. Go to the next step if node is formatting element. - if node == formattingElement { - break - } - // Step 14.5. Remove node from the list of active formatting elements if - // inner loop counter is greater than three and node is in the list of - // active formatting elements. - if ni := p.afe.index(node); j > 3 && ni > -1 { - p.afe.remove(node) - // If any element of the list of active formatting elements is removed, - // we need to take care whether bookmark should be decremented or not. - // This is because the value of bookmark may exceed the size of the - // list by removing elements from the list. - if ni <= bookmark { - bookmark-- - } - continue - } - // Step 14.6. Continue the next inner loop if node is not in the list of - // active formatting elements. - if p.afe.index(node) == -1 { - p.oe.remove(node) - continue - } - // Step 14.7. - clone := node.clone() - p.afe[p.afe.index(node)] = clone - p.oe[p.oe.index(node)] = clone - node = clone - // Step 14.8. - if lastNode == furthestBlock { - bookmark = p.afe.index(node) + 1 - } - // Step 14.9. - if lastNode.Parent != nil { - lastNode.Parent.RemoveChild(lastNode) - } - node.AppendChild(lastNode) - // Step 14.10. - lastNode = node - } - - // Step 15. Reparent lastNode to the common ancestor, - // or for misnested table nodes, to the foster parent. - if lastNode.Parent != nil { - lastNode.Parent.RemoveChild(lastNode) - } - switch commonAncestor.DataAtom { - case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr: - p.fosterParent(lastNode) - default: - commonAncestor.AppendChild(lastNode) - } - - // Steps 16-18. Reparent nodes from the furthest block's children - // to a clone of the formatting element. - clone := formattingElement.clone() - reparentChildren(clone, furthestBlock) - furthestBlock.AppendChild(clone) - - // Step 19. Fix up the list of active formatting elements. - if oldLoc := p.afe.index(formattingElement); oldLoc != -1 && oldLoc < bookmark { - // Move the bookmark with the rest of the list. - bookmark-- - } - p.afe.remove(formattingElement) - p.afe.insert(bookmark, clone) - - // Step 20. Fix up the stack of open elements. - p.oe.remove(formattingElement) - p.oe.insert(p.oe.index(furthestBlock)+1, clone) - } -} - -// inBodyEndTagOther performs the "any other end tag" algorithm for inBodyIM. -// "Any other end tag" handling from 12.2.6.5 The rules for parsing tokens in foreign content -// https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inforeign -func (p *parser) inBodyEndTagOther(tagAtom a.Atom, tagName string) { - for i := len(p.oe) - 1; i >= 0; i-- { - // Two element nodes have the same tag if they have the same Data (a - // string-typed field). As an optimization, for common HTML tags, each - // Data string is assigned a unique, non-zero DataAtom (a uint32-typed - // field), since integer comparison is faster than string comparison. - // Uncommon (custom) tags get a zero DataAtom. - // - // The if condition here is equivalent to (p.oe[i].Data == tagName). - if (p.oe[i].DataAtom == tagAtom) && - ((tagAtom != 0) || (p.oe[i].Data == tagName)) { - p.oe = p.oe[:i] - break - } - if isSpecialElement(p.oe[i]) { - break - } - } -} - -// Section 12.2.6.4.8. -func textIM(p *parser) bool { - switch p.tok.Type { - case ErrorToken: - p.oe.pop() - case TextToken: - d := p.tok.Data - if n := p.oe.top(); n.DataAtom == a.Textarea && n.FirstChild == nil { - // Ignore a newline at the start of a