自定义pac

master
潘啟华 6 years ago
parent 2dec6bc0a5
commit ed40e9cec2
  1. 7
      PixivSearch/dao/bangumi.py
  2. 3
      PixivSearch/model/config.py
  3. 778
      PixivSearch/pac/CreatePacFile.py
  4. 16
      PixivSearch/pac/RuleManage.py
  5. 27
      PixivSearch/templates/addConfig.html
  6. 35
      PixivSearch/templates/pac/list.html
  7. 1
      PixivSearch/templates/pixiv/index.html
  8. 12
      PixivSearch/urls.py
  9. 52
      PixivSearch/view.py
  10. BIN
      mydatabase

@ -1,19 +1,14 @@
import _thread
import json
import math
import os
from concurrent import futures
from queue import Queue
import django
import requests
from bs4 import BeautifulSoup
from PixivSearch.settings import logger
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
django.setup()
from PixivSearch.model.config import mediaInfo, stat
from PixivSearch.settings import logger
current_mediaInfo = None

@ -41,3 +41,6 @@ class bangumi_list(models.Model):
title = models.CharField(max_length=128)
total_count = models.IntegerField()
trailer_aid = models.IntegerField()
class rule(models.Model):
regex=models.CharField(primary_key=True,max_length=128)

@ -0,0 +1,778 @@
# from PixivSearch.model.config import rule
import base64
import requests
from PixivSearch.model.config import rule
def create():
response = requests.get('https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt')
if response.status_code == 200:
gfwlistText = (str)(base64.b64decode(response.content).decode('utf-8'))
gfwlist=gfwlistText.split('\n')[1:]
pacScript= 'var proxy = "PROXY 127.0.0.1:1080;";\n' \
'var rules = [\n'
for line in gfwlist:
if len(line)>0 and not line.startswith('!'):
# print(line)
pacScript+='"'+line+'",\n'
for line in rule.objects.all():
pacScript+='"'+line.regex+'",\n'
# print(pacScript[:-2])
pacScript=pacScript[:-2]+'\n];\n' \
'function createDict()\n' \
'{\n' \
' var result = {};\n' \
' result.__proto__ = null;\n' \
' return result;\n' \
'}\n' \
'\n' \
'function getOwnPropertyDescriptor(obj, key)\n' \
'{\n' \
' if (obj.hasOwnProperty(key))\n' \
' {\n' \
' return obj[key];\n' \
' }\n' \
' return null;\n' \
'}\n' \
'\n' \
'function extend(subclass, superclass, definition)\n' \
'{\n' \
' if (Object.__proto__)\n' \
' {\n' \
' definition.__proto__ = superclass.prototype;\n' \
' subclass.prototype = definition;\n' \
' }\n' \
' else\n' \
' {\n' \
' var tmpclass = function(){}, ret;\n' \
' tmpclass.prototype = superclass.prototype;\n' \
' subclass.prototype = new tmpclass();\n' \
' subclass.prototype.constructor = superclass;\n' \
' for (var i in definition)\n' \
' {\n' \
' if (definition.hasOwnProperty(i))\n' \
' {\n' \
' subclass.prototype[i] = definition[i];\n' \
' }\n' \
' }\n' \
' }\n' \
'}\n' \
'\n' \
'function Filter(text)\n' \
'{\n' \
' this.text = text;\n' \
' this.subscriptions = [];\n' \
'}\n' \
'Filter.prototype = {\n' \
' text: null,\n' \
' subscriptions: null,\n' \
' toString: function()\n' \
' {\n' \
' return this.text;\n' \
' }\n' \
'};\n' \
'Filter.knownFilters = createDict();\n' \
'Filter.elemhideRegExp = /^([^\/\*\|\@"!]*?)#(\@)?(?:([\w\-]+|\*)((?:\([\w\-]+(?:[$^*]?=[^\(\)"]*)?\))*)|#([^{}]+))$/;\n' \
'Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)?$/;\n' \
'Filter.optionsRegExp = /\$(~?[\w\-]+(?:=[^,\s]+)?(?:,~?[\w\-]+(?:=[^,\s]+)?)*)$/;\n' \
'Filter.fromText = function(text)\n' \
'{\n' \
' if (text in Filter.knownFilters)\n' \
' {\n' \
' return Filter.knownFilters[text];\n' \
' }\n' \
' var ret;\n' \
' if (text.charAt(0) == "!")\n' \
' {\n' \
' ret = new CommentFilter(text);\n' \
' }\n' \
' else\n' \
' {\n' \
' ret = RegExpFilter.fromText(text);\n' \
' }\n' \
' Filter.knownFilters[ret.text] = ret;\n' \
' return ret;\n' \
'};\n' \
'\n' \
'function InvalidFilter(text, reason)\n' \
'{\n' \
' Filter.call(this, text);\n' \
' this.reason = reason;\n' \
'}\n' \
'extend(InvalidFilter, Filter, {\n' \
' reason: null\n' \
'});\n' \
'\n' \
'function CommentFilter(text)\n' \
'{\n' \
' Filter.call(this, text);\n' \
'}\n' \
'extend(CommentFilter, Filter, {\n' \
'});\n' \
'\n' \
'function ActiveFilter(text, domains)\n' \
'{\n' \
' Filter.call(this, text);\n' \
' this.domainSource = domains;\n' \
'}\n' \
'extend(ActiveFilter, Filter, {\n' \
' domainSource: null,\n' \
' domainSeparator: null,\n' \
' ignoreTrailingDot: true,\n' \
' domainSourceIsUpperCase: false,\n' \
' getDomains: function()\n' \
' {\n' \
' var prop = getOwnPropertyDescriptor(this, "domains");\n' \
' if (prop)\n' \
' {\n' \
' return prop;\n' \
' }\n' \
' var domains = null;\n' \
' if (this.domainSource)\n' \
' {\n' \
' var source = this.domainSource;\n' \
' if (!this.domainSourceIsUpperCase)\n' \
' {\n' \
' source = source.toUpperCase();\n' \
' }\n' \
' var list = source.split(this.domainSeparator);\n' \
' if (list.length == 1 && (list[0]).charAt(0) != "~")\n' \
' {\n' \
' domains = createDict();\n' \
' domains[""] = false;\n' \
' if (this.ignoreTrailingDot)\n' \
' {\n' \
' list[0] = list[0].replace(/\.+$/, "");\n' \
' }\n' \
' domains[list[0]] = true;\n' \
' }\n' \
' else\n' \
' {\n' \
' var hasIncludes = false;\n' \
' for (var i = 0; i < list.length; i++)\n' \
' {\n' \
' var domain = list[i];\n' \
' if (this.ignoreTrailingDot)\n' \
' {\n' \
' domain = domain.replace(/\.+$/, "");\n' \
' }\n' \
' if (domain == "")\n' \
' {\n' \
' continue;\n' \
' }\n' \
' var include;\n' \
' if (domain.charAt(0) == "~")\n' \
' {\n' \
' include = false;\n' \
' domain = domain.substr(1);\n' \
' }\n' \
' else\n' \
' {\n' \
' include = true;\n' \
' hasIncludes = true;\n' \
' }\n' \
' if (!domains)\n' \
' {\n' \
' domains = createDict();\n' \
' }\n' \
' domains[domain] = include;\n' \
' }\n' \
' domains[""] = !hasIncludes;\n' \
' }\n' \
' this.domainSource = null;\n' \
' }\n' \
' return this.domains;\n' \
' },\n' \
' sitekeys: null,\n' \
' isActiveOnDomain: function(docDomain, sitekey)\n' \
' {\n' \
' if (this.getSitekeys() && (!sitekey || this.getSitekeys().indexOf(sitekey.toUpperCase()) < 0))\n' \
' {\n' \
' return false;\n' \
' }\n' \
' if (!this.getDomains())\n' \
' {\n' \
' return true;\n' \
' }\n' \
' if (!docDomain)\n' \
' {\n' \
' return this.getDomains()[""];\n' \
' }\n' \
' if (this.ignoreTrailingDot)\n' \
' {\n' \
' docDomain = docDomain.replace(/\.+$/, "");\n' \
' }\n' \
' docDomain = docDomain.toUpperCase();\n' \
' while (true)\n' \
' {\n' \
' if (docDomain in this.getDomains())\n' \
' {\n' \
' return this.domains[docDomain];\n' \
' }\n' \
' var nextDot = docDomain.indexOf(".");\n' \
' if (nextDot < 0)\n' \
' {\n' \
' break;\n' \
' }\n' \
' docDomain = docDomain.substr(nextDot + 1);\n' \
' }\n' \
' return this.domains[""];\n' \
' },\n' \
' isActiveOnlyOnDomain: function(docDomain)\n' \
' {\n' \
' if (!docDomain || !this.getDomains() || this.getDomains()[""])\n' \
' {\n' \
' return false;\n' \
' }\n' \
' if (this.ignoreTrailingDot)\n' \
' {\n' \
' docDomain = docDomain.replace(/\.+$/, "");\n' \
' }\n' \
' docDomain = docDomain.toUpperCase();\n' \
' for (var domain in this.getDomains())\n' \
' {\n' \
' if (this.domains[domain] && domain != docDomain && (domain.length <= docDomain.length || domain.indexOf("." + docDomain) != domain.length - docDomain.length - 1))\n' \
' {\n' \
' return false;\n' \
' }\n' \
' }\n' \
' return true;\n' \
' }\n' \
'});\n' \
'\n' \
'function RegExpFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys)\n' \
'{\n' \
' ActiveFilter.call(this, text, domains, sitekeys);\n' \
' if (contentType != null)\n' \
' {\n' \
' this.contentType = contentType;\n' \
' }\n' \
' if (matchCase)\n' \
' {\n' \
' this.matchCase = matchCase;\n' \
' }\n' \
' if (thirdParty != null)\n' \
' {\n' \
' this.thirdParty = thirdParty;\n' \
' }\n' \
' if (sitekeys != null)\n' \
' {\n' \
' this.sitekeySource = sitekeys;\n' \
' }\n' \
' if (regexpSource.length >= 2 && regexpSource.charAt(0) == "/" && regexpSource.charAt(regexpSource.length - 1) == "/")\n' \
' {\n' \
' var regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), this.matchCase ? "" : "i");\n' \
' this.regexp = regexp;\n' \
' }\n' \
' else\n' \
' {\n' \
' this.regexpSource = regexpSource;\n' \
' }\n' \
'}\n' \
'extend(RegExpFilter, ActiveFilter, {\n' \
' domainSourceIsUpperCase: true,\n' \
' length: 1,\n' \
' domainSeparator: "|",\n' \
' regexpSource: null,\n' \
' getRegexp: function()\n' \
' {\n' \
' var prop = getOwnPropertyDescriptor(this, "regexp");\n' \
' if (prop)\n' \
' {\n' \
' return prop;\n' \
' }\n' \
' var source = this.regexpSource.replace(/\*+/g, "*").replace(/\^\|$/, "^").replace(/\W/g, "\\$&").replace(/\\\*/g, ".*").replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]|$)").replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?").replace(/^\\\|/, "^").replace(/\\\|$/, "$").replace(/^(\.\*)/, "").replace(/(\.\*)$/, "");\n' \
' var regexp = new RegExp(source, this.matchCase ? "" : "i");\n' \
' this.regexp = regexp;\n' \
' return regexp;\n' \
' },\n' \
' contentType: 2147483647,\n' \
' matchCase: false,\n' \
' thirdParty: null,\n' \
' sitekeySource: null,\n' \
' getSitekeys: function()\n' \
' {\n' \
' var prop = getOwnPropertyDescriptor(this, "sitekeys");\n' \
' if (prop)\n' \
' {\n' \
' return prop;\n' \
' }\n' \
' var sitekeys = null;\n' \
' if (this.sitekeySource)\n' \
' {\n' \
' sitekeys = this.sitekeySource.split("|");\n' \
' this.sitekeySource = null;\n' \
' }\n' \
' this.sitekeys = sitekeys;\n' \
' return this.sitekeys;\n' \
' },\n' \
' matches: function(location, contentType, docDomain, thirdParty, sitekey)\n' \
' {\n' \
' if (this.getRegexp().test(location) && this.isActiveOnDomain(docDomain, sitekey))\n' \
' {\n' \
' return true;\n' \
' }\n' \
' return false;\n' \
' }\n' \
'});\n' \
'RegExpFilter.prototype["0"] = "#this";\n' \
'RegExpFilter.fromText = function(text)\n' \
'{\n' \
' var blocking = true;\n' \
' var origText = text;\n' \
' if (text.indexOf("@@") == 0)\n' \
' {\n' \
' blocking = false;\n' \
' text = text.substr(2);\n' \
' }\n' \
' var contentType = null;\n' \
' var matchCase = null;\n' \
' var domains = null;\n' \
' var sitekeys = null;\n' \
' var thirdParty = null;\n' \
' var collapse = null;\n' \
' var options;\n' \
' var match = text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null;\n' \
' if (match)\n' \
' {\n' \
' options = match[1].toUpperCase().split(",");\n' \
' text = match.input.substr(0, match.index);\n' \
' for (var _loopIndex6 = 0; _loopIndex6 < options.length; ++_loopIndex6)\n' \
' {\n' \
' var option = options[_loopIndex6];\n' \
' var value = null;\n' \
' var separatorIndex = option.indexOf("=");\n' \
' if (separatorIndex >= 0)\n' \
' {\n' \
' value = option.substr(separatorIndex + 1);\n' \
' option = option.substr(0, separatorIndex);\n' \
' }\n' \
' option = option.replace(/-/, "_");\n' \
' if (option in RegExpFilter.typeMap)\n' \
' {\n' \
' if (contentType == null)\n' \
' {\n' \
' contentType = 0;\n' \
' }\n' \
' contentType |= RegExpFilter.typeMap[option];\n' \
' }\n' \
' else if (option.charAt(0) == "~" && option.substr(1) in RegExpFilter.typeMap)\n' \
' {\n' \
' if (contentType == null)\n' \
' {\n' \
' contentType = RegExpFilter.prototype.contentType;\n' \
' }\n' \
' contentType &= ~RegExpFilter.typeMap[option.substr(1)];\n' \
' }\n' \
' else if (option == "MATCH_CASE")\n' \
' {\n' \
' matchCase = true;\n' \
' }\n' \
' else if (option == "~MATCH_CASE")\n' \
' {\n' \
' matchCase = false;\n' \
' }\n' \
' else if (option == "DOMAIN" && typeof value != "undefined")\n' \
' {\n' \
' domains = value;\n' \
' }\n' \
' else if (option == "THIRD_PARTY")\n' \
' {\n' \
' thirdParty = true;\n' \
' }\n' \
' else if (option == "~THIRD_PARTY")\n' \
' {\n' \
' thirdParty = false;\n' \
' }\n' \
' else if (option == "COLLAPSE")\n' \
' {\n' \
' collapse = true;\n' \
' }\n' \
' else if (option == "~COLLAPSE")\n' \
' {\n' \
' collapse = false;\n' \
' }\n' \
' else if (option == "SITEKEY" && typeof value != "undefined")\n' \
' {\n' \
' sitekeys = value;\n' \
' }\n' \
' else\n' \
' {\n' \
' return new InvalidFilter(origText, "Unknown option " + option.toLowerCase());\n' \
' }\n' \
' }\n' \
' }\n' \
' if (!blocking && (contentType == null || contentType & RegExpFilter.typeMap.DOCUMENT) && (!options || options.indexOf("DOCUMENT") < 0) && !/^\|?[\w\-]+:/.test(text))\n' \
' {\n' \
' if (contentType == null)\n' \
' {\n' \
' contentType = RegExpFilter.prototype.contentType;\n' \
' }\n' \
' contentType &= ~RegExpFilter.typeMap.DOCUMENT;\n' \
' }\n' \
' try\n' \
' {\n' \
' if (blocking)\n' \
' {\n' \
' return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse);\n' \
' }\n' \
' else\n' \
' {\n' \
' return new WhitelistFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys);\n' \
' }\n' \
' }\n' \
' catch (e)\n' \
' {\n' \
' return new InvalidFilter(origText, e);\n' \
' }\n' \
'};\n' \
'RegExpFilter.typeMap = {\n' \
' OTHER: 1,\n' \
' SCRIPT: 2,\n' \
' IMAGE: 4,\n' \
' STYLESHEET: 8,\n' \
' OBJECT: 16,\n' \
' SUBDOCUMENT: 32,\n' \
' DOCUMENT: 64,\n' \
' XBL: 1,\n' \
' PING: 1,\n' \
' XMLHTTPREQUEST: 2048,\n' \
' OBJECT_SUBREQUEST: 4096,\n' \
' DTD: 1,\n' \
' MEDIA: 16384,\n' \
' FONT: 32768,\n' \
' BACKGROUND: 4,\n' \
' POPUP: 268435456,\n' \
' ELEMHIDE: 1073741824\n' \
'};\n' \
'RegExpFilter.prototype.contentType &= ~ (RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP);\n' \
'\n' \
'function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys, collapse)\n' \
'{\n' \
' RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys);\n' \
' this.collapse = collapse;\n' \
'}\n' \
'extend(BlockingFilter, RegExpFilter, {\n' \
' collapse: null\n' \
'});\n' \
'\n' \
'function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys)\n' \
'{\n' \
' RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, thirdParty, sitekeys);\n' \
'}\n' \
'extend(WhitelistFilter, RegExpFilter, {\n' \
'});\n' \
'\n' \
'function Matcher()\n' \
'{\n' \
' this.clear();\n' \
'}\n' \
'Matcher.prototype = {\n' \
' filterByKeyword: null,\n' \
' keywordByFilter: null,\n' \
' clear: function()\n' \
' {\n' \
' this.filterByKeyword = createDict();\n' \
' this.keywordByFilter = createDict();\n' \
' },\n' \
' add: function(filter)\n' \
' {\n' \
' if (filter.text in this.keywordByFilter)\n' \
' {\n' \
' return;\n' \
' }\n' \
' var keyword = this.findKeyword(filter);\n' \
' var oldEntry = this.filterByKeyword[keyword];\n' \
' if (typeof oldEntry == "undefined")\n' \
' {\n' \
' this.filterByKeyword[keyword] = filter;\n' \
' }\n' \
' else if (oldEntry.length == 1)\n' \
' {\n' \
' this.filterByKeyword[keyword] = [oldEntry, filter];\n' \
' }\n' \
' else\n' \
' {\n' \
' oldEntry.push(filter);\n' \
' }\n' \
' this.keywordByFilter[filter.text] = keyword;\n' \
' },\n' \
' remove: function(filter)\n' \
' {\n' \
' if (!(filter.text in this.keywordByFilter))\n' \
' {\n' \
' return;\n' \
' }\n' \
' var keyword = this.keywordByFilter[filter.text];\n' \
' var list = this.filterByKeyword[keyword];\n' \
' if (list.length <= 1)\n' \
' {\n' \
' delete this.filterByKeyword[keyword];\n' \
' }\n' \
' else\n' \
' {\n' \
' var index = list.indexOf(filter);\n' \
' if (index >= 0)\n' \
' {\n' \
' list.splice(index, 1);\n' \
' if (list.length == 1)\n' \
' {\n' \
' this.filterByKeyword[keyword] = list[0];\n' \
' }\n' \
' }\n' \
' }\n' \
' delete this.keywordByFilter[filter.text];\n' \
' },\n' \
' findKeyword: function(filter)\n' \
' {\n' \
' var result = "";\n' \
' var text = filter.text;\n' \
' if (Filter.regexpRegExp.test(text))\n' \
' {\n' \
' return result;\n' \
' }\n' \
' var match = Filter.optionsRegExp.exec(text);\n' \
' if (match)\n' \
' {\n' \
' text = match.input.substr(0, match.index);\n' \
' }\n' \
' if (text.substr(0, 2) == "@@")\n' \
' {\n' \
' text = text.substr(2);\n' \
' }\n' \
' var candidates = text.toLowerCase().match(/[^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0-9%*])/g);\n' \
' if (!candidates)\n' \
' {\n' \
' return result;\n' \
' }\n' \
' var hash = this.filterByKeyword;\n' \
' var resultCount = 16777215;\n' \
' var resultLength = 0;\n' \
' for (var i = 0, l = candidates.length; i < l; i++)\n' \
' {\n' \
' var candidate = candidates[i].substr(1);\n' \
' var count = candidate in hash ? hash[candidate].length : 0;\n' \
' if (count < resultCount || count == resultCount && candidate.length > resultLength)\n' \
' {\n' \
' result = candidate;\n' \
' resultCount = count;\n' \
' resultLength = candidate.length;\n' \
' }\n' \
' }\n' \
' return result;\n' \
' },\n' \
' hasFilter: function(filter)\n' \
' {\n' \
' return filter.text in this.keywordByFilter;\n' \
' },\n' \
' getKeywordForFilter: function(filter)\n' \
' {\n' \
' if (filter.text in this.keywordByFilter)\n' \
' {\n' \
' return this.keywordByFilter[filter.text];\n' \
' }\n' \
' else\n' \
' {\n' \
' return null;\n' \
' }\n' \
' },\n' \
' _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty, sitekey)\n' \
' {\n' \
' var list = this.filterByKeyword[keyword];\n' \
' for (var i = 0; i < list.length; i++)\n' \
' {\n' \
' var filter = list[i];\n' \
' if (filter == "#this")\n' \
' {\n' \
' filter = list;\n' \
' }\n' \
' if (filter.matches(location, contentType, docDomain, thirdParty, sitekey))\n' \
' {\n' \
' return filter;\n' \
' }\n' \
' }\n' \
' return null;\n' \
' },\n' \
' matchesAny: function(location, contentType, docDomain, thirdParty, sitekey)\n' \
' {\n' \
' var candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);\n' \
' if (candidates === null)\n' \
' {\n' \
' candidates = [];\n' \
' }\n' \
' candidates.push("");\n' \
' for (var i = 0, l = candidates.length; i < l; i++)\n' \
' {\n' \
' var substr = candidates[i];\n' \
' if (substr in this.filterByKeyword)\n' \
' {\n' \
' var result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);\n' \
' if (result)\n' \
' {\n' \
' return result;\n' \
' }\n' \
' }\n' \
' }\n' \
' return null;\n' \
' }\n' \
'};\n' \
'\n' \
'function CombinedMatcher()\n' \
'{\n' \
' this.blacklist = new Matcher();\n' \
' this.whitelist = new Matcher();\n' \
' this.resultCache = createDict();\n' \
'}\n' \
'CombinedMatcher.maxCacheEntries = 1000;\n' \
'CombinedMatcher.prototype = {\n' \
' blacklist: null,\n' \
' whitelist: null,\n' \
' resultCache: null,\n' \
' cacheEntries: 0,\n' \
' clear: function()\n' \
' {\n' \
' this.blacklist.clear();\n' \
' this.whitelist.clear();\n' \
' this.resultCache = createDict();\n' \
' this.cacheEntries = 0;\n' \
' },\n' \
' add: function(filter)\n' \
' {\n' \
' if (filter instanceof WhitelistFilter)\n' \
' {\n' \
' this.whitelist.add(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' this.blacklist.add(filter);\n' \
' }\n' \
' if (this.cacheEntries > 0)\n' \
' {\n' \
' this.resultCache = createDict();\n' \
' this.cacheEntries = 0;\n' \
' }\n' \
' },\n' \
' remove: function(filter)\n' \
' {\n' \
' if (filter instanceof WhitelistFilter)\n' \
' {\n' \
' this.whitelist.remove(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' this.blacklist.remove(filter);\n' \
' }\n' \
' if (this.cacheEntries > 0)\n' \
' {\n' \
' this.resultCache = createDict();\n' \
' this.cacheEntries = 0;\n' \
' }\n' \
' },\n' \
' findKeyword: function(filter)\n' \
' {\n' \
' if (filter instanceof WhitelistFilter)\n' \
' {\n' \
' return this.whitelist.findKeyword(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' return this.blacklist.findKeyword(filter);\n' \
' }\n' \
' },\n' \
' hasFilter: function(filter)\n' \
' {\n' \
' if (filter instanceof WhitelistFilter)\n' \
' {\n' \
' return this.whitelist.hasFilter(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' return this.blacklist.hasFilter(filter);\n' \
' }\n' \
' },\n' \
' getKeywordForFilter: function(filter)\n' \
' {\n' \
' if (filter instanceof WhitelistFilter)\n' \
' {\n' \
' return this.whitelist.getKeywordForFilter(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' return this.blacklist.getKeywordForFilter(filter);\n' \
' }\n' \
' },\n' \
' isSlowFilter: function(filter)\n' \
' {\n' \
' var matcher = filter instanceof WhitelistFilter ? this.whitelist : this.blacklist;\n' \
' if (matcher.hasFilter(filter))\n' \
' {\n' \
' return !matcher.getKeywordForFilter(filter);\n' \
' }\n' \
' else\n' \
' {\n' \
' return !matcher.findKeyword(filter);\n' \
' }\n' \
' },\n' \
' matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sitekey)\n' \
' {\n' \
' var candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);\n' \
' if (candidates === null)\n' \
' {\n' \
' candidates = [];\n' \
' }\n' \
' candidates.push("");\n' \
' var blacklistHit = null;\n' \
' for (var i = 0, l = candidates.length; i < l; i++)\n' \
' {\n' \
' var substr = candidates[i];\n' \
' if (substr in this.whitelist.filterByKeyword)\n' \
' {\n' \
' var result = this.whitelist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);\n' \
' if (result)\n' \
' {\n' \
' return result;\n' \
' }\n' \
' }\n' \
' if (substr in this.blacklist.filterByKeyword && blacklistHit === null)\n' \
' {\n' \
' blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);\n' \
' }\n' \
' }\n' \
' return blacklistHit;\n' \
' },\n' \
' matchesAny: function(location, docDomain)\n' \
' {\n' \
' var key = location + " " + docDomain + " ";\n' \
' if (key in this.resultCache)\n' \
' {\n' \
' return this.resultCache[key];\n' \
' }\n' \
' var result = this.matchesAnyInternal(location, 0, docDomain, null, null);\n' \
' if (this.cacheEntries >= CombinedMatcher.maxCacheEntries)\n' \
' {\n' \
' this.resultCache = createDict();\n' \
' this.cacheEntries = 0;\n' \
' }\n' \
' this.resultCache[key] = result;\n' \
' this.cacheEntries++;\n' \
' return result;\n' \
' }\n' \
'};\n' \
'var defaultMatcher = new CombinedMatcher();\n' \
'\n' \
'var direct = \'DIRECT;\';\n' \
'\n' \
'for (var i = 0; i < rules.length; i++) {\n' \
' defaultMatcher.add(Filter.fromText(rules[i]));\n' \
'}\n' \
'\n' \
'function FindProxyForURL(url, host) {\n' \
' if (defaultMatcher.matchesAny(url, host) instanceof BlockingFilter) {\n' \
' return proxy;\n' \
' }\n' \
' return direct;\n' \
'}\n'
return pacScript
if __name__ == '__main__':
print(create())

