summaryrefslogtreecommitdiff
path: root/rhimport.pl
blob: 29eba44496414da5ca345af44e013afada74b32d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/perl -w
#
#

use strict;

use Getopt::Long;
use DBI;
use Gtk2;
use Gtk2::GladeXML;

my $DBHOST = "airplay";
my $DBUSER = "rivendellro";
my $DBPW = "lldrivenro";
my $DB = "rivendell";
my $HELP = 0;
my $M3U = "";
my $DONTCONCAT = 0;
my $LISTALLOWED = 0;

GetOptions ("help!" => \$HELP,
            "m3u=s" => \$M3U,
            "dont-concat!" => \$DONTCONCAT,
            "list-allowed!" => \$LISTALLOWED,
             );

if($HELP) {
  print << "EOF";
usage: $0 --m3u <playlist file> --dont-concat

options:
     --m3u           the playlist file to import
     --dont-concat   dont concat the audio files, import as seperate files
     --list-allowed  list allowed dropboxes and exit

EOF
  exit;
}

my $user = 'martinland';#$ENV{'USER'};
$user or die "Username not found in environment";

# my $dbh = DBI->connect( "DBI:mysql:$DB:$DBHOST","$DBUSER","$DBPW") or die "Database Error: $DBI::errstr";

# my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH from USER_PERMS, DROPBOXES where USER_PERMS.USER_NAME='$user' and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME;};

# my $sth = $dbh->prepare($sql);
# $sth->execute();
my @allowed_dbs;
# while(my ($group, $path) = $sth->fetchrow_array()) {
#   $path =~ s/\/\*$//;
#   my $perm = {};
#   $perm->{'GROUP'} = $group;
#   $perm->{'PATH'} = $path;
#   push @allowed_dbs, $perm;
# }
# $sth->finish();


if($LISTALLOWED) {
  for my $href ( @allowed_dbs ) {
    print "$href->{'PATH'}\n";
  }
#  $dbh->disconnect();
  exit 0;
}

## GUI mode

if(!$M3U) {
  Gtk2->init;

  my $guixml = Gtk2::GladeXML->new('rhimport.glade');
  $guixml or die "can't load glade xml file";

  my $appwin = $guixml->get_widget('appwin');
  $appwin or die "can't find Main Window";

  $appwin->show;
  
  Gtk2->main;
#  $dbh->disconnect();
  exit 0;
}

## command line mode

(-e "$M3U") or die "file '$M3U' not found";
if($DONTCONCAT) {
  print "Will import $M3U (seperate files), with user $user\n\n";
} else {
  print "Will import $M3U (concatenated), with user $user\n\n";
}

# $dbh->disconnect();
exit 0;