-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9fccb4
commit dd2a881
Showing
9 changed files
with
177 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module BiliFile | ||
|
||
require 'fileutils' | ||
|
||
def biliMove(file, newfile=file, condition) | ||
|
||
tmp = file + ".tmp" | ||
|
||
open(file, 'r') do |f0| | ||
open(tmp, 'w') do |f1| | ||
f0.each_line do |line| | ||
|
||
status = true | ||
code = eval(condition) | ||
|
||
if code != nil then | ||
if code == false then | ||
status = false | ||
else | ||
if code != true then | ||
if code > 0 then | ||
status = true | ||
else | ||
status = false | ||
end | ||
else | ||
status = true | ||
end | ||
end | ||
else | ||
status = false | ||
end | ||
|
||
f1.write(line) if status | ||
end | ||
end | ||
end | ||
|
||
if newfile == file then | ||
oldfile = file + ".old" | ||
FileUtils.mv file, oldfile | ||
end | ||
|
||
FileUtils.mv tmp, newfile | ||
|
||
end | ||
|
||
def biliTouch(file="") | ||
open(file, 'w').close | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/ruby | ||
|
||
module BiliWeb | ||
|
||
require 'open-uri' | ||
require_relative 'BiliConfig' | ||
|
||
class BiliFetch | ||
|
||
include BiliConfig | ||
include BiliFile | ||
|
||
def initialize(url) | ||
@url = url | ||
@cachePath = File.join($configPath,"cache") | ||
unless Dir.exists?(@cachePath) then | ||
Dir.mkdir(@cachePath) | ||
end | ||
@filename = @cachePath + "/" + @url.gsub(/http:\/\//,"") + ".html" | ||
end | ||
|
||
def get | ||
content = open(@url).read | ||
io = File.open(@filename, "w") | ||
io.puts(content) | ||
io.close | ||
end | ||
|
||
def clean(filename="#{@filename}") | ||
|
||
if filename.index("bilibili.tv.html") then | ||
|
||
biliMove(filename,"line.index('/video/') && ! line.index('av271')") | ||
|
||
else | ||
p "[WARN] Don't know what to do!" | ||
end | ||
|
||
end | ||
|
||
def format | ||
end | ||
|
||
def indexLevels | ||
indexFile = @cachePath + "/bilibili.tv.html" | ||
indexLevel1 = indexFile + ".level1" | ||
indexLevel2 = indexFile + ".level2" | ||
|
||
biliMove(indexFile,indexLevel1,"line.index('i-link')") | ||
biliMove(indexFile,indexLevel2,"! line.index('i-link')") | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
# Test code below | ||
|
||
#class Test | ||
# include BiliWeb | ||
|
||
# def initialize(url) | ||
#@url = url | ||
# end | ||
|
||
# def get | ||
# BiliFetch.new(@url).get | ||
# BiliFetch.new(@url).clean | ||
# BiliFetch.new(@url).indexLevels | ||
# end | ||
|
||
#end | ||
|
||
#Test.new("http://bilibili.tv").get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.