Added functionality to manual add, fixed a few UI issues, manual add textbox is still funky
This commit is contained in:
parent
dd3d2c5ca7
commit
1300fbca2d
20
info.sh
Executable file
20
info.sh
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
DATA="./info_raw"
|
||||||
|
|
||||||
|
curl -s "$1" | sed 's/></>\n</g' > $DATA
|
||||||
|
|
||||||
|
ID=$(cat $DATA | grep '<meta itemprop="videoId"' | awk -F "content=" '{print $2}' | tr -d '">')
|
||||||
|
export Length_RAW=$(cat $DATA | grep '<meta itemprop="duration"' | awk -F "content=" '{print $2}' | tr -d '">')
|
||||||
|
Title=$(cat $DATA | grep '<meta itemprop="name"' | awk -F "content=" '{print $2}' | tr -d '">')
|
||||||
|
Channel=$(cat $DATA | grep '<link itemprop="name"' | awk -F "=" '{print $3}' | tr -d '">')
|
||||||
|
Desc=$(cat $DATA | grep '<meta itemprop="description"' | awk -F "content=" '{print $2}' | tr -d '">')
|
||||||
|
export Published_RAW=$(cat $DATA | grep '<meta itemprop="datePublished"' | awk -F "content=" '{print $2}' | tr -d '">')
|
||||||
|
|
||||||
|
Published=$(date -d "2000/1/1 $(date +%s.%N) seconds - $(date -d "$Published_RAW" +%s.%N) seconds" +"%-j days %H:%M:%S ago")
|
||||||
|
|
||||||
|
Length=$(echo $Length_RAW | sed -r 's/PT//' | sed -r 's/([0-9]+)H/\1:/g' | sed -r 's/([0-9]+)M/\1:/g' | sed -r 's/([0-9]+)S/\1/g')
|
||||||
|
|
||||||
|
echo "{'id':'$ID','runtime':'$Length','title':'$Title','channel':'$Channel','description':'$Desc','published':'$Published'}" | tr "'" '"'
|
||||||
|
|
||||||
|
rm $DATA
|
45
ytbrowser.pl
45
ytbrowser.pl
@ -8,9 +8,9 @@ use Digest::SHA1 qw( sha1_hex );
|
|||||||
use Curses;
|
use Curses;
|
||||||
use Curses::UI;
|
use Curses::UI;
|
||||||
|
|
||||||
#use Data::Dumper;
|
use Data::Dumper;
|
||||||
#$Data::Dumper::Indent = 1;
|
$Data::Dumper::Indent = 1;
|
||||||
#$Data::Dumper::Maxdepth = 1;
|
$Data::Dumper::Maxdepth = 1;
|
||||||
|
|
||||||
my $homeDir = "/home/bluesaxman/";
|
my $homeDir = "/home/bluesaxman/";
|
||||||
my $cookiesFile = $homeDir."cookies.txt";
|
my $cookiesFile = $homeDir."cookies.txt";
|
||||||
@ -166,6 +166,11 @@ open(DEBUG, ">", $debugFile);
|
|||||||
open(CACHING, ">", $cachedFile);
|
open(CACHING, ">", $cachedFile);
|
||||||
open(SAVE, ">", $playlistFile);
|
open(SAVE, ">", $playlistFile);
|
||||||
|
|
||||||
|
close(STDERR);
|
||||||
|
open(STDERR, ">>", $debugFile);
|
||||||
|
|
||||||
|
select( (select(DEBUG), $| = 1)[0] );
|
||||||
|
|
||||||
sub sync2files {
|
sub sync2files {
|
||||||
truncate(DEBUG,0);
|
truncate(DEBUG,0);
|
||||||
truncate(CACHING,0);
|
truncate(CACHING,0);
|
||||||
@ -186,8 +191,9 @@ sub sync2files {
|
|||||||
|
|
||||||
my $cui = new Curses::UI( -clear_on_exit => 1, -color_support => 1 );
|
my $cui = new Curses::UI( -clear_on_exit => 1, -color_support => 1 );
|
||||||
my $win = $cui->add( 'main', 'Window');
|
my $win = $cui->add( 'main', 'Window');
|
||||||
my $suggestions = $win->add( 'suggestions', 'Listbox', -pad => 1, -ipad => 1, -border => 1, -title => "Suggestions", -fg => "blue", -bg => "white", -height => $win->height() / 2 , -values => \@suggestArray);
|
my $suggestions = $win->add( 'suggestions', 'Listbox', -pad => 1, -ipad => 1, -border => 1, -title => "Suggestions", -vscrollbar => 'right', -fg => "blue", -bg => "white", -height => $win->height() / 2 , -values => \@suggestArray);
|
||||||
my $wlist = $win->add( 'watchlist', 'Listbox', -pad => 1, -ipad => 1, -border => 1, -title => "Watch list", -fg => "green", -bg => "black", -height => $win->height() / 2, -y => $suggestions->height(), -values => \@watchArray);
|
my $wlist = $win->add( 'watchlist', 'Listbox', -pad => 1, -ipad => 1, -border => 1, -title => "Watch list", -vscrollbar => 'right', -fg => "green", -bg => "black", -height => $win->height() / 2, -y => $suggestions->height(), -values => \@watchArray);
|
||||||
|
my $textEntry = $win->add( 'mytextentry', 'TextEntry', -y => $win->height() / 2, -title => "Manual Video Add");
|
||||||
loadSugs();
|
loadSugs();
|
||||||
|
|
||||||
$cui->set_binding( sub { $cui->mainloopExit(); }, "q" );
|
$cui->set_binding( sub { $cui->mainloopExit(); }, "q" );
|
||||||
@ -285,7 +291,33 @@ $wlist->set_binding( sub {
|
|||||||
}, "<");
|
}, "<");
|
||||||
|
|
||||||
$wlist->set_binding( sub {
|
$wlist->set_binding( sub {
|
||||||
|
print DEBUG "Manually adding a video...\n";
|
||||||
$cui->status("Manual Adding not implimented at this time");
|
$cui->status("Manual Adding not implimented at this time");
|
||||||
|
$textEntry->text("");
|
||||||
|
$textEntry->set_binding( sub {
|
||||||
|
my $text = $textEntry->get();
|
||||||
|
if($text =~ m/youtu(?:\.be\/|be.com\/\S*(?:watch|embed)(?:(?:(?=\/[-a-zA-Z0-9_]{11,}(?!\S))\/)|(?:\S*v=|v\/)))([-a-zA-Z0-9_]{11,})/) {
|
||||||
|
print DEBUG $1."\n";
|
||||||
|
my $videoJsonString = `./info.sh "https://www.youtube.com/watch?v=$1"`;
|
||||||
|
print DEBUG $videoJsonString."\n";
|
||||||
|
my $video = \%{decode_json($videoJsonString)};
|
||||||
|
print DEBUG "Confirming with user\n";
|
||||||
|
print DEBUG Dumper($video)."\n";
|
||||||
|
my $confirm = $cui->dialog(-message => "Here is what we know about that:\nTitle: ".$video->{title}."\nChannel: ".$video->{channel}."\nRuntime: ".$video->{runtime}."\nPublished: ".$video->{published}, -buttons => [{ -label => "Add Video", -value => 1, -shortcut => "a" },'cancel']);
|
||||||
|
print DEBUG $confirm."\n";
|
||||||
|
if ($confirm) {
|
||||||
|
print DEBUG "Attempting to add...\n";
|
||||||
|
push(@watchArray, $video->{runtime}>" ".$video->{title});
|
||||||
|
push(@watchlist, $video);
|
||||||
|
print DEBUG Dumper($video);
|
||||||
|
sync2files();
|
||||||
|
$suggestions->draw();
|
||||||
|
$wlist->draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$wlist->focus();
|
||||||
|
}, KEY_ENTER);
|
||||||
|
$textEntry->focus();
|
||||||
}, "m");
|
}, "m");
|
||||||
|
|
||||||
$suggestions->set_binding( sub {
|
$suggestions->set_binding( sub {
|
||||||
@ -301,6 +333,9 @@ $cui->mainloop();
|
|||||||
|
|
||||||
#Save leftovers
|
#Save leftovers
|
||||||
sync2files();
|
sync2files();
|
||||||
|
|
||||||
|
print DEBUG "Closeing Program\n";
|
||||||
|
|
||||||
close(DEBUG);
|
close(DEBUG);
|
||||||
close(CACHING);
|
close(CACHING);
|
||||||
close(SAVE);
|
close(SAVE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user