Skip to content

Commit

Permalink
release v0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Nov 16, 2014
1 parent c9fccb4 commit dd2a881
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 46 deletions.
33 changes: 11 additions & 22 deletions BiliConfig.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module BiliConfig

class Biliconf
require_relative 'BiliFile'

class BiliConf

include BiliFile

$userHome = `echo $HOME`.gsub(/\n/,"")
$configPath = File.join($userHome,".config/BiliGui")
Expand All @@ -19,8 +23,7 @@ def initialize(name="biligui.conf", path=$configPath)
@configEntries = {}

unless File.exists?(@config) then
io = File.open(@config, "w")
io.close
biliTouch(@config)
else
io = File.open(@config, "r")
io.each_line do |line|
Expand All @@ -34,28 +37,14 @@ def initialize(name="biligui.conf", path=$configPath)

end

def writeNewConfig(key, value)
def write(key, value)
configKey = key
configValue = value

# if Key exists, then we should delete
if @configEntries.key?(configKey) then

require 'fileutils'

tmpfile = @config + ".tmp"
oldfile = @config + ".old"

open(@config, 'r') do |f0|
open(tmpfile, 'w') do |f1|
f0.each_line do |line|
f1.write(line) unless line.index(configKey)
end
end
end

FileUtils.mv @config, oldfile
FileUtils.mv tmpfile, @config
if @configEntries.key?(configKey) then

billMove(@config,"! line.index(configKey)")

end

Expand All @@ -64,7 +53,7 @@ def writeNewConfig(key, value)
io.close
end

def loadConfigs
def load
return @configEntries
end

Expand Down
52 changes: 52 additions & 0 deletions BiliFile.rb
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
24 changes: 14 additions & 10 deletions BiliPlaylist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def initialize(videos="")
@videos = videos
@videosHash = {}

videosSplit
split
end

def videosSplit
def split

unless @videos.empty? then

Expand Down Expand Up @@ -50,9 +50,9 @@ def save(filename="")
old_playlist = playlist + ".old"

if File.exist?(playlist) then
FileUtils.mv playlist, old_playlist
mv playlist, old_playlist
else
io = File.open(playlist,"w")
io = open(playlist,"w")
io.puts "#EXTM3U"

@videosHash.to_a.each do |video|
Expand All @@ -66,7 +66,7 @@ def save(filename="")

def load(playlist="")

playlistHash = {}
hash = {}

default_playlist = "#{$configPath}/biliplaylist.m3u8"

Expand All @@ -79,9 +79,9 @@ def load(playlist="")
p "[ERR] No playlist available!"
else

io = File.open(playlist, 'r')
io = open(playlist, 'r')

validArray = []
array = []
i = 0

io.each_line do |line|
Expand All @@ -97,19 +97,23 @@ def load(playlist="")
unless line.index("bilibili") then
p "#{line} doesn't seem to be a Bilibili URL!"
else
p line
validArray[i] = line
value = line
key = "av" + line.gsub(/^.*\/av/,"").gsub(/\//,"")
hash[key] = value
array[i] = line
end

end

if validArray.empty? then
if array.empty? then
p "This playlist has no URL we support!"
end

io.close
end

return hash

end

end
Expand Down
75 changes: 75 additions & 0 deletions BiliWeb.rb
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
28 changes: 17 additions & 11 deletions BiliWidgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
class BiliGuiConfig

include BiliConfig
@@config = Biliconf.new
@@config = BiliConf.new

def put(key,value)
confKey = key
confValue = value
@@config.writeNewConfig(confKey,confValue)
@@config.write(confKey,confValue)
end

def load
@@config.loadConfigs()
@@config.load
end

end
Expand Down Expand Up @@ -64,8 +64,8 @@ def initialize
super

setWindowTitle "BiliGui"

setWindowIcon(Qt::Icon.new("bilibili.svgz"))
#setStyleSheet "QWidget {color: #ff3d6a;}"

init_ui

Expand Down Expand Up @@ -98,8 +98,12 @@ def init_ui
biliTabs.addTab webTab, "Bilibili.tv"
biliTabs.addTab settingsTab, "BiliGui Settings"

@messageLabel = Qt::Label.new ""
@messageLabel.setStyleSheet("color: #ff0000;")

grid_biliTabs = Qt::GridLayout.new self
grid_biliTabs.addWidget biliTabs, 0, 0, 1, 1
grid_biliTabs.addWidget @messageLabel, 1, 0, 1, 1
grid_biliTabs.setColumnStretch 0, 0

# Playlist Tab
Expand All @@ -108,8 +112,6 @@ def init_ui
biliUrlLabel = Qt::Label.new "Please paste Bilibili URL below", playlistTab
biliWebButton = Qt::PushButton.new 'Visit bilibili.tv (experimental)', playlistTab
@urlArea = Qt::TextEdit.new playlistTab
@messageLabel = Qt::Label.new "", playlistTab
@messageLabel.setStyleSheet("color: #ff0000;")
ctlPanel = Qt::Widget.new playlistTab
okButton = Qt::PushButton.new 'Play', playlistTab
clearButton = Qt::PushButton.new 'Clear', playlistTab
Expand All @@ -118,7 +120,6 @@ def init_ui
grid_Playlist.addWidget biliWebButton, 0, 1, 1, 1
grid_Playlist.addWidget @urlArea, 1, 0, 1, 4
grid_Playlist.addWidget ctlPanel, 1, 4, 1, 1
grid_Playlist.addWidget @messageLabel, 2, 0, 1, 2
grid_Playlist.addWidget okButton, 2, 2, 1, 1
grid_Playlist.addWidget clearButton, 2, 3, 1, 1
grid_Playlist.setColumnStretch 0, 0
Expand Down Expand Up @@ -186,12 +187,12 @@ def bilidan
command = "#{pathText} #{hashvalue}"
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stderr.each_line do |line|
# 99% is a common error can safely ignore
unless line.index("99%") then
# common error
unless line.index("Cache") then
@messageLabel.setText(line)
end

stdout.each_line {|line| p line}
#stdout.each_line {|line| p line}

end

Expand Down Expand Up @@ -235,7 +236,12 @@ def biliWeb
def biliLoad
playlist = Qt::FileDialog.getOpenFileName(self, "Please choose your playlist", "#{$configPath}", "Playlist file (*.m3u8)")
unless playlist == nil then
BiliGuiPlaylist.new.load(playlist)
hash = BiliGuiPlaylist.new.load(playlist)
str = ""
hash.each_value do |value|
str += value + "\n"
end
@urlArea.setText(str)
end
end

Expand Down
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.0.6
* fix: forgot to have BiliPlaylist::BiliLoad functional
* initialize BiliWeb module, handling communication w/ bilibili.tv
* split common file functions to BiliFile module
* logo: add drop shadow
0.0.5
* switch to Tab layout for future features
* load/save bilibili playlist file.
Expand Down
6 changes: 3 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* let error message fade out
* autoload playlists
* capture more useful informations from console output
* more error detecting
* Bangou (avXXXX) paste support
* capture more useful informations from console output (to fill BiliPlaylist metadata)
* more error detection (use raise maybe)
* Bangou (avXXXX) paste support (use "\n",",",";" to separate)
* custom look and feel
* play history

Expand Down
Binary file modified bilibili.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bilibili.svgz
Binary file not shown.

0 comments on commit dd2a881

Please sign in to comment.