summaryrefslogtreecommitdiff
path: root/odin/strm/manual_youtube
blob: 943ae5d46294873156c987a3337e6c818ff8570d (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
#!@perl@/bin/perl

use utf8;
use strict;
use warnings;

use Email::MIME;

use Email::Date::Format qw(email_date);

our $fromMail = "$ENV{'USER'}\@odin.asgard.yggdrasil";
our $fromName = "manual";

my $i = 0;

my @tags = ();
for (my $j = 0; $j < $#ARGV; $j++)
{
    next unless ($ARGV[$j] eq "--");

    @tags = @ARGV[0 .. $j - 1];
    @ARGV = @ARGV[$j + 1 .. $#ARGV];
    last;
}

# use Data::Dumper;
# print Dumper(@tags, @ARGV);
# exit 1;

foreach my $url (@ARGV)
{
    my $title;
    open(my $fh, '-|', "@youtubedl@/bin/youtube-dl --restrict-filenames --get-title --no-playlist -- '$url'") || die "Could not spawn youtube-dl";
    $title = <$fh>;
    close($fh);
    die "youtube-dl could not extract title" unless (defined($title));
    chomp($title);

    my $mail = Email::MIME->create(
        header_str => [
            From           => "$fromName <$fromMail>",
            To             => 'gkleen@odin.asgard.yggdrasil',
            Subject        => $title,
            'X-RSS-URL'    => $url,
            Date           => email_date(time() + ($i++))
        ],
        attributes => {
            content_type   => 'text/html',
            encoding       => '7bit',
            charset        => 'US-ASCII'
        },
        body => "<a href=\"$url\">$title</a>\n"
        );

    my @args = ();
    push @args, (('junk') x 5);
    push @args, @tags;

    open($fh, '|-', "rss_deliver", @args) || die "Could not spawn rss_deliver";
    print $fh $mail->as_string;
    close($fh);
}