Skip to content

Commit

Permalink
add bangou(avXXXXXX) paste support
Browse files Browse the repository at this point in the history
  • Loading branch information
marguerite committed Nov 16, 2014
1 parent dd2a881 commit c377200
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
61 changes: 45 additions & 16 deletions BiliPlaylist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class BiliPlaylist

def initialize(videos="")
@videos = videos
@videosHash = {}
@hash = {}

split
end
Expand All @@ -13,26 +13,55 @@ def split

unless @videos.empty? then

@videos.split(/\n/).each do |video|

unless video.index("http://") then
next
end


videoHashKey = "av" + video.gsub(/^.*\/av/,"").gsub(/\//,"")
videoHashValue = video
if @videos.index("http://") then
@videos.split(/\n/).each do |video|
unless video.index("http://") then
next
end
key = "av" + video.gsub(/^.*\/av/,'').gsub(/\//,'')
value = video
@hash[key] = value
end
else # bangou
if @videos.index(",") || @videos.index(";") then
if @videos.index(",") then
separator = ","
else
separator = ";"
end

@videos.split(/\n/).each do |video|
video.split(separator).each do |bangou|
unless bangou.index("av") then
next
p "[WARN] #{bangou} is not a valid bango!"
end

key = bangou
value = "http://bilibili.tv/video/" + bangou + "/"
@hash[key] = value
end
end

@videosHash[videoHashKey] = videoHashValue

end
else
# single bangou or no URL
unless @videos.index("av") then
p "[WARN] Did you paste anything?"
else
key = @videos.gsub(/\n/,'')
value = "http://bilibili.tv/video/" + key + "/"
@hash[key] = value
end
end
end

end

end

def hash
return @videosHash
return @hash
end

def save(filename="")
Expand All @@ -50,12 +79,12 @@ def save(filename="")
old_playlist = playlist + ".old"

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

@videosHash.to_a.each do |video|
@hash.to_a.each do |video|
io.puts "#EXTINF:#{video[0]}"
io.puts video[1]
end
Expand Down Expand Up @@ -98,7 +127,7 @@ def load(playlist="")
p "#{line} doesn't seem to be a Bilibili URL!"
else
value = line
key = "av" + line.gsub(/^.*\/av/,"").gsub(/\//,"")
key = "av" + value.gsub(/^.*\/av/,'').gsub(/\//,'')
hash[key] = value
array[i] = line
end
Expand Down
10 changes: 5 additions & 5 deletions BiliWidgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def bilidan
require 'open3'

urlText = @urlArea.toPlainText()
urlTextHash = BiliGuiPlaylist.new(urlText).hash
urlHash = BiliGuiPlaylist.new(urlText).hash
pathText = @bilidanPath.text()

# validate bilidan.py path
Expand All @@ -178,13 +178,13 @@ def bilidan
end
end

unless urlTextHash.empty? then
unless urlHash.empty? then

urlTextHash.each_value do |hashvalue|
urlHash.each_value do |value|

p "Now Playing: #{hashvalue}"
p "Now Playing: #{value}"

command = "#{pathText} #{hashvalue}"
command = "#{pathText} #{value}"
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stderr.each_line do |line|
# common error
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.0.7
* fix: BiliPlaylist::BiliSave can't override old file
* bangou (avXXXXXX) paste support
0.0.6
* fix: forgot to have BiliPlaylist::BiliLoad functional
* initialize BiliWeb module, handling communication w/ bilibili.tv
Expand Down
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* autoload playlists
* 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

0 comments on commit c377200

Please sign in to comment.