@ -0,0 +1,16 @@
from PixivSearch.model.config import rule
def insert(value):
rule(regex=value).save()
def delete(value):
select(value).delete()
def select(value=None):
if value == None:
return rule.objects.all()
else:
return rule.objects.filter(regex=value)

@ -1,27 +0,0 @@
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>参数管理</title>
{% load staticfiles %}
<script src="{% static "js/jquery-3.2.1.min.js"%}"></script>
<script>
$(function () {
$("button").click(function(){
$("form").attr("method",$(this).attr("id")).submit();
});
})
</script>
</head>
<body>
<form action="/tsdm">
{% csrf_token %}
<label>参数名<input name="param_name" value="{{param_name}}"/></label>
<label>参数值<input name="param_value" value="{{param_value}}"/></label>
<div>
<button id="POST">设置</button>
<button id="GET">获取</button>
</div>
</form>
</body>
</html>

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</head>
<body>
<table class="table">
<thead>
<tr>
<th scope="col">规则</th>
<th scope="col">操作</th>
</tr>
</thead>
<tbody>
{% for rule in rules %}
<tr>
<td>{{ rule.regex }}</td>
<td>删除</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

@ -14,7 +14,6 @@
}
</style>
{% load staticfiles %}
<script src="{% static "js/jquery-3.2.1.min.js" %}"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"

