Skip to content

Commit

Permalink
starting to provide web
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Nov 16, 2014
1 parent 70906d9 commit 2d59240
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 36 deletions.
60 changes: 30 additions & 30 deletions BiliWeb.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ module BiliWeb
require 'open-uri'
require_relative 'BiliConfig'

$cachePath = File.join($configPath, 'cache')

Dir.mkdir($cachePath) unless Dir.exists?($cachePath)

class BiliFetch

include BiliConfig
include BiliFile

def initialize(url)
@@index = "bilibili.tv.html"
@@indexfile = File.join($cachePath,@@index)

def initialize(url="http://bilibili.tv")
@url = url
@cachePath = File.join($configPath,"cache")
unless Dir.exists?(@cachePath) then
Dir.mkdir(@cachePath)
end
@filename = @cachePath + "/" + @url.gsub(/http:\/\//,"") + ".html"
@filename = $cachePath + "/" + @url.gsub(/http:\/\//,"") + ".html"
end

def get
Expand All @@ -28,7 +31,7 @@ def get

def clean(filename="#{@filename}")

if filename.index("bilibili.tv.html") then
if filename.index(@@index) then

biliMove(filename,"line.index('/video/') && ! line.index('av271')")

Expand All @@ -41,13 +44,26 @@ def clean(filename="#{@filename}")
def format
end

def indexLevels
indexFile = @cachePath + "/bilibili.tv.html"
indexLevel1 = indexFile + ".level1"
indexLevel2 = indexFile + ".level2"
def parse_index

biliMove(indexFile,indexLevel1,"line.index('i-link')")
biliMove(indexFile,indexLevel2,"! line.index('i-link')")
hash1 = {}
hash2 = {}
lev1 = @@indexfile + ".l1"
lev2 = @@indexfile + ".l2"

biliMove(@@indexfile,lev1,"line.index('i-link')")

# parse level 1 pair
open(lev1) do |f|
f.each_line do |line|
line.chomp!
key = line.gsub(/^.*<em>/,'').gsub(/<\/em.*$/,'')
value = line.gsub(/^.*href=\"/,'').gsub(/\"><em.*$/,'')
hash1[key] = value
end
end

return hash1

end

Expand All @@ -56,20 +72,4 @@ def indexLevels
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
#Test.new("http://www.bilibili.com/video/av1718394/").get
41 changes: 36 additions & 5 deletions BiliWidgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'qtwebkit'
require_relative 'BiliConfig'
require_relative 'BiliPlaylist'
require_relative 'BiliWeb'

class BiliGuiConfig

Expand Down Expand Up @@ -46,7 +47,23 @@ def load(playlist="")

end

class BiliGui < Qt::Widget
class BiliGuiWeb

include BiliWeb

def initialize(url="http://bilibili.tv")
@url = url
end

def get
BiliFetch.new(@url).get
BiliFetch.new(@url).clean
BiliFetch.new(@url).parse_index
end

end

class BiliGui < Qt::MainWindow

slots 'clear()'
slots 'bilidanChoose()'
Expand All @@ -62,12 +79,17 @@ class BiliGui < Qt::Widget
Height = 400
@@configw = BiliGuiConfig.new
@@config = @@configw.load
@@lev1 = BiliGuiWeb.new.get

def initialize
super

setWindowTitle "BiliGui"
setWindowIcon(Qt::Icon.new("bilibili.svgz"))
setStyleSheet("background-color: #171a21; color: #b8b6b4")

@central = Qt::Widget.new self
setCentralWidget @central

init_ui

Expand Down Expand Up @@ -103,7 +125,7 @@ def init_ui
@messageLabel = Qt::Label.new
@messageLabel.setStyleSheet("color: #ff0000;")

grid_biliTabs = Qt::GridLayout.new self
grid_biliTabs = Qt::GridLayout.new(@central)
grid_biliTabs.addWidget biliTabs, 0, 0, 1, 1
grid_biliTabs.addWidget @messageLabel, 1, 0, 1, 1
grid_biliTabs.setColumnStretch 0, 0
Expand Down Expand Up @@ -145,18 +167,27 @@ def init_ui
connect ctlLoadButton, SIGNAL('clicked()'), self, SLOT('biliLoad()')
connect ctlSaveButton, SIGNAL('clicked()'), self, SLOT('biliSave()')

# Web Tab
menu = Qt::MenuBar.new(webTab)
@@lev1.each do |array|
name = array[1].gsub(/\/video\//,'').gsub(/\.html/,'')
name = Qt::Menu.new "#{array[0]}"
menu.addMenu name
end

# Settings Tab
grid_Settings = Qt::GridLayout.new settingsTab
bilidanPathLabel = Qt::Label.new "Please enter your bilidan's path:", settingsTab
@bilidanPath = Qt::LineEdit.new @@config["BilidanPath"], settingsTab
bilidanButton = Qt::PushButton.new 'Choose', settingsTab

logo = Qt::Label.new "BiliGui is a graphical frontend for Bilidan, developed by marguerite", settingsTab
desc = Qt::Label.new "BiliGui is a graphical frontend for Bilibili, developed by marguerite", settingsTab
#logo = Qt::Pixmap.new("bilibili.svgz")
#desc.setPixmap(logo)

grid_Settings.addWidget bilidanPathLabel, 0, 0, 1, 1
grid_Settings.addWidget @bilidanPath, 0, 1, 1, 1
grid_Settings.addWidget bilidanButton, 0, 2, 1, 1
grid_Settings.addWidget logo, 1, 1, 1, 1
grid_Settings.addWidget desc, 1, 1, 1, 1
grid_Settings.setColumnStretch 0, 0

connect bilidanButton, SIGNAL('clicked()'), self, SLOT('bilidanChoose()')
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## BiliGui

Bilibili GUI for [BiliDan](https://github.com/m13253/BiliDan)
BiliGui is an All-in-one frontend for all the Bilibili black magic in Linux world.

It's writtern in `ruby` + `Qt` and highly modular, eg: using `[BiliDan](https://github.com/m13253/BiliDan)`
as player backend (further callback `mpv`), `[Biligrab](https://github.com/cnbeining/Biligrab)` as download module
and a lot more.

![BiliGui Screenshot](https://raw.githubusercontent.com/marguerite/BiliGui/master/screenshot.png)

### Features

### Installation

Expand Down
8 changes: 8 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* more error detection (use raise maybe)
* custom look and feel
* play history
* query url to get title & author
* BiliDaemon.rb to run background tasks
** autosave config
* Playlist merge
** find all saved playlists
** merge into a temp big one
** and autoload in init_ui
** simulate "history" function, can also load "BiliPlaylist.history"

future:

Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d59240

Please sign in to comment.