From ba2e5caaeb395a47105601d7a04804327ff1bb8c Mon Sep 17 00:00:00 2001 From: marguerite Date: Wed, 19 Nov 2014 23:11:47 +0800 Subject: [PATCH] release 0.0.10 --- BiliFile.rb | 2 -- BiliPlaylist.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ BiliWeb.rb | 12 +++++----- BiliWidgets.rb | 26 ++++++++++++++++----- doc/ChangeLog | 3 +++ doc/TODO | 12 ---------- 6 files changed, 89 insertions(+), 26 deletions(-) diff --git a/BiliFile.rb b/BiliFile.rb index 1b2f124..4b52baf 100644 --- a/BiliFile.rb +++ b/BiliFile.rb @@ -6,8 +6,6 @@ def biliMove(file, newfile=file, condition) tmp = file + ".tmp" - p condition - open(file, 'r') do |f0| open(tmp, 'w') do |f1| f0.each_line do |line| diff --git a/BiliPlaylist.rb b/BiliPlaylist.rb index 4646463..2bd67cb 100644 --- a/BiliPlaylist.rb +++ b/BiliPlaylist.rb @@ -1,11 +1,16 @@ module BiliPlaylist + require_relative 'BiliConfig' + class BiliPlaylist def initialize(videos="") @videos = videos @hash = {} + @historyfile = File.join($configPath,"biligui.history") + @lastfile = File.join($configPath,"biligui.last") + split end @@ -134,6 +139,61 @@ def load(playlist="") end + def history + + io = open(@lastfile, 'w') + @hash.each_value { |item| io.puts item } + io.close + + open(@lastfile,'r') do |f| + open(@historyfile, 'a') do |f1| + f.each_line do |line| + f1.puts line + end + end + end + + duplicate([@lastfile,@historyfile]) + + end + + def duplicate(files) + + files.each do |file| + array = [] + i = 0 + + open(file,'r') do |f| + f.each_line do |line| + line.chomp! + array[i] = line + i+=1 + end + end + + new = array.uniq + + io = open(file, 'w') + new.each {|value| io.puts value} + io.close + end + end + + def last + + str = "" + + open(@lastfile,'r') do |f| + f.each_line do |line| + str += line + end + end + + p str + return str + + end + end end diff --git a/BiliWeb.rb b/BiliWeb.rb index 1b41328..a2cf3b2 100644 --- a/BiliWeb.rb +++ b/BiliWeb.rb @@ -12,9 +12,6 @@ class BiliParser include BiliConfig include BiliFile - @@index = "bilibili.tv.html" - @@indexfile = File.join($cachePath,@@index) - def initialize(array=["http://bilibili.tv"]) @filename = {} @@ -25,6 +22,9 @@ def initialize(array=["http://bilibili.tv"]) @pool = Queue.new + @index = "bilibili.tv.html" + @indexfile = File.join($cachePath,@index) + get end @@ -51,7 +51,7 @@ def clean Thread.new { file = @pool.pop - if file.index(@@index) then + if file.index(@index) then biliMove(file,"line.index('/video/') && ! line.index('av271')") else p "[WARN] Don't know what to do!" @@ -65,9 +65,9 @@ def clean def parse hash1 = {} - lev1 = @@indexfile + ".l1" + lev1 = @indexfile + ".l1" - biliMove(@@indexfile,lev1,"line.index('i-link')") + biliMove(@indexfile,lev1,"line.index('i-link')") # parse level 1 pair open(lev1) do |f| diff --git a/BiliWidgets.rb b/BiliWidgets.rb index 1304b92..7681190 100644 --- a/BiliWidgets.rb +++ b/BiliWidgets.rb @@ -20,11 +20,10 @@ class BiliGui < Qt::MainWindow slots 'biliWeb()' slots 'biliSave()' slots 'biliLoad()' + slots 'biliHistory()' Width = 800 Height = 550 - @@configw = BiliConf.new - @@config = @@configw.load def initialize super @@ -36,6 +35,10 @@ def initialize @central.setObjectName("centralwidget") setCentralWidget @central + @configw = BiliConf.new + @config = @configw.load + @last = BiliPlaylist.new.last + init_ui resize Width, Height @@ -81,6 +84,7 @@ 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 + @urlArea.setText(@last) ctlPanel = Qt::Widget.new playlistTab @playButton = Qt::PushButton.new 'Play', playlistTab clearButton = Qt::PushButton.new 'Clear', playlistTab @@ -95,6 +99,7 @@ def init_ui connect biliWebButton, SIGNAL('clicked()'), self, SLOT('biliWeb()') + connect @urlArea, SIGNAL('textChanged()'), self, SLOT('biliHistory()') connect @playButton, SIGNAL('clicked()'), self, SLOT('bilidanPlay()') connect clearButton, SIGNAL('clicked()'), self, SLOT('clear()') @@ -124,7 +129,7 @@ def init_ui # 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 + @bilidanPath = Qt::LineEdit.new @config["BilidanPath"], settingsTab bilidanButton = Qt::PushButton.new 'Choose', settingsTab grid_Settings.addWidget bilidanPathLabel, 0, 0, 1, 1 @@ -207,7 +212,6 @@ def bilidanChoose unless bilidanBin == nil then if bilidanBin.index("bilidan.py") then @bilidanPath.setText(bilidanBin) - @@configw.put("BilidanPath", bilidanBin) else @messageLabel.setText("[WARN] You didn't choose bilidan.py!") end @@ -216,8 +220,10 @@ def bilidanChoose def bilidanAutoSave - p @bilidanPath.text - @@configw.put("BilidanPath", @bilidanPath.text) + # avoid waste resource + if @bilidanPath.text.index("bilidan.py") then + @configw.put("BilidanPath", @bilidanPath.text) + end end @@ -253,4 +259,12 @@ def biliSave end end + def biliHistory + + if @urlArea.toPlainText.index("av") then + BiliPlaylist.new(@urlArea.toPlainText).history + end + + end + end diff --git a/doc/ChangeLog b/doc/ChangeLog index b27d1e0..2e68928 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,9 @@ 0.0.10 * autosave bilidan path in input area * regression: can not set biligui config +* autosave paste history & last pasted +* load last pasted URLs by default +* fix: don't use class variable, use local variable instead 0.0.9 * make it themeable (external stylesheet .qss) * clean module usage, don't need to create wrapper classes diff --git a/doc/TODO b/doc/TODO index 14be237..f06ce45 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,18 +1,6 @@ * let error message fade out -* autoload playlists * capture more useful informations from console output (to fill BiliPlaylist metadata) -* more error detection (use raise maybe) -* custom look and feel -* play history * query url to get title & author -* BiliDaemon.rb to run background tasks -* 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" - -* thread safe! * handle exceptions future: