* [WIP] Torrent Generation on not found error As asked in #1517, it allows on-the-fly torrent generation. Since it uses magnet links, it needs some time to connect to peers. So it can't be instant generation, we need the user to wait and try after a minute at least. * Replace Fatal by simple error * attempt at fixing travis * del * Add Anacrolyx dependency * Add back difflib * Remove .torrent suffix in the url example * Add some explanations when file missing page shown * Ignore downloads directory * Either use cache (third-party site) or own download directory * Wrong import * If there is an error then it means we aren't generating a torrent file May it be "torrent not found" or "We do not store torrent files" which are the two only existing errors for this page * hash is never empty * TorrentLink may be empty at times So we add a /download/:hash link if it is * Update README.md * Made a mistake here, need to check if false * Update en-us.all.json * Update CHANGELOG.md * Torrent file generation can be triggered by click on button if JS enabled * Update download.go * Update download.go * Use c.JSON instead of text/template * Return to default behavior if we don't generate the file * Don't do the query if returned to default behavior * Add "Could not generate torrent file" error * Fix JS condition & lower delay until button updates * Start download automatically once torrent file is generated * Fix torrentFileExists() constantly returning false if external torrent download URL * torrent-view-data is two tables instead of one This allows the removal of useless things without any problem (e.g Website link), but also a better responsibe design since the previous one separated stats after a certain res looking very wonky * CSS changes to go along * Remove useless <b></b> * Update main.css * In torrentFileExists, check if filestorage path exists instead of looking at the domain in torrent link When checking if the file is stored on another server i used to simply check if the domain name was inside the torrent link, but we can straight up check for filestorage length * Fix JS of on-demand stat fetching * ScrapeAge variable accessible through view.jet.html Contains last scraped time in hours, is at -1 is torrent has never been scraped Stats will get updated if it's either at -1 or above 1460 (2 months old) * Refresh stats if older than two months OR unknown and older than 24h Show last scraped date even if stats are unknown * Add StatsObsolete variable to torrent Indicating if: - They can be shown - They need to be updated * Update scraped data even if Unknown, prevent users from trying to fetch stats every seconds * Torrent file stored locally by default * no need to do all of that if no filestorage * fix filestorage path * Fix torrent download button stuck on "Generating torrent file" at rare times * fix some css rules that didn't work on IE * Fix panic error Seems like this error is a known bug from anacrolyx torrent https://github.com/anacrolix/torrent/issues/83 To prevent it, I'm creating a single client and modifying the socket.go to make it not raise a panic but a simple error log.
196 lignes
5,5 Kio
Go
196 lignes
5,5 Kio
Go
package roaring
|
|
|
|
import (
|
|
"container/heap"
|
|
)
|
|
|
|
// Or function that requires repairAfterLazy
|
|
func lazyOR(x1, x2 *Bitmap) *Bitmap {
|
|
answer := NewBitmap()
|
|
pos1 := 0
|
|
pos2 := 0
|
|
length1 := x1.highlowcontainer.size()
|
|
length2 := x2.highlowcontainer.size()
|
|
main:
|
|
for (pos1 < length1) && (pos2 < length2) {
|
|
s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
|
|
for {
|
|
if s1 < s2 {
|
|
answer.highlowcontainer.appendCopy(x1.highlowcontainer, pos1)
|
|
pos1++
|
|
if pos1 == length1 {
|
|
break main
|
|
}
|
|
s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
} else if s1 > s2 {
|
|
answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2)
|
|
pos2++
|
|
if pos2 == length2 {
|
|
break main
|
|
}
|
|
s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
} else {
|
|
|
|
answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getContainerAtIndex(pos1).lazyOR(x2.highlowcontainer.getContainerAtIndex(pos2)), false)
|
|
pos1++
|
|
pos2++
|
|
if (pos1 == length1) || (pos2 == length2) {
|
|
break main
|
|
}
|
|
s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
}
|
|
}
|
|
}
|
|
if pos1 == length1 {
|
|
answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
|
|
} else if pos2 == length2 {
|
|
answer.highlowcontainer.appendCopyMany(x1.highlowcontainer, pos1, length1)
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// In-place Or function that requires repairAfterLazy
|
|
func (x1 *Bitmap) lazyOR(x2 *Bitmap) *Bitmap {
|
|
answer := NewBitmap() // TODO: we return a new bitmap... could be optimized
|
|
pos1 := 0
|
|
pos2 := 0
|
|
length1 := x1.highlowcontainer.size()
|
|
length2 := x2.highlowcontainer.size()
|
|
main:
|
|
for (pos1 < length1) && (pos2 < length2) {
|
|
s1 := x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
|
|
for {
|
|
if s1 < s2 {
|
|
answer.highlowcontainer.appendWithoutCopy(x1.highlowcontainer, pos1)
|
|
pos1++
|
|
if pos1 == length1 {
|
|
break main
|
|
}
|
|
s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
} else if s1 > s2 {
|
|
answer.highlowcontainer.appendCopy(x2.highlowcontainer, pos2)
|
|
pos2++
|
|
if pos2 == length2 {
|
|
break main
|
|
}
|
|
s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
} else {
|
|
|
|
answer.highlowcontainer.appendContainer(s1, x1.highlowcontainer.getWritableContainerAtIndex(pos1).lazyIOR(x2.highlowcontainer.getContainerAtIndex(pos2)), false)
|
|
pos1++
|
|
pos2++
|
|
if (pos1 == length1) || (pos2 == length2) {
|
|
break main
|
|
}
|
|
s1 = x1.highlowcontainer.getKeyAtIndex(pos1)
|
|
s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
|
|
}
|
|
}
|
|
}
|
|
if pos1 == length1 {
|
|
answer.highlowcontainer.appendCopyMany(x2.highlowcontainer, pos2, length2)
|
|
} else if pos2 == length2 {
|
|
answer.highlowcontainer.appendWithoutCopyMany(x1.highlowcontainer, pos1, length1)
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// to be called after lazy aggregates
|
|
func (x1 *Bitmap) repairAfterLazy() {
|
|
for pos := 0; pos < x1.highlowcontainer.size(); pos++ {
|
|
c := x1.highlowcontainer.getContainerAtIndex(pos)
|
|
switch c.(type) {
|
|
case *bitmapContainer:
|
|
if c.(*bitmapContainer).cardinality == invalidCardinality {
|
|
c = x1.highlowcontainer.getWritableContainerAtIndex(pos)
|
|
c.(*bitmapContainer).computeCardinality()
|
|
if c.(*bitmapContainer).getCardinality() <= arrayDefaultMaxSize {
|
|
x1.highlowcontainer.setContainerAtIndex(pos, c.(*bitmapContainer).toArrayContainer())
|
|
} else if c.(*bitmapContainer).isFull() {
|
|
x1.highlowcontainer.setContainerAtIndex(pos, newRunContainer16Range(0, MaxUint16))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// FastAnd computes the intersection between many bitmaps quickly
|
|
// Compared to the And function, it can take many bitmaps as input, thus saving the trouble
|
|
// of manually calling "And" many times.
|
|
func FastAnd(bitmaps ...*Bitmap) *Bitmap {
|
|
if len(bitmaps) == 0 {
|
|
return NewBitmap()
|
|
} else if len(bitmaps) == 1 {
|
|
return bitmaps[0].Clone()
|
|
}
|
|
answer := And(bitmaps[0], bitmaps[1])
|
|
for _, bm := range bitmaps[2:] {
|
|
answer.And(bm)
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// FastOr computes the union between many bitmaps quickly, as opposed to having to call Or repeatedly.
|
|
// It might also be faster than calling Or repeatedly.
|
|
func FastOr(bitmaps ...*Bitmap) *Bitmap {
|
|
if len(bitmaps) == 0 {
|
|
return NewBitmap()
|
|
} else if len(bitmaps) == 1 {
|
|
return bitmaps[0].Clone()
|
|
}
|
|
answer := lazyOR(bitmaps[0], bitmaps[1])
|
|
for _, bm := range bitmaps[2:] {
|
|
answer = answer.lazyOR(bm)
|
|
}
|
|
// here is where repairAfterLazy is called.
|
|
answer.repairAfterLazy()
|
|
return answer
|
|
}
|
|
|
|
// HeapOr computes the union between many bitmaps quickly using a heap.
|
|
// It might be faster than calling Or repeatedly.
|
|
func HeapOr(bitmaps ...*Bitmap) *Bitmap {
|
|
if len(bitmaps) == 0 {
|
|
return NewBitmap()
|
|
}
|
|
// TODO: for better speed, we could do the operation lazily, see Java implementation
|
|
pq := make(priorityQueue, len(bitmaps))
|
|
for i, bm := range bitmaps {
|
|
pq[i] = &item{bm, i}
|
|
}
|
|
heap.Init(&pq)
|
|
|
|
for pq.Len() > 1 {
|
|
x1 := heap.Pop(&pq).(*item)
|
|
x2 := heap.Pop(&pq).(*item)
|
|
heap.Push(&pq, &item{Or(x1.value, x2.value), 0})
|
|
}
|
|
return heap.Pop(&pq).(*item).value
|
|
}
|
|
|
|
// HeapXor computes the symmetric difference between many bitmaps quickly (as opposed to calling Xor repeated).
|
|
// Internally, this function uses a heap.
|
|
// It might be faster than calling Xor repeatedly.
|
|
func HeapXor(bitmaps ...*Bitmap) *Bitmap {
|
|
if len(bitmaps) == 0 {
|
|
return NewBitmap()
|
|
}
|
|
|
|
pq := make(priorityQueue, len(bitmaps))
|
|
for i, bm := range bitmaps {
|
|
pq[i] = &item{bm, i}
|
|
}
|
|
heap.Init(&pq)
|
|
|
|
for pq.Len() > 1 {
|
|
x1 := heap.Pop(&pq).(*item)
|
|
x2 := heap.Pop(&pq).(*item)
|
|
heap.Push(&pq, &item{Xor(x1.value, x2.value), 0})
|
|
}
|
|
return heap.Pop(&pq).(*item).value
|
|
}
|