summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-22 13:20:09 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-22 13:20:09 (GMT)
commite6035cca7cf6f23b3965f6238e41103838c48d3b (patch)
treeed9dffb239a8babbf37a8cb11dc7d1ddfef54f99
parentf4fd11fd93aeba8650f413f4a7a538eb8ba59ea0 (diff)
removed old stuff
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rwxr-xr-xconfigure2
-rw-r--r--debian/control4
-rw-r--r--gui_callbacks.pm71
-rwxr-xr-xrhimport398
-rwxr-xr-xrhimport-create-id9
-rw-r--r--rhimport.glade235
-rw-r--r--rhimport.pm104
9 files changed, 42 insertions, 786 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cd51438
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+include.mk
diff --git a/Makefile b/Makefile
index d4c76c8..9419904 100644
--- a/Makefile
+++ b/Makefile
@@ -60,7 +60,6 @@ install-bin:
$(INSTALL) -m 755 $(EXECUTABLE)-zf $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(EXECUTABLE)-zffe $(DESTDIR)$(BINDIR)
$(INSTALL) -m 755 $(EXECUTABLE)-zfw $(DESTDIR)$(BINDIR)
- $(INSTALL) -m 755 $(EXECUTABLE)-create-id $(DESTDIR)$(BINDIR)
@sed s#/usr/local/share/rhimport/#$(SHAREDIR)/$(EXECUTABLE)/#g -i $(DESTDIR)$(BINDIR)/$(EXECUTABLE)
@sed s#/usr/local/share/rhimport/#$(SHAREDIR)/$(EXECUTABLE)/#g -i $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-btl
@sed s#/usr/local/share/rhimport/#$(SHAREDIR)/$(EXECUTABLE)/#g -i $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-dn
@@ -83,8 +82,6 @@ install-bin:
install-share:
$(INSTALL) -d $(DESTDIR)$(SHAREDIR)/$(EXECUTABLE)
$(INSTALL) -m 644 rhimport.pm $(DESTDIR)$(SHAREDIR)/$(EXECUTABLE)
- $(INSTALL) -m 644 gui_callbacks.pm $(DESTDIR)$(SHAREDIR)/$(EXECUTABLE)
- $(INSTALL) -m 644 rhimport.glade $(DESTDIR)$(SHAREDIR)/$(EXECUTABLE)
uninstall: remove
@@ -109,7 +106,6 @@ remove-bin:
rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-zf
rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-zffe
rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-zfw
- rm -f $(DESTDIR)$(BINDIR)/$(EXECUTABLE)-create-id
remove-share:
rm -rf $(DESTDIR)$(SHAREDIR)/$(EXECUTABLE)
diff --git a/configure b/configure
index 44b08c6..8d52333 100755
--- a/configure
+++ b/configure
@@ -74,7 +74,7 @@ fi
cat >> include.mk <<EOF
# this file was created automatically
-# do not edit this file directly
+# do not edit this file directly
# use ./configure instead
INSTALL := install
diff --git a/debian/control b/debian/control
index ca8efc8..4f0d1f0 100644
--- a/debian/control
+++ b/debian/control
@@ -8,9 +8,7 @@ Homepage: http://www.helsinki.at/
Package: rhimport
Architecture: all
-Depends: ${misc:Depends}, adduser, perl, libdbd-mysql-perl, libgtk2-gladexml-perl, libdate-calc-perl, libxml-feed-perl, libfile-slurp-perl, libfile-touch-perl
+Depends: ${misc:Depends}, adduser, perl, libdbd-mysql-perl, libconfig-inifiles-perl, libdate-calc-perl, libxml-feed-perl, libfile-slurp-perl, libfile-touch-perl
Description: Radio Helsinki Import Tool
rhimport is a small tool which can be used to import media files
into the playout system namley Rivendell.
-
-
diff --git a/gui_callbacks.pm b/gui_callbacks.pm
deleted file mode 100644
index f101cf7..0000000
--- a/gui_callbacks.pm
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/perl -w
-#
-#
-# rhimport
-#
-# Copyright (C) 2009 Christian Pointner <equinox@helsinki.at>
-#
-# This file is part of rhimport.
-#
-# rhimport is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# any later version.
-#
-# rhimport is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with rhimport. If not, see <http://www.gnu.org/licenses/>.
-#
-
-use strict;
-
-package gui_callbacks;
-
-sub on_exit
-{
- my ($widget, $data) = @_;
-
- Gtk2->main_quit;
-}
-
-sub on_b_mode_clicked
-{
- my ($widget, $data) = @_;
-
- ::toggle_mode_gui();
-}
-
-sub on_b_apply_clicked
-{
- my ($widget, $data) = @_;
-
- ::start_import_gui();
-}
-
-sub on_b_showcarts_clicked
-{
- my ($widget, $data) = @_;
-
- ::show_used_carts_gui();
-}
-
-sub on_co_dropbox_changed
-{
- my ($widget, $data) = @_;
-
- ::clear_status_gui();
- ::dropbox_updated_gui();
-}
-
-sub on_filechooser_selection_changed
-{
- my ($widget, $data) = @_;
-
- ::clear_status_gui();
-}
-
-1;
diff --git a/rhimport b/rhimport
index caaa267..05bf4c9 100755
--- a/rhimport
+++ b/rhimport
@@ -24,22 +24,12 @@
use strict;
use Getopt::Long;
-use DBI;
-use Gtk2;
-use Gtk2::GladeXML;
use lib '/usr/local/share/rhimport/';
use rhimport;
-my $glade_file = '/usr/local/share/rhimport/rhimport.glade';
-my $DBHOST = "airplay";
-my $DBUSER = "rivendell";
-my $DBPW = "lldriven";
-my $DB = "rivendell";
my $HELP = 0;
my $FILE = "";
-my $POOL = 0;
-my $KEEPCARTS = 0;
my $DROPBOX = "";
my $LISTALLOWED = 0;
@@ -49,22 +39,16 @@ binmode(STDERR, ":utf8");
GetOptions ("help!" => \$HELP,
"file=s" => \$FILE,
- "pool!" => \$POOL,
- "keep-carts!" => \$KEEPCARTS,
"dropbox=s" => \$DROPBOX,
"list-allowed!" => \$LISTALLOWED,
) or die();
if($HELP) {
print << "EOF";
-usage: $0 --file <audio or playlist file> --pool --keep-carts --dropbox <path to dropbox> --list-allowed
-
-When called with no file and/or no dropbox the GUI gets started to select the missing parameters
+usage: $0 --file <audio or playlist file> --dropbox <path to dropbox> --list-allowed
options:
-f | --file the media file or playlist to import
- -p | --pool pool mode, import media files referneced by playlist
- -k | --keep-carts in pool mode keep existing carts instead of clearing them before import
-d | --dropbox the path to the dropbox to use
-l | --list-allowed list allowed dropboxes and exit
@@ -75,361 +59,21 @@ EOF
my $user = `/usr/bin/id -un`;
$user =~ s/\n//;
-my $dbh = DBI->connect("DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr";
+my ($dbh, $errorstring) = rhimport::opendb();
+if(!defined $dbh) {
+ print "$errorstring\n";
+ exit 1;
+}
my @allowed_dbs = rhimport::get_dropboxes($dbh, $user);
if($LISTALLOWED) {
for my $href ( @allowed_dbs ) {
print "$href->{'NAME'} \t-> $href->{'PATH'}\n" unless $href->{'NAME'} =~ /^autoimport/;
}
- $dbh->disconnect();
+ rhimport::closedb($dbh);
exit 0;
}
-###########################################
-## GUI mode
-
-my $guixml;
-
-sub set_mode_playlist_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- $POOL = 1;
- my $l_mode = $guixml->get_widget('l_mode');
- $l_mode->set_label("<b>Musik Pool</b>");
- my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
- $cb_clear_carts->set_sensitive(1);
- my $l_file_playlist = $guixml->get_widget('l_file_playlist');
- $l_file_playlist->set_label("<b>Playlist</b>");
- my $filter = Gtk2::FileFilter->new;
- $filter->add_pattern("*.m3u");
- my $filechooser = $guixml->get_widget('filechooser');
- $filechooser->set_filter($filter);
-}
-
-sub set_mode_file_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- $POOL = 0;
- my $l_mode = $guixml->get_widget('l_mode');
- $l_mode->set_label("<b>Sendung</b>");
- my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
- $cb_clear_carts->set_sensitive(0);
- my $l_file_playlist = $guixml->get_widget('l_file_playlist');
- $l_file_playlist->set_label("<b>Datei</b>");
- my $filter = Gtk2::FileFilter->new;
- $filter->add_pattern("*.wav");
- $filter->add_pattern("*.WAV");
- $filter->add_pattern("*.ogg");
- $filter->add_pattern("*.OGG");
- $filter->add_pattern("*.flac");
- $filter->add_pattern("*.FLAC");
- $filter->add_pattern("*.fla");
- $filter->add_pattern("*.FLA");
- $filter->add_pattern("*.mp*");
- $filter->add_pattern("*.MP*");
- my $filechooser = $guixml->get_widget('filechooser');
- $filechooser->set_filter($filter);
-}
-
-sub set_mode_disabled_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my @widgets = ('b_mode', 'cb_clear_carts', 'b_showcarts', 'b_apply', 'filechooser');
- for my $w ( @widgets ) {
- my $widget = $guixml->get_widget($w);
- $widget->set_sensitive(0) if($widget);
- }
-}
-
-sub toggle_mode_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my $co_dropbox = $guixml->get_widget('co_dropbox');
- my $to_cart = $allowed_dbs[$co_dropbox->get_active]->{'TO_CART'} if($allowed_dbs[$co_dropbox->get_active]);
-
- my $response = 'no';
- if(($to_cart == 0 && $POOL) ||
- ($to_cart != 0 && !$POOL)) {
- my $question = "Diese Sendung hat ";
- if($to_cart != 0) {
- $question .= "nur ein Cart";
- } else {
- $question .= "mehrere Carts";
- }
- $question .= ". Soll der Modus trotzdem gewechselt werden?";
-
- my $parent_window = $guixml->get_widget('appwin');
- my $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
- 'question', 'yes-no', $question);
- $dialog->set_default_response ('no');
- $response = $dialog->run;
- $dialog->destroy;
- }
- else {
- $response = 'yes';
- }
-
- if($response eq 'yes') {
- if($POOL) {
- set_mode_file_gui();
- } else {
- set_mode_playlist_gui();
- }
- }
-}
-
-my $gui_progress_cb = sub {
- my ($elapsed, $max, $text) = @_;
-
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
- my $progressbar = $guixml->get_widget('progressbar');
- $progressbar->set_text("($elapsed/$max) $text");
- $progressbar->set_fraction($elapsed/$max);
- while (Gtk2->events_pending) {
- Gtk2->main_iteration;
- }
- Gtk2::Gdk->flush;
-};
-
-my $gui_error_cb = sub {
- my ($text) = @_;
-
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
- $text .= "\n\nVorgang abbrechen?";
- my $parent_window = $guixml->get_widget('appwin');
- my $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
- 'error', 'yes-no', $text);
- $dialog->set_default_response ('no');
- my $response = $dialog->run;
- $dialog->destroy;
-
- return 0 if($response eq 'yes');
-
- return 1;
-};
-
-sub start_import_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my $b_apply = $guixml->get_widget('b_apply');
- my $b_close = $guixml->get_widget('b_close');
- $b_apply->set_sensitive(0);
- $b_close->set_sensitive(0);
-
- if(!rhimport::check_key_file()) {
- my $parent_window = $guixml->get_widget('appwin');
- my $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
- 'error', 'ok', "Es wurde kein Import Key gefunden.");
- $dialog->run;
- $dialog->destroy;
- $b_apply->set_sensitive(1);
- $b_close->set_sensitive(1);
- return 0;
- }
-
- my $l_status = $guixml->get_widget('l_status');
-
- my $filechooser = $guixml->get_widget('filechooser');
- my $file = $filechooser->get_filename;
- if(!$file || -d $file) {
- if($POOL) {
- $l_status->set_label("Keine Playlist ausgewählt!");
- } else {
- $l_status->set_label("Keine Audio Datei ausgewählt!");
- }
- $b_apply->set_sensitive(1);
- $b_close->set_sensitive(1);
- return 0;
- }
- $filechooser->unselect_all;
-
- my $co_dropbox = $guixml->get_widget('co_dropbox');
- my $dropbox = $allowed_dbs[$co_dropbox->get_active]->{'PATH'} if ($allowed_dbs[$co_dropbox->get_active]);
- my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'} if ($allowed_dbs[$co_dropbox->get_active]);
- my $to_cart = $allowed_dbs[$co_dropbox->get_active]->{'TO_CART'} if($allowed_dbs[$co_dropbox->get_active]);
-
- $l_status->set_label("importiere von $file");
-
- my $ret;
- my $log;
- if($POOL) {
- my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
- if($cb_clear_carts->get_active) {
- $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb);
- }
- my $import_log;
- ($ret, $import_log) = rhimport::import_playlist($file, $dropbox, $user, rhimport::get_num_carts($dbh, $group) ,$gui_progress_cb, $gui_error_cb);
- $log .= $import_log;
- } else {
- $log = rhimport::clear_carts($dbh, $group, $to_cart, $gui_progress_cb);
- my $import_log;
- ($ret, $import_log) = rhimport::import_single($file, $dropbox, $user, $gui_progress_cb, $gui_error_cb);
- $log .= $import_log;
- }
-
- my $parent_window = $guixml->get_widget('appwin');
- my $dialog;
- if(!$ret) {
- $l_status->set_label("Fehler beim Importieren");
- $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
- 'error', 'ok', "Fehler beim Importieren.");
-# $dialog->add_button("Log anzeigen", 1);
- } else {
- $l_status->set_label("");
- $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
- 'info', 'ok', "Der Import wurde erfolgreich abgeschlossen!");
-# $dialog->add_button("Log anzeigen", 1);
- }
- my $response = $dialog->run;
- $dialog->destroy;
-
-# if($response == 1) {
-# $dialog = Gtk2::MessageDialog->new ($parent_window, 'destroy-with-parent',
-# 'info', 'ok', $log);
-# $dialog->run;
-# $dialog->destroy;
-# }
-
- $b_apply->set_sensitive(1);
- $b_close->set_sensitive(1);
- return $ret;
-}
-
-sub show_used_carts_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my $co_dropbox = $guixml->get_widget('co_dropbox');
- my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'} if($allowed_dbs[$co_dropbox->get_active]);
-
-
- my $l_status = $guixml->get_widget('l_status');
- my ($low_cart, $high_cart) = rhimport::get_cart_range($dbh, $group);
- if($low_cart eq $high_cart) {
- $l_status->set_label("Cart: $low_cart");
- } else {
- $l_status->set_label("Carts: $low_cart - $high_cart");
- }
-
- # my $usedcartswin = Gtk2::Window->new();
- # $usedcartswin or die "can't open new window";
- # $usedcartswin->resize(640,480);
- # if($low_cart eq $high_cart) {
- # $usedcartswin->set_title("Cart: $low_cart");
- # } else {
- # $usedcartswin->set_title("Carts: $low_cart - $high_cart");
- # }
- # $usedcartswin->show;
-}
-
-sub clear_status_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my $l_status = $guixml->get_widget('l_status');
- $l_status->set_label("");
-
- my $progressbar = $guixml->get_widget('progressbar');
- $progressbar->set_text("");
- $progressbar->set_fraction(0);
-}
-
-sub dropbox_updated_gui()
-{
- if(!$guixml) {
- print STDERR "no GUI definition found!\n";
- exit 2;
- }
-
- my $co_dropbox = $guixml->get_widget('co_dropbox');
- if($allowed_dbs[$co_dropbox->get_active]) {
- my $to_cart = $allowed_dbs[$co_dropbox->get_active]->{'TO_CART'};
- my $group = $allowed_dbs[$co_dropbox->get_active]->{'GROUP'};
- my ($low_cart, $high_cart) = rhimport::get_cart_range($dbh, $group);
-
- if($to_cart == 0) {
- set_mode_playlist_gui();
- } else {
- set_mode_file_gui();
- }
- } else {
- set_mode_disabled_gui();
- }
-}
-
-if(!$FILE || !$DROPBOX) {
- Gtk2->init;
-
- $guixml = Gtk2::GladeXML->new($glade_file);
- $guixml or die "can't load glade xml file";
- require gui_callbacks;
-
- my $model = Gtk2::ListStore->new('Glib::String', 'Glib::String', 'Glib::String', 'Glib::String');
- for my $href ( @allowed_dbs ) {
- $model->set ($model->append, 0, $href->{'PATH'}, 1, $href->{'GROUP'}, 2, $href->{'TO_CART'}, 3, $href->{'NAME'});
- }
- my $co_dropbox = $guixml->get_widget('co_dropbox');
- $co_dropbox->set_model($model);
- my $renderer = Gtk2::CellRendererText->new;
- $co_dropbox->pack_start($renderer, 1);
- $co_dropbox->add_attribute($renderer, text => 3);
- $co_dropbox->set_active(0);
- dropbox_updated_gui();
-
- my $cb_clear_carts = $guixml->get_widget('cb_clear_carts');
- if($KEEPCARTS) {
- $cb_clear_carts->set_active(0);
- } else {
- $cb_clear_carts->set_active(1);
- }
-
- $guixml->signal_autoconnect_from_package('gui_callbacks');
- my $appwin = $guixml->get_widget('appwin');
- $appwin or die "can't find Main Window";
- $appwin->resize(800,600);
- $appwin->show;
-
- Gtk2->main;
- $dbh->disconnect();
- exit 0;
-}
-
-###########################################
-## command line mode
-
my $cl_error_cb = sub {
my ($text) = @_;
@@ -438,14 +82,8 @@ my $cl_error_cb = sub {
$x =~ /^n/i;
};
-rhimport::check_key_file() or die "Import Key not found, use rhimport-create-id to create one\n";
-
(-e "$FILE") or die "file '$FILE' not found\n";
-if($POOL) {
- print "will import from playlist $FILE, with user $user\n\n";
-} else {
- print "will import $FILE, with user $user\n\n";
-}
+print "will import $FILE, with user $user\n\n";
my $group = '';
my $to_cart = 0;
@@ -464,22 +102,12 @@ if($group eq '') {
my $ret;
my $log;
-if($POOL) {
- if(!$KEEPCARTS) {
- $log = rhimport::clear_carts($dbh, $group, $to_cart);
- }
-
- my $import_log;
- ($ret, $import_log) = rhimport::import_playlist($FILE, $DROPBOX, $user, rhimport::get_num_carts($dbh, $group), 0, $cl_error_cb);
- $log .= $import_log;
-} else {
- $log = rhimport::clear_carts($dbh, $group, $to_cart);
- my $import_log;
- ($ret, $import_log) = rhimport::import_single($FILE, $DROPBOX, $user, 0, $cl_error_cb);
- $log .= $import_log;
-}
+$log = rhimport::clear_carts($dbh, $group, $to_cart);
+my $import_log;
+($ret, $import_log) = rhimport::import_single($FILE, $DROPBOX, $user, 0, $cl_error_cb);
+$log .= $import_log;
-$dbh->disconnect();
+rhimport::closedb($dbh);
if(!$ret) {
exit 1;
diff --git a/rhimport-create-id b/rhimport-create-id
deleted file mode 100755
index 01a19b8..0000000
--- a/rhimport-create-id
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-KEYDIR="$HOME/.rhimport"
-KEYFILE=$KEYDIR/import.key
-
-mkdir -p $KEYDIR
-ssh-keygen -f $KEYFILE -t dsa
-chmod 600 $KEYFILE
-cat $KEYFILE.pub | ssh rhadmin@airplay "sudo /usr/local/bin/rhimport-add-id"
diff --git a/rhimport.glade b/rhimport.glade
deleted file mode 100644
index 69f7a20..0000000
--- a/rhimport.glade
+++ /dev/null
@@ -1,235 +0,0 @@
-<?xml version="1.0"?>
-<glade-interface>
- <!-- interface-requires gtk+ 2.16 -->
- <!-- interface-naming-policy project-wide -->
- <widget class="GtkWindow" id="appwin">
- <property name="width_request">320</property>
- <property name="height_request">480</property>
- <property name="border_width">5</property>
- <property name="title">rhimport</property>
- <property name="gravity">center</property>
- <property name="startup_id">1</property>
- <signal name="destroy" handler="on_exit"/>
- <child>
- <widget class="GtkFrame" id="mainframe">
- <property name="visible">True</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">none</property>
- <child>
- <widget class="GtkAlignment" id="alignment">
- <property name="visible">True</property>
- <property name="top_padding">5</property>
- <property name="bottom_padding">5</property>
- <property name="left_padding">5</property>
- <property name="right_padding">5</property>
- <child>
- <widget class="GtkVBox" id="vbox">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="spacing">4</property>
- <child>
- <widget class="GtkHBox" id="hbox_mode">
- <property name="visible">True</property>
- <child>
- <widget class="GtkButton" id="b_mode">
- <property name="label" translatable="yes">Modus</property>
- <property name="width_request">130</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="on_b_mode_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="l_mode">
- <property name="width_request">120</property>
- <property name="visible">True</property>
- <property name="label" translatable="yes">&lt;b&gt;Sendung&lt;/b&gt;</property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkCheckButton" id="cb_clear_carts">
- <property name="label" translatable="yes">Vor Import alle Carts leeren</property>
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </widget>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHSeparator" id="hseparator">
- <property name="visible">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">5</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="l_dropbox">
- <property name="visible">True</property>
- <property name="label">&lt;b&gt;Dropbox&lt;/b&gt;</property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHBox" id="hbox_dropbox">
- <property name="visible">True</property>
- <child>
- <widget class="GtkComboBox" id="co_dropbox">
- <property name="visible">True</property>
- <signal name="changed" handler="on_co_dropbox_changed"/>
- </widget>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="b_showcarts">
- <property name="label" translatable="yes">Carts anzeigen</property>
- <property name="width_request">130</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="on_b_showcarts_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">3</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="l_file_playlist">
- <property name="visible">True</property>
- <property name="label">&lt;b&gt;Datei&lt;/b&gt;</property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">4</property>
- </packing>
- </child>
- <child>
- <widget class="GtkFileChooserWidget" id="filechooser">
- <property name="visible">True</property>
- <property name="orientation">vertical</property>
- <property name="use_preview_label">False</property>
- <property name="preview_widget_active">False</property>
- <signal name="selection_changed" handler="on_filechooser_selection_changed"/>
- </widget>
- <packing>
- <property name="position">5</property>
- </packing>
- </child>
- <child>
- <widget class="GtkProgressBar" id="progressbar">
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">6</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHBox" id="hbox_button">
- <property name="visible">True</property>
- <child>
- <widget class="GtkLabel" id="l_status">
- <property name="visible">True</property>
- </widget>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="b_close">
- <property name="label">gtk-close</property>
- <property name="width_request">130</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- <signal name="clicked" handler="on_exit"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="b_apply">
- <property name="label">gtk-apply</property>
- <property name="width_request">130</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- <signal name="clicked" handler="on_b_apply_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="position">7</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GtkLabel" id="l_main">
- <property name="visible">True</property>
- <property name="label">&lt;big&gt;&lt;b&gt;rhimport - Radio Helsinki Importtool&lt;/b&gt;&lt;/big&gt;</property>
- <property name="use_markup">True</property>
- </widget>
- <packing>
- <property name="type">label_item</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
-</glade-interface>
diff --git a/rhimport.pm b/rhimport.pm
index 66e37f7..8109f7e 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -35,6 +35,8 @@ use DateTime;
use DateTime::TimeZone;
use LWP::Simple;
use XML::Feed;
+use DBI;
+use Config::IniFiles;
my $ssh_host = "airplay";
my $ssh_user = "rhimport";
@@ -89,12 +91,30 @@ sub fetch_parse_rss
return XML::Feed->parse(\$xml);
}
-sub check_key_file
+sub opendb
{
- if(-e "$ssh_key_file") {
- return 1;
- }
- return 0;
+ my $RD_CONF = "/etc/rd.conf";
+ my $cfg = Config::IniFiles->new(-file => $RD_CONF)
+ or return (undef, "Config File Error: " . join("\n", @Config::IniFiles::errors));
+
+ my $dbhost = $cfg->val('mySQL', 'Hostname');
+ my $dbname = $cfg->val('mySQL', 'Database');
+ my $dbuser = $cfg->val('mySQL', 'Loginname');
+ my $dbpasswd = $cfg->val('mySQL', 'Password');
+
+ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd")
+ or return (undef, "Database Error: " . $DBI::errstr);
+
+ $dbh->do(qq{SET CHARACTER SET utf8;})
+ or return (undef, "Database Error: " . $dbh->errstr);
+
+ return ($dbh);
+}
+
+sub closedb
+{
+ my $dbh = shift;
+ $dbh->disconnect();
}
sub get_dropboxes
@@ -218,78 +238,6 @@ sub clear_carts
return $log;
}
-sub check_file_extension
-{
- my ($file) = @_;
-
- my $ext = uc((fileparse($file, qr/\.[^.]*/))[2]);
- foreach (".MP3", ".OGG", ".FLAC", ".WAV") {
- if($ext eq $_) {
- return 1;
- }
- }
- return 0;
-}
-
-sub import_playlist
-{
- my ($playlist, $dropbox, $user, $num_carts, $progress_cb, $error_cb) = @_;
-
- print "Starting import from playlist $playlist to $dropbox";
- my @entries;
- open (FILE, $playlist) or die "can't open playlist $playlist: $!";
- binmode(FILE, ":utf8");
- while (my $entry = <FILE>) {
- next if($entry =~ /^#/);
- next if($entry =~ /^\s/);
- $entry =~ s/\n$//;
- $entry =~ s/^file:\/\///;
- $entry = uri_unescape($entry);
- next if(-d $entry);
- next if(!-r $entry);
- push @entries, $entry;
- }
- close(FILE);
- my $num_entries = scalar(@entries);
- print " ($num_entries Files in list -> $num_carts available)\n";
-
- if($num_carts < $num_entries) {
- if($error_cb) {
- my $ret = $error_cb->("Achtung!\nDie Playlist beinhaltet mehr als $num_carts Dateien. Es werden nur die ersten $num_carts Dateien importiert.");
- if(!$ret) {
- return 0, "too many files in playlist";
- }
-
- $#entries = $num_carts-1;
- $num_entries = scalar(@entries);
- }
- }
- print "will import $num_entries files\n";
-
- my $cnt = 0;
- my $ret = 0;
- my $log = "";
- prepare_import($user);
- for my $entry ( @entries ) {
- $progress_cb->($cnt, $num_entries, $entry) if($progress_cb);
-
- my $out;
- ($ret, $out) = import_file($entry, $dropbox, $user, $error_cb);
- $log .= "\n--- $entry ---\n$out\n" if $out;
- last if($ret == 0);
-
- $cnt++;
- }
-
- if($ret) {
- $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!") if($progress_cb);
- } else {
- $progress_cb->($cnt, $num_entries, "Import abgebrochen!") if($progress_cb);
- }
-
- return ($ret, $log);
-}
-
sub import_single
{
my ($file, $dropbox, $user, $progress_cb, $error_cb) = @_;
@@ -409,7 +357,7 @@ sub delete_file
sub pv_add_note
{
my ( $title, $text, $id, $date, $type, $index ) = @_;
- my @script = ('/usr/bin/ssh', 'root@web', 'addnote', $id, $date, $type);
+ my @script = ('/usr/bin/ssh', 'pv@rdimport', 'addnote', $id, $date, $type);
push(@script , $index) unless (!defined $index);
my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );