diff --git a/info.sh b/info.sh
new file mode 100755
index 0000000..0ece0d1
--- /dev/null
+++ b/info.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+DATA="./info_raw"
+
+curl -s "$1" | sed 's/>>\n $DATA
+
+ID=$(cat $DATA | grep '')
+export Length_RAW=$(cat $DATA | grep '')
+Title=$(cat $DATA | grep '')
+Channel=$(cat $DATA | grep '')
+Desc=$(cat $DATA | grep '')
+export Published_RAW=$(cat $DATA | grep '')
+
+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
diff --git a/ytbrowser.pl b/ytbrowser.pl
index a551dc8..553105c 100755
--- a/ytbrowser.pl
+++ b/ytbrowser.pl
@@ -8,9 +8,9 @@ use Digest::SHA1 qw( sha1_hex );
use Curses;
use Curses::UI;
-#use Data::Dumper;
-#$Data::Dumper::Indent = 1;
-#$Data::Dumper::Maxdepth = 1;
+use Data::Dumper;
+$Data::Dumper::Indent = 1;
+$Data::Dumper::Maxdepth = 1;
my $homeDir = "/home/bluesaxman/";
my $cookiesFile = $homeDir."cookies.txt";
@@ -166,6 +166,11 @@ open(DEBUG, ">", $debugFile);
open(CACHING, ">", $cachedFile);
open(SAVE, ">", $playlistFile);
+close(STDERR);
+open(STDERR, ">>", $debugFile);
+
+select( (select(DEBUG), $| = 1)[0] );
+
sub sync2files {
truncate(DEBUG,0);
truncate(CACHING,0);
@@ -186,8 +191,9 @@ sub sync2files {
my $cui = new Curses::UI( -clear_on_exit => 1, -color_support => 1 );
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 $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 $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", -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();
$cui->set_binding( sub { $cui->mainloopExit(); }, "q" );
@@ -285,7 +291,33 @@ $wlist->set_binding( sub {
}, "<");
$wlist->set_binding( sub {
+ print DEBUG "Manually adding a video...\n";
$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");
$suggestions->set_binding( sub {
@@ -301,6 +333,9 @@ $cui->mainloop();
#Save leftovers
sync2files();
+
+print DEBUG "Closeing Program\n";
+
close(DEBUG);
close(CACHING);
close(SAVE);