-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
148 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>PlauschangriffDownloader</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
<nature>com.aptana.projects.webnature</nature> | ||
<nature>com.aptana.ruby.core.rubynature</nature> | ||
</natures> | ||
</projectDescription> |
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,62 @@ | ||
class Gui < FXMainWindow | ||
|
||
def initialize(app) | ||
@xml = Xml.new | ||
@prepare = Prepare.new | ||
|
||
# Initialize base class first | ||
super(app, "Plauschangriff Downloader", :opts => DECOR_ALL, :width => 460, :height => 165) | ||
|
||
# Create GUI | ||
|
||
# Frames | ||
topFrame = FXHorizontalFrame.new(self) | ||
topFrameLeft = FXVerticalFrame.new(topFrame) | ||
topFrameRight = FXVerticalFrame.new(topFrame, :padLeft => 25) | ||
|
||
|
||
lbl1 = FXLabel.new(topFrameLeft, 'Select podcasts', nil, LAYOUT_LEFT) | ||
@list1 = FXList.new(topFrameLeft, :opts => LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT|LIST_EXTENDEDSELECT|LIST_MULTIPLESELECT, :width => 350, :height => 80) | ||
@list1.fillItems(@xml.getPodcastNames) | ||
lbl2 = FXLabel.new(topFrameRight, ' ', nil, LAYOUT_LEFT) | ||
btnDownload = FXButton.new(topFrameRight, 'Download', :opts => FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X) | ||
btnExit = FXButton.new(topFrameRight, 'Exit', :opts => FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X) | ||
@lbl3 = FXLabel.new(topFrameLeft, 'Waiting...', nil, JUSTIFY_LEFT|LAYOUT_FIX_WIDTH, :width => 350) | ||
@progressbar = FXProgressBar.new(topFrameLeft, :opts => LAYOUT_FIX_WIDTH|PROGRESSBAR_HORIZONTAL|PROGRESSBAR_NORMAL|PROGRESSBAR_PERCENTAGE, :width => 350) | ||
@progressbar.barColor = Fox.FXRGB(152, 251, 152) | ||
|
||
# Commands | ||
btnExit.connect(SEL_COMMAND) { exit } | ||
btnDownload.connect(SEL_COMMAND) { Thread.new {start} } | ||
|
||
end | ||
|
||
def download(url, name) | ||
open(name, 'wb') do |file| | ||
open(url, :progress_proc => proc { |step| | ||
@progressbar.progress = step | ||
}) do |uri| | ||
file.write(uri.read) | ||
end | ||
end | ||
end | ||
|
||
|
||
def start | ||
@list1.each do |item| | ||
if(item.selected?) | ||
url = @xml.getDownloadLink(item) | ||
@progressbar.total = @prepare.getSize(url) | ||
name = "Rocket Beans Plauschangriff - " + item.to_s + ".mp3" | ||
@lbl3.text = "Downloading: " + item.to_s + ".mp3" | ||
download(url, @prepare.sanitize(name)) | ||
end | ||
end | ||
end | ||
|
||
|
||
def create | ||
super | ||
show(PLACEMENT_SCREEN) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Prepare | ||
|
||
def initialize() | ||
|
||
end | ||
|
||
def sanitize(filename) | ||
bad_chars = [ '/', '\\', '?', '%', '*', ':', '|', '"', '<', '>' ] | ||
bad_chars.each do |bad_char| | ||
filename.gsub!(bad_char, ' ') | ||
end | ||
filename | ||
end | ||
|
||
def getSize(url) | ||
res = nil | ||
urlbase = url.split('/')[2] | ||
urlpath = '/'+url.split('/')[3..-1].join('/') | ||
Net::HTTP.start(urlbase, 80) do |http| | ||
res = http.head(urlpath) | ||
end | ||
res['content-length'].to_f | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Xml | ||
|
||
def initialize | ||
@doc = Nokogiri::XML(open("http://rocketbeans.tv/plauschangriff.xml")) | ||
end | ||
|
||
def getPodcastNames | ||
@podcastnames = Array.new | ||
@doc.xpath('//item').each do |parent| | ||
@podcastnames.push(parent.xpath('./title').text) | ||
end | ||
@podcastnames | ||
end | ||
|
||
def escape_single_quotes_for_xpath(string) | ||
if string =~ /'/ | ||
%[concat('] + string.gsub(/'/, %[', "'", ']) + %[')] # horribly, this is how you escape single quotes in XPath. | ||
else | ||
%['#{string}'] | ||
end | ||
end | ||
|
||
def getDownloadLink(podcastname) | ||
pod = escape_single_quotes_for_xpath(podcastname.to_s) | ||
expression = "//title[text() = #{pod}]/.." | ||
node = @doc.xpath(expression) | ||
node.xpath('./enclosure/@url').to_s | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$:.unshift File.dirname(__FILE__) | ||
|
||
require 'fox16' | ||
include Fox | ||
|
||
require 'nokogiri' | ||
require 'open-uri' | ||
require 'includes/gui' | ||
require 'includes/xml' | ||
require 'includes/prepare' | ||
|
||
if __FILE__ == $0 | ||
FXApp.new("Plauschangriff Downloader", "FXRuby") do |app| | ||
Gui.new(app) | ||
app.create | ||
app.run | ||
end | ||
end |