@ -14,15 +14,15 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from PixivSearch.view import search, index, download, saveConfig, get, start, stop, migu
from PixivSearch.view import search, index, download, get, start, stop, migu,pac
urlpatterns = [
url(r'^$', index),
url(r'^pixiv/search', search),
url(r'^pixiv/download', download),
url(r'^tsdm', saveConfig),
url(r'^bangumi/get', get),
url(r'^bangumi/start', start),
url(r'^bangumi/stop', stop),
url(r'^migu',migu)
url(r'^bangumi/get$', get),
url(r'^bangumi/start$', start),
url(r'^bangumi/stop$', stop),
url(r'^migu$',migu),
url(r'^pac$',pac)
]

@ -3,19 +3,16 @@ import _thread
import json
import os
import django
from django.http import Http404, StreamingHttpResponse, HttpResponse
from django.shortcuts import render
import root
from PixivSearch.dao.bangumi import get_, stop_, getIds
from PixivSearch.migu import GetVideoUrl
from PixivSearch.pac import CreatePacFile
from PixivSearch.pixiv.pixiv import get_nodes
from PixivSearch.settings import logger
from PixivSearch.migu import GetVideoUrl
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PixivSearch.settings")
django.setup() # 添加的代码
from PixivSearch.model import config
from PixivSearch.pac import RuleManage
def search(request):
@ -24,13 +21,13 @@ def search(request):
order = 10
type = 'text'
if request.POST.get('word') != '' and request.POST.get('word') is not None:
if request.POST.get('word') is not None and len(request.POST.get('word')) > 0:
word = request.POST.get('word')
if request.POST.get('pageSize') != '' and request.POST.get('pageSize') is not None:
if request.POST.get('pageSize') is not None and request.POST.get('pageSize') > 0:
pageSize = int(request.POST.get('pageSize'))
if request.POST.get('order') != '' and request.POST.get('order') is not None:
if request.POST.get('order') is not None and len(request.POST.get('order') != '') > 0:
order = int(request.POST.get('order'))
if request.POST.get('type') != '' and request.POST.get('type') is not None:
if request.POST.get('type') is not None and len(request.POST.get('type')) > 0:
type = request.POST.get('type')
try:
@ -47,19 +44,36 @@ def search(request):
'type': type}
else:
nodes = {'tip': '没有返回结果'}
return render(request, 'index.html', nodes)
return render(request, 'pixiv/index.html', nodes)
except ValueError:
raise Http404()
def migu(request):
if request.GET.get('playurl') != '' and request.GET.get('playurl') is not None:
result = GetVideoUrl.getUrl(request.GET.get('playurl'))
else:
result={'参数不能为空'}
result = {'error': '参数不能为空'}
return HttpResponse(json.dumps(result, ensure_ascii=False), content_type='application/json', charset='utf-8')
def pac(request):
action = request.GET.get('action')
value = request.GET.get('value')
if action == 'create':
return HttpResponse(CreatePacFile.create(), content_type='application/x-ns-proxy-autoconfig', charset='utf-8')
else:
if action == 'insert' and value != None and len(value) > 0:
RuleManage.insert(value)
elif action == 'select' and value != None and len(value) > 0:
return render(request, 'pac/list.html', {'rules':RuleManage.select(value)})
elif action == 'delete' and value != None and len(value) > 0:
RuleManage.delete(value)
return render(request, 'pac/list.html', {'rules':RuleManage.select()})
def index(request):
return render(request, 'index.html', {'tip': '输入参数进行搜索'})
return render(request, 'pixiv/index.html', {'tip': '输入参数进行搜索'})
def download(request):
@ -81,18 +95,6 @@ def download(request):
return response
def saveConfig(request):
if 'GET' == request.method and request.GET.get('param_name'):
p = config.param.objects.get(param_name=request.GET.get('param_name'))
return render(request, 'addConfig.html', p.__dict__)
elif 'POST' == request.method and request.POST.get('param_name') and request.POST.get('param_value'):
p = config.param(param_name=request.POST.get('param_name'), param_value=request.POST.get('param_value'))
p.save()
return render(request, 'addConfig.html', p.__dict__)
else:
return render(request, 'addConfig.html')
def get(request):
return HttpResponse(str(get_().__str__()))

Binary file not shown.
Loading…
Cancel
Save