summaryrefslogtreecommitdiff
path: root/cgi-bin/playlist
blob: 9b87d6a50054c2587d2142242282fe55c524a302 (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
#!/usr/bin/perl

use localbucky;
use URI::Escape;

$dbh = DBI->connect ($dsn);

our ($USER, $lastlog) = checkin();
our $loggedin = ($USER != -1);

our ($t, $kw, $files) = playlist_init();
playlist_run($t, $kw, $files);

sub playlist_run
  {
  my ($t, $kw, $files) = @_;
  my $sorty = sub { sort {lc($a->{filename}) cmp lc($b->{filename})} @_ };

  my $z_title = $t->{title};
  my $z_link = qq($BUCKY/).details_link().qq(/$t->{id});
  $z_link .= get_revision($t) if ($USER != -1);

  my $rss = <<__RSS__;
<rss version="2.0" xmlns:media="http://">
<channel>
<title>$z_title</title>
<link>$z_link</link>
__RSS__

  foreach my $file ($sorty->(@$files))
    {
    next if (($file->{username} ne $USER->{username}) && $file->{private} && !$whitelist && $USER->{ulevel} != 3);
    next unless ($file->{filename} =~ /mp3$/i);
    my $z_file = $file->{filename};
    my $z_filepath = uri_escape($file->{filename});
    my $z_content = "https://$BUCKY_HOST$live_path/$file->{thread}/$z_filepath";
    $rss .= <<__RSS__;
<item>
<title>$z_file</title>
<link>$z_content</link>
<description></description>
<media:content url="$z_content" type="audio/mpeg" />
</item>
__RSS__
    }

  $rss .= "</channel>\n</rss>\n";

  print "Content-type: text/xml\n\n";
  $rss =~ s/&/&amp;/g;
  print $rss;
  }

sub playlist_init
  {
  $input->{id} ||= $input->{object_from_uri} if defined($input->{object_from_uri});
  my $id = exists($input->{id}) ? $input->{id} : error("No such thread!");

  my $t = get_thread($id);
  error("No such post.") if ($t == -1);
  my $kw = get_keyword($t->{keyword});

  my $files = get_files($t->{id});
#  my $comments = get_comments ($t->{id});

  if ( ! check_privacy($t, $kw) ) # || check_participation($files, $comments) )
  #unless ( check_privacy($t, $kw) || check_participation($files, $comments) )
    { error("No such post!"); }

  # Reset NULL viewed
  if ( ! $t->{viewed} )
    { $t->{viewed} = 0; }

  # Increment viewed for this thread
#  $t->{viewed}++;
  # Update thread viewed count
#  update_thread_viewed( $t->{id}, $t->{viewed} );

  return ($t, $kw, $files); # $comments);
  }