aboutsummaryrefslogtreecommitdiffstats
path: root/sys/nixpkgs
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-01-20 18:38:18 +0100
committerSoispha <soispha@vhack.eu>2024-01-20 18:38:18 +0100
commitb53a8d82a07c29010a690b7126795fd7ddcabe0c (patch)
tree203dd0581950f9acb75881383d4b6fbc849e91af /sys/nixpkgs
parentfix(sys/nixpkgs/yt/constants): Add extension to last selection path (diff)
downloadnixos-config-b53a8d82a07c29010a690b7126795fd7ddcabe0c.zip
feat(sys/nixpkgs/yt): Add support for the 'url' command
This simply opens the youtube url in the browser
Diffstat (limited to 'sys/nixpkgs')
-rw-r--r--sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js2
-rw-r--r--sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json14
-rw-r--r--sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json8
-rw-r--r--sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c417
-rw-r--r--sys/nixpkgs/pkgs/yt/.envrc1
-rw-r--r--sys/nixpkgs/pkgs/yt/Cargo.toml2
-rw-r--r--sys/nixpkgs/pkgs/yt/default.nix6
-rw-r--r--sys/nixpkgs/pkgs/yt/flake.lock85
-rw-r--r--sys/nixpkgs/pkgs/yt/flake.nix36
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs46
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs2
-rw-r--r--sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs52
-rw-r--r--sys/nixpkgs/pkgs/yt/src/constants.rs23
-rw-r--r--sys/nixpkgs/pkgs/yt/src/downloader.rs15
-rw-r--r--sys/nixpkgs/pkgs/yt/src/help.str7
-rw-r--r--sys/nixpkgs/pkgs/yt/src/lib.rs31
16 files changed, 462 insertions, 285 deletions
diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js b/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js
index 722d6a44..655f6dea 100644
--- a/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js
+++ b/sys/nixpkgs/pkgs/tree-sitter-yts/grammar.js
@@ -6,7 +6,7 @@ module.exports = grammar({
line: ($) =>
seq($.command, $.id, $.title, $.date, $.author, $.duration, $.url, "\n"),
- command: ($) => choice("pick", "watch", "drop", "p", "w", "d"),
+ command: ($) => choice("pick", "p", "watch", "w", "drop", "d", "url", "u"),
id: ($) => /[0-9]+/,
title: ($) => seq($._q, /[^"]+/, $._q),
date: ($) => seq($._q, /\d{4}-\d{2}-\d{2}/, $._q),
diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json b/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json
index 4157fde6..a35a5464 100644
--- a/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json
+++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/grammar.json
@@ -63,23 +63,31 @@
},
{
"type": "STRING",
+ "value": "p"
+ },
+ {
+ "type": "STRING",
"value": "watch"
},
{
"type": "STRING",
+ "value": "w"
+ },
+ {
+ "type": "STRING",
"value": "drop"
},
{
"type": "STRING",
- "value": "p"
+ "value": "d"
},
{
"type": "STRING",
- "value": "w"
+ "value": "url"
},
{
"type": "STRING",
- "value": "d"
+ "value": "u"
}
]
},
diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json b/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json
index 1dcd3402..1a63a552 100644
--- a/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json
+++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/node-types.json
@@ -182,6 +182,14 @@
"named": true
},
{
+ "type": "u",
+ "named": false
+ },
+ {
+ "type": "url",
+ "named": false
+ },
+ {
"type": "w",
"named": false
},
diff --git a/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c b/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c
index fc86808b..5b02c3d0 100644
--- a/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c
+++ b/sys/nixpkgs/pkgs/tree-sitter-yts/src/parser.c
@@ -8,9 +8,9 @@
#define LANGUAGE_VERSION 14
#define STATE_COUNT 31
#define LARGE_STATE_COUNT 2
-#define SYMBOL_COUNT 28
+#define SYMBOL_COUNT 30
#define ALIAS_COUNT 0
-#define TOKEN_COUNT 18
+#define TOKEN_COUNT 20
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 0
#define MAX_ALIAS_SEQUENCE_LENGTH 8
@@ -19,42 +19,46 @@
enum {
anon_sym_LF = 1,
anon_sym_pick = 2,
- anon_sym_watch = 3,
- anon_sym_drop = 4,
- anon_sym_p = 5,
- anon_sym_w = 6,
+ anon_sym_p = 3,
+ anon_sym_watch = 4,
+ anon_sym_w = 5,
+ anon_sym_drop = 6,
anon_sym_d = 7,
- sym_id = 8,
- aux_sym_title_token1 = 9,
- aux_sym_date_token1 = 10,
- anon_sym_LBRACK = 11,
- anon_sym_NoDuration = 12,
- aux_sym_duration_token1 = 13,
- aux_sym_duration_token2 = 14,
- anon_sym_RBRACK = 15,
- sym_comment = 16,
- sym_quote = 17,
- sym_source_file = 18,
- sym_line = 19,
- sym_command = 20,
- sym_title = 21,
- sym_date = 22,
- sym_author = 23,
- sym_duration = 24,
- sym_url = 25,
- sym__q = 26,
- aux_sym_source_file_repeat1 = 27,
+ anon_sym_url = 8,
+ anon_sym_u = 9,
+ sym_id = 10,
+ aux_sym_title_token1 = 11,
+ aux_sym_date_token1 = 12,
+ anon_sym_LBRACK = 13,
+ anon_sym_NoDuration = 14,
+ aux_sym_duration_token1 = 15,
+ aux_sym_duration_token2 = 16,
+ anon_sym_RBRACK = 17,
+ sym_comment = 18,
+ sym_quote = 19,
+ sym_source_file = 20,
+ sym_line = 21,
+ sym_command = 22,
+ sym_title = 23,
+ sym_date = 24,
+ sym_author = 25,
+ sym_duration = 26,
+ sym_url = 27,
+ sym__q = 28,
+ aux_sym_source_file_repeat1 = 29,
};
static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
[anon_sym_LF] = "\n",
[anon_sym_pick] = "pick",
- [anon_sym_watch] = "watch",
- [anon_sym_drop] = "drop",
[anon_sym_p] = "p",
+ [anon_sym_watch] = "watch",
[anon_sym_w] = "w",
+ [anon_sym_drop] = "drop",
[anon_sym_d] = "d",
+ [anon_sym_url] = "url",
+ [anon_sym_u] = "u",
[sym_id] = "id",
[aux_sym_title_token1] = "title_token1",
[aux_sym_date_token1] = "date_token1",
@@ -81,11 +85,13 @@ static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
[anon_sym_LF] = anon_sym_LF,
[anon_sym_pick] = anon_sym_pick,
- [anon_sym_watch] = anon_sym_watch,
- [anon_sym_drop] = anon_sym_drop,
[anon_sym_p] = anon_sym_p,
+ [anon_sym_watch] = anon_sym_watch,
[anon_sym_w] = anon_sym_w,
+ [anon_sym_drop] = anon_sym_drop,
[anon_sym_d] = anon_sym_d,
+ [anon_sym_url] = anon_sym_url,
+ [anon_sym_u] = anon_sym_u,
[sym_id] = sym_id,
[aux_sym_title_token1] = aux_sym_title_token1,
[aux_sym_date_token1] = aux_sym_date_token1,
@@ -121,23 +127,31 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = true,
.named = false,
},
+ [anon_sym_p] = {
+ .visible = true,
+ .named = false,
+ },
[anon_sym_watch] = {
.visible = true,
.named = false,
},
+ [anon_sym_w] = {
+ .visible = true,
+ .named = false,
+ },
[anon_sym_drop] = {
.visible = true,
.named = false,
},
- [anon_sym_p] = {
+ [anon_sym_d] = {
.visible = true,
.named = false,
},
- [anon_sym_w] = {
+ [anon_sym_url] = {
.visible = true,
.named = false,
},
- [anon_sym_d] = {
+ [anon_sym_u] = {
.visible = true,
.named = false,
},
@@ -270,21 +284,22 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
eof = lexer->eof(lexer);
switch (state) {
case 0:
- if (eof) ADVANCE(46);
- if (lookahead == '"') ADVANCE(71);
- if (lookahead == '#') ADVANCE(70);
- if (lookahead == 'N') ADVANCE(29);
- if (lookahead == '[') ADVANCE(65);
- if (lookahead == '\\') SKIP(45)
- if (lookahead == ']') ADVANCE(69);
- if (lookahead == 'd') ADVANCE(53);
- if (lookahead == 'p') ADVANCE(51);
+ if (eof) ADVANCE(47);
+ if (lookahead == '"') ADVANCE(74);
+ if (lookahead == '#') ADVANCE(73);
+ if (lookahead == 'N') ADVANCE(30);
+ if (lookahead == '[') ADVANCE(68);
+ if (lookahead == '\\') SKIP(46)
+ if (lookahead == ']') ADVANCE(72);
+ if (lookahead == 'd') ADVANCE(54);
+ if (lookahead == 'p') ADVANCE(50);
+ if (lookahead == 'u') ADVANCE(56);
if (lookahead == 'w') ADVANCE(52);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') SKIP(0)
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(57);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(60);
END_STATE();
case 1:
if (lookahead == '\n') SKIP(14)
@@ -308,7 +323,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (lookahead == '\r') SKIP(5)
END_STATE();
case 7:
- if (lookahead == '\n') ADVANCE(47);
+ if (lookahead == '\n') ADVANCE(48);
if (lookahead == '\\') SKIP(6)
if (lookahead == '\t' ||
lookahead == '\r' ||
@@ -318,25 +333,25 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (lookahead == ' ') ADVANCE(13);
END_STATE();
case 9:
- if (lookahead == ' ') ADVANCE(38);
+ if (lookahead == ' ') ADVANCE(39);
END_STATE();
case 10:
- if (lookahead == ' ') ADVANCE(39);
+ if (lookahead == ' ') ADVANCE(40);
END_STATE();
case 11:
- if (lookahead == '-') ADVANCE(42);
+ if (lookahead == '-') ADVANCE(43);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(24);
END_STATE();
case 12:
- if (lookahead == '-') ADVANCE(43);
+ if (lookahead == '-') ADVANCE(44);
END_STATE();
case 13:
- if (lookahead == 'D') ADVANCE(37);
+ if (lookahead == 'D') ADVANCE(38);
END_STATE();
case 14:
- if (lookahead == 'N') ADVANCE(29);
+ if (lookahead == 'N') ADVANCE(30);
if (lookahead == '\\') SKIP(2)
if (lookahead == '\t' ||
lookahead == '\n' ||
@@ -345,13 +360,13 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(23);
END_STATE();
case 15:
- if (lookahead == '\\') ADVANCE(60);
+ if (lookahead == '\\') ADVANCE(63);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
- lookahead == ' ') ADVANCE(62);
+ lookahead == ' ') ADVANCE(65);
if (lookahead != 0 &&
- lookahead != '"') ADVANCE(63);
+ lookahead != '"') ADVANCE(66);
END_STATE();
case 16:
if (lookahead == '\\') SKIP(4)
@@ -359,10 +374,10 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') SKIP(16)
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(59);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(62);
END_STATE();
case 17:
- if (lookahead == 'a') ADVANCE(35);
+ if (lookahead == 'a') ADVANCE(36);
END_STATE();
case 18:
if (lookahead == 'c') ADVANCE(26);
@@ -371,7 +386,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (lookahead == 'c') ADVANCE(20);
END_STATE();
case 20:
- if (lookahead == 'h') ADVANCE(49);
+ if (lookahead == 'h') ADVANCE(51);
END_STATE();
case 21:
if (lookahead == 'h') ADVANCE(9);
@@ -394,188 +409,198 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(24);
END_STATE();
case 25:
- if (lookahead == 'i') ADVANCE(31);
+ if (lookahead == 'i') ADVANCE(32);
END_STATE();
case 26:
- if (lookahead == 'k') ADVANCE(48);
+ if (lookahead == 'k') ADVANCE(49);
END_STATE();
case 27:
- if (lookahead == 'm') ADVANCE(68);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(27);
+ if (lookahead == 'l') ADVANCE(55);
END_STATE();
case 28:
- if (lookahead == 'n') ADVANCE(66);
+ if (lookahead == 'm') ADVANCE(71);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(28);
END_STATE();
case 29:
- if (lookahead == 'o') ADVANCE(8);
+ if (lookahead == 'n') ADVANCE(69);
END_STATE();
case 30:
- if (lookahead == 'o') ADVANCE(32);
+ if (lookahead == 'o') ADVANCE(8);
END_STATE();
case 31:
- if (lookahead == 'o') ADVANCE(28);
+ if (lookahead == 'o') ADVANCE(33);
END_STATE();
case 32:
- if (lookahead == 'p') ADVANCE(50);
+ if (lookahead == 'o') ADVANCE(29);
END_STATE();
case 33:
- if (lookahead == 'r') ADVANCE(17);
+ if (lookahead == 'p') ADVANCE(53);
END_STATE();
case 34:
- if (lookahead == 's') ADVANCE(67);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34);
+ if (lookahead == 'r') ADVANCE(17);
END_STATE();
case 35:
- if (lookahead == 't') ADVANCE(25);
+ if (lookahead == 's') ADVANCE(70);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(35);
END_STATE();
case 36:
- if (lookahead == 't') ADVANCE(19);
+ if (lookahead == 't') ADVANCE(25);
END_STATE();
case 37:
- if (lookahead == 'u') ADVANCE(33);
+ if (lookahead == 't') ADVANCE(19);
END_STATE();
case 38:
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(27);
+ if (lookahead == 'u') ADVANCE(34);
END_STATE();
case 39:
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(28);
END_STATE();
case 40:
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(35);
END_STATE();
case 41:
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(64);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE();
case 42:
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(40);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(67);
END_STATE();
case 43:
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(41);
END_STATE();
case 44:
- if (eof) ADVANCE(46);
- if (lookahead == '\n') SKIP(0)
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(42);
END_STATE();
case 45:
- if (eof) ADVANCE(46);
+ if (eof) ADVANCE(47);
if (lookahead == '\n') SKIP(0)
- if (lookahead == '\r') SKIP(44)
END_STATE();
case 46:
- ACCEPT_TOKEN(ts_builtin_sym_end);
+ if (eof) ADVANCE(47);
+ if (lookahead == '\n') SKIP(0)
+ if (lookahead == '\r') SKIP(45)
END_STATE();
case 47:
- ACCEPT_TOKEN(anon_sym_LF);
- if (lookahead == '\n') ADVANCE(47);
+ ACCEPT_TOKEN(ts_builtin_sym_end);
END_STATE();
case 48:
- ACCEPT_TOKEN(anon_sym_pick);
+ ACCEPT_TOKEN(anon_sym_LF);
+ if (lookahead == '\n') ADVANCE(48);
END_STATE();
case 49:
- ACCEPT_TOKEN(anon_sym_watch);
+ ACCEPT_TOKEN(anon_sym_pick);
END_STATE();
case 50:
- ACCEPT_TOKEN(anon_sym_drop);
- END_STATE();
- case 51:
ACCEPT_TOKEN(anon_sym_p);
if (lookahead == 'i') ADVANCE(18);
END_STATE();
+ case 51:
+ ACCEPT_TOKEN(anon_sym_watch);
+ END_STATE();
case 52:
ACCEPT_TOKEN(anon_sym_w);
- if (lookahead == 'a') ADVANCE(36);
+ if (lookahead == 'a') ADVANCE(37);
END_STATE();
case 53:
- ACCEPT_TOKEN(anon_sym_d);
- if (lookahead == 'r') ADVANCE(30);
+ ACCEPT_TOKEN(anon_sym_drop);
END_STATE();
case 54:
+ ACCEPT_TOKEN(anon_sym_d);
+ if (lookahead == 'r') ADVANCE(31);
+ END_STATE();
+ case 55:
+ ACCEPT_TOKEN(anon_sym_url);
+ END_STATE();
+ case 56:
+ ACCEPT_TOKEN(anon_sym_u);
+ if (lookahead == 'r') ADVANCE(27);
+ END_STATE();
+ case 57:
ACCEPT_TOKEN(sym_id);
- if (lookahead == '-') ADVANCE(42);
+ if (lookahead == '-') ADVANCE(43);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(58);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(61);
END_STATE();
- case 55:
+ case 58:
ACCEPT_TOKEN(sym_id);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(54);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(57);
END_STATE();
- case 56:
+ case 59:
ACCEPT_TOKEN(sym_id);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(55);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(58);
END_STATE();
- case 57:
+ case 60:
ACCEPT_TOKEN(sym_id);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(56);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(59);
END_STATE();
- case 58:
+ case 61:
ACCEPT_TOKEN(sym_id);
if (lookahead == 'h') ADVANCE(9);
if (lookahead == 'm') ADVANCE(10);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(58);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(61);
END_STATE();
- case 59:
+ case 62:
ACCEPT_TOKEN(sym_id);
- if (('0' <= lookahead && lookahead <= '9')) ADVANCE(59);
+ if (('0' <= lookahead && lookahead <= '9')) ADVANCE(62);
END_STATE();
- case 60:
+ case 63:
ACCEPT_TOKEN(aux_sym_title_token1);
- if (lookahead == '\n') ADVANCE(62);
- if (lookahead == '\r') ADVANCE(61);
+ if (lookahead == '\n') ADVANCE(65);
+ if (lookahead == '\r') ADVANCE(64);
if (lookahead != 0 &&
- lookahead != '"') ADVANCE(63);
+ lookahead != '"') ADVANCE(66);
END_STATE();
- case 61:
+ case 64:
ACCEPT_TOKEN(aux_sym_title_token1);
- if (lookahead == '\n') ADVANCE(62);
+ if (lookahead == '\n') ADVANCE(65);
if (lookahead != 0 &&
- lookahead != '"') ADVANCE(63);
+ lookahead != '"') ADVANCE(66);
END_STATE();
- case 62:
+ case 65:
ACCEPT_TOKEN(aux_sym_title_token1);
- if (lookahead == '\\') ADVANCE(60);
+ if (lookahead == '\\') ADVANCE(63);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
- lookahead == ' ') ADVANCE(62);
+ lookahead == ' ') ADVANCE(65);
if (lookahead != 0 &&
- lookahead != '"') ADVANCE(63);
+ lookahead != '"') ADVANCE(66);
END_STATE();
- case 63:
+ case 66:
ACCEPT_TOKEN(aux_sym_title_token1);
if (lookahead != 0 &&
- lookahead != '"') ADVANCE(63);
+ lookahead != '"') ADVANCE(66);
END_STATE();
- case 64:
+ case 67:
ACCEPT_TOKEN(aux_sym_date_token1);
END_STATE();
- case 65:
+ case 68:
ACCEPT_TOKEN(anon_sym_LBRACK);
END_STATE();
- case 66:
+ case 69:
ACCEPT_TOKEN(anon_sym_NoDuration);
END_STATE();
- case 67:
+ case 70:
ACCEPT_TOKEN(aux_sym_duration_token1);
END_STATE();
- case 68:
+ case 71:
ACCEPT_TOKEN(aux_sym_duration_token2);
END_STATE();
- case 69:
+ case 72:
ACCEPT_TOKEN(anon_sym_RBRACK);
END_STATE();
- case 70:
+ case 73:
ACCEPT_TOKEN(sym_comment);
if (lookahead != 0 &&
- lookahead != '\n') ADVANCE(70);
+ lookahead != '\n') ADVANCE(73);
END_STATE();
- case 71:
+ case 74:
ACCEPT_TOKEN(sym_quote);
END_STATE();
default:
@@ -621,11 +646,13 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
[anon_sym_pick] = ACTIONS(1),
- [anon_sym_watch] = ACTIONS(1),
- [anon_sym_drop] = ACTIONS(1),
[anon_sym_p] = ACTIONS(1),
+ [anon_sym_watch] = ACTIONS(1),
[anon_sym_w] = ACTIONS(1),
+ [anon_sym_drop] = ACTIONS(1),
[anon_sym_d] = ACTIONS(1),
+ [anon_sym_url] = ACTIONS(1),
+ [anon_sym_u] = ACTIONS(1),
[sym_id] = ACTIONS(1),
[aux_sym_date_token1] = ACTIONS(1),
[anon_sym_LBRACK] = ACTIONS(1),
@@ -643,11 +670,13 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[aux_sym_source_file_repeat1] = STATE(2),
[ts_builtin_sym_end] = ACTIONS(3),
[anon_sym_pick] = ACTIONS(5),
- [anon_sym_watch] = ACTIONS(5),
- [anon_sym_drop] = ACTIONS(5),
[anon_sym_p] = ACTIONS(7),
+ [anon_sym_watch] = ACTIONS(5),
[anon_sym_w] = ACTIONS(7),
+ [anon_sym_drop] = ACTIONS(5),
[anon_sym_d] = ACTIONS(7),
+ [anon_sym_url] = ACTIONS(5),
+ [anon_sym_u] = ACTIONS(7),
[sym_comment] = ACTIONS(9),
},
};
@@ -663,15 +692,17 @@ static const uint16_t ts_small_parse_table[] = {
STATE(3), 2,
sym_line,
aux_sym_source_file_repeat1,
- ACTIONS(5), 3,
+ ACTIONS(5), 4,
anon_sym_pick,
anon_sym_watch,
anon_sym_drop,
- ACTIONS(7), 3,
+ anon_sym_url,
+ ACTIONS(7), 4,
anon_sym_p,
anon_sym_w,
anon_sym_d,
- [24] = 6,
+ anon_sym_u,
+ [26] = 6,
ACTIONS(15), 1,
ts_builtin_sym_end,
ACTIONS(23), 1,
@@ -681,167 +712,171 @@ static const uint16_t ts_small_parse_table[] = {
STATE(3), 2,
sym_line,
aux_sym_source_file_repeat1,
- ACTIONS(17), 3,
+ ACTIONS(17), 4,
anon_sym_pick,
anon_sym_watch,
anon_sym_drop,
- ACTIONS(20), 3,
+ anon_sym_url,
+ ACTIONS(20), 4,
anon_sym_p,
anon_sym_w,
anon_sym_d,
- [48] = 2,
- ACTIONS(28), 3,
+ anon_sym_u,
+ [52] = 2,
+ ACTIONS(28), 4,
anon_sym_p,
anon_sym_w,
anon_sym_d,
- ACTIONS(26), 5,
+ anon_sym_u,
+ ACTIONS(26), 6,
ts_builtin_sym_end,
anon_sym_pick,
anon_sym_watch,
anon_sym_drop,
+ anon_sym_url,
sym_comment,
- [61] = 3,
+ [67] = 3,
ACTIONS(30), 1,
sym_quote,
STATE(21), 1,
sym_url,
STATE(22), 1,
sym__q,
- [71] = 3,
+ [77] = 3,
ACTIONS(32), 1,
sym_quote,
STATE(7), 1,
sym_title,
STATE(25), 1,
sym__q,
- [81] = 3,
+ [87] = 3,
ACTIONS(34), 1,
sym_quote,
STATE(9), 1,
sym_date,
STATE(23), 1,
sym__q,
- [91] = 1,
+ [97] = 1,
ACTIONS(36), 3,
anon_sym_NoDuration,
aux_sym_duration_token1,
aux_sym_duration_token2,
- [97] = 3,
+ [103] = 3,
ACTIONS(38), 1,
sym_quote,
STATE(10), 1,
sym_author,
STATE(16), 1,
sym__q,
- [107] = 3,
+ [113] = 3,
ACTIONS(40), 1,
sym_quote,
STATE(5), 1,
sym_duration,
STATE(18), 1,
sym__q,
- [117] = 2,
+ [123] = 2,
ACTIONS(42), 1,
sym_quote,
STATE(30), 1,
sym__q,
- [124] = 2,
+ [130] = 2,
ACTIONS(44), 1,
sym_quote,
STATE(28), 1,
sym__q,
- [131] = 2,
+ [137] = 2,
ACTIONS(46), 1,
sym_quote,
STATE(24), 1,
sym__q,
- [138] = 2,
+ [144] = 2,
ACTIONS(48), 1,
sym_quote,
STATE(17), 1,
sym__q,
- [145] = 2,
+ [151] = 2,
ACTIONS(50), 1,
sym_quote,
STATE(20), 1,
sym__q,
- [152] = 1,
+ [158] = 1,
ACTIONS(52), 1,
aux_sym_title_token1,
- [156] = 1,
+ [162] = 1,
ACTIONS(54), 1,
sym_quote,
- [160] = 1,
+ [166] = 1,
ACTIONS(56), 1,
anon_sym_LBRACK,
- [164] = 1,
+ [170] = 1,
ACTIONS(58), 1,
sym_id,
- [168] = 1,
+ [174] = 1,
ACTIONS(60), 1,
sym_quote,
- [172] = 1,
+ [178] = 1,
ACTIONS(62), 1,
anon_sym_LF,
- [176] = 1,
+ [182] = 1,
ACTIONS(64), 1,
aux_sym_title_token1,
- [180] = 1,
+ [186] = 1,
ACTIONS(66), 1,
aux_sym_date_token1,
- [184] = 1,
+ [190] = 1,
ACTIONS(68), 1,
sym_quote,
- [188] = 1,
+ [194] = 1,
ACTIONS(70), 1,
aux_sym_title_token1,
- [192] = 1,
+ [198] = 1,
ACTIONS(72), 1,
sym_id,
- [196] = 1,
+ [202] = 1,
ACTIONS(74), 1,
anon_sym_RBRACK,
- [200] = 1,
+ [206] = 1,
ACTIONS(76), 1,
anon_sym_LF,
- [204] = 1,
+ [210] = 1,
ACTIONS(78), 1,
ts_builtin_sym_end,
- [208] = 1,
+ [214] = 1,
ACTIONS(80), 1,
sym_quote,
};
static const uint32_t ts_small_parse_table_map[] = {
[SMALL_STATE(2)] = 0,
- [SMALL_STATE(3)] = 24,
- [SMALL_STATE(4)] = 48,
- [SMALL_STATE(5)] = 61,
- [SMALL_STATE(6)] = 71,
- [SMALL_STATE(7)] = 81,
- [SMALL_STATE(8)] = 91,
- [SMALL_STATE(9)] = 97,
- [SMALL_STATE(10)] = 107,
- [SMALL_STATE(11)] = 117,
- [SMALL_STATE(12)] = 124,
- [SMALL_STATE(13)] = 131,
- [SMALL_STATE(14)] = 138,
- [SMALL_STATE(15)] = 145,
- [SMALL_STATE(16)] = 152,
- [SMALL_STATE(17)] = 156,
- [SMALL_STATE(18)] = 160,
- [SMALL_STATE(19)] = 164,
- [SMALL_STATE(20)] = 168,
- [SMALL_STATE(21)] = 172,
- [SMALL_STATE(22)] = 176,
- [SMALL_STATE(23)] = 180,
- [SMALL_STATE(24)] = 184,
- [SMALL_STATE(25)] = 188,
- [SMALL_STATE(26)] = 192,
- [SMALL_STATE(27)] = 196,
- [SMALL_STATE(28)] = 200,
- [SMALL_STATE(29)] = 204,
- [SMALL_STATE(30)] = 208,
+ [SMALL_STATE(3)] = 26,
+ [SMALL_STATE(4)] = 52,
+ [SMALL_STATE(5)] = 67,
+ [SMALL_STATE(6)] = 77,
+ [SMALL_STATE(7)] = 87,
+ [SMALL_STATE(8)] = 97,
+ [SMALL_STATE(9)] = 103,
+ [SMALL_STATE(10)] = 113,
+ [SMALL_STATE(11)] = 123,
+ [SMALL_STATE(12)] = 130,
+ [SMALL_STATE(13)] = 137,
+ [SMALL_STATE(14)] = 144,
+ [SMALL_STATE(15)] = 151,
+ [SMALL_STATE(16)] = 158,
+ [SMALL_STATE(17)] = 162,
+ [SMALL_STATE(18)] = 166,
+ [SMALL_STATE(19)] = 170,
+ [SMALL_STATE(20)] = 174,
+ [SMALL_STATE(21)] = 178,
+ [SMALL_STATE(22)] = 182,
+ [SMALL_STATE(23)] = 186,
+ [SMALL_STATE(24)] = 190,
+ [SMALL_STATE(25)] = 194,
+ [SMALL_STATE(26)] = 198,
+ [SMALL_STATE(27)] = 202,
+ [SMALL_STATE(28)] = 206,
+ [SMALL_STATE(29)] = 210,
+ [SMALL_STATE(30)] = 214,
};
static const TSParseActionEntry ts_parse_actions[] = {
diff --git a/sys/nixpkgs/pkgs/yt/.envrc b/sys/nixpkgs/pkgs/yt/.envrc
new file mode 100644
index 00000000..3550a30f
--- /dev/null
+++ b/sys/nixpkgs/pkgs/yt/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/sys/nixpkgs/pkgs/yt/Cargo.toml b/sys/nixpkgs/pkgs/yt/Cargo.toml
index faad6699..04d4518f 100644
--- a/sys/nixpkgs/pkgs/yt/Cargo.toml
+++ b/sys/nixpkgs/pkgs/yt/Cargo.toml
@@ -20,7 +20,7 @@ url = "2.5.0"
yts = []
ytc = []
yt = []
-default = ["yt"]
+default = ["yt", "yts", "ytc"]
[[bin]]
name = "yts"
diff --git a/sys/nixpkgs/pkgs/yt/default.nix b/sys/nixpkgs/pkgs/yt/default.nix
index 63bce5c3..32396051 100644
--- a/sys/nixpkgs/pkgs/yt/default.nix
+++ b/sys/nixpkgs/pkgs/yt/default.nix
@@ -8,7 +8,7 @@
makeWrapper
rustPlatform
# dependencies
-
+
ytcc
yt-dlp
mpv
@@ -25,7 +25,7 @@
makeWrapper
rustPlatform
# dependencies
-
+
ytcc
;
};
@@ -40,7 +40,7 @@
makeWrapper
rustPlatform
# dependencies
-
+
ytcc
yt-dlp
mpv
diff --git a/sys/nixpkgs/pkgs/yt/flake.lock b/sys/nixpkgs/pkgs/yt/flake.lock
new file mode 100644
index 00000000..4e6d0ce1
--- /dev/null
+++ b/sys/nixpkgs/pkgs/yt/flake.lock
@@ -0,0 +1,85 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1705309234,
+ "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1705496572,
+ "narHash": "sha256-rPIe9G5EBLXdBdn9ilGc0nq082lzQd0xGGe092R/5QE=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "842d9d80cfd4560648c785f8a4e6f3b096790e19",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs",
+ "rust-overlay": "rust-overlay"
+ }
+ },
+ "rust-overlay": {
+ "inputs": {
+ "flake-utils": [
+ "flake-utils"
+ ],
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1705716951,
+ "narHash": "sha256-Yp4EkRWoXX57a7hDyx6xJDTtl0h1WRFdRlp9SejPPOQ=",
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "rev": "612b6a974cb921fe7aa4cafd54f4f5f899b19173",
+ "type": "github"
+ },
+ "original": {
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/sys/nixpkgs/pkgs/yt/flake.nix b/sys/nixpkgs/pkgs/yt/flake.nix
new file mode 100644
index 00000000..5f711304
--- /dev/null
+++ b/sys/nixpkgs/pkgs/yt/flake.nix
@@ -0,0 +1,36 @@
+{
+ description = "yt";
+
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = {
+ self,
+ nixpkgs,
+ flake-utils,
+ }: (flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages."${system}";
+ in {
+ devShells.default = pkgs.mkShell {
+ packages = with pkgs; [
+ # rust stuff
+ cargo
+ cargo-clippy
+ cargo-fmt
+ clippy-driver
+ rust-gdb
+ rust-gdbgui
+ rust-lldb
+ rustc
+ rustdoc
+ rustfmt
+
+ cargo-edit
+ cargo-expand
+ ];
+ };
+ }));
+}
diff --git a/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
index ae1bcacd..f3c16613 100644
--- a/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
+++ b/sys/nixpkgs/pkgs/yt/src/bin/yt/main.rs
@@ -7,8 +7,8 @@ use std::{
use tempfile::Builder;
use yt::{
constants::{last_select, HELP_STR},
- downloader::{Downloadable, Downloader},
- ytcc_drop, Line, LineCommand, YtccListData,
+ downloader::Downloader,
+ filter_line, YtccListData,
};
fn main() -> Result<()> {
@@ -41,16 +41,14 @@ fn main() -> Result<()> {
{
let mut edit_file = BufWriter::new(&temp_file);
- json_map
- .iter()
- .map(|line| line.to_string())
- .for_each(|line| {
- edit_file
- .write(line.as_bytes())
- .expect("This write should not fail");
- });
+ json_map.iter().for_each(|line| {
+ let line = line.to_string();
+ edit_file
+ .write_all(line.as_bytes())
+ .expect("This write should not fail");
+ });
- edit_file.write(HELP_STR.as_bytes())?;
+ edit_file.write_all(HELP_STR.as_bytes())?;
edit_file.flush().context("Failed to flush edit file")?;
let mut nvim = StdCmd::new("nvim");
@@ -64,7 +62,7 @@ fn main() -> Result<()> {
let read_file = temp_file.reopen()?;
fs::copy(
temp_file.path(),
- last_select().context("Failed to get persistent the selection file path")?,
+ last_select().context("Failed to get the persistent selection file path")?,
)
.context("Failed to persist selection file")?;
@@ -73,28 +71,14 @@ fn main() -> Result<()> {
for line in reader.lines() {
let line = line.context("Failed to read line")?;
- if line.starts_with("#") {
- // comment
- continue;
- } else if line.trim().len() == 0 {
- // empty line
- continue;
- }
-
- let line = Line::from(line.as_str());
- match line.cmd {
- LineCommand::Pick => (),
- LineCommand::Drop => {
- ytcc_drop(line.id).with_context(|| format!("Failed to drop: {}", line.id))?
- }
- LineCommand::Watch => watching.push(Downloadable {
- id: Some(line.id),
- url: line.url,
- }),
+ if let Some(downloadable) =
+ filter_line(&line).with_context(|| format!("Failed to process line: '{}'", line))?
+ {
+ watching.push(downloadable);
}
}
- if watching.len() == 0 {
+ if watching.is_empty() {
return Ok(());
}
diff --git a/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
index 437df803..3fa3148d 100644
--- a/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
+++ b/sys/nixpkgs/pkgs/yt/src/bin/ytc/main.rs
@@ -37,7 +37,7 @@ fn main() -> Result<()> {
)
.context("Failed to deserialize json output")?;
- if json.len() == 0 {
+ if json.is_empty() {
bail!("Could not find a video with id: {}", id);
}
assert_eq!(json.len(), 1);
diff --git a/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs b/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs
index 788ecab2..7398db61 100644
--- a/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs
+++ b/sys/nixpkgs/pkgs/yt/src/bin/yts/main.rs
@@ -6,7 +6,7 @@ use std::{
process::Command as StdCmd,
};
use tempfile::NamedTempFile;
-use yt::{constants::HELP_STR, ytcc_drop, Line, LineCommand, YtccListData};
+use yt::{constants::HELP_STR, filter_line, YtccListData};
use crate::args::{Args, Command, OrderCommand};
@@ -49,26 +49,13 @@ fn main() -> Result<()> {
let mut edit_file = NamedTempFile::new().context("Failed to get tempfile")?;
- let file: String = json_map
- .iter()
- .map(|line| {
- format!(
- "pick {} \"{}\" <{}> [{}]\n",
- line.id,
- line.title,
- line.playlists
- .iter()
- .map(|p| &p.name[..])
- .collect::<Vec<&str>>()
- .join(", "),
- line.duration.trim()
- )
- })
- .collect();
+ json_map.iter().for_each(|line| {
+ let line = line.to_string();
+ edit_file
+ .write_all(line.as_bytes())
+ .expect("This write should not fail");
+ });
- for line in file.lines() {
- writeln!(&edit_file, "{}", line)?;
- }
write!(&edit_file, "{}", HELP_STR)?;
edit_file.flush().context("Failed to flush edit file")?;
@@ -87,23 +74,18 @@ fn main() -> Result<()> {
for line in reader.lines() {
let line = line.context("Failed to read line")?;
- if line.starts_with("#") {
- continue;
- } else if line.trim().len() == 0 {
- // empty line
- continue;
- }
-
- let line = Line::from(line.as_str());
- match line.cmd {
- LineCommand::Pick => (),
- LineCommand::Drop => {
- ytcc_drop(line.id).with_context(|| format!("Failed to drop: {}", line.id))?
- }
- LineCommand::Watch => watching.push(line.id),
+ if let Some(downloadable) =
+ filter_line(&line).with_context(|| format!("Failed to process line: '{}'", line))?
+ {
+ watching.push(downloadable);
}
}
- dbg!(&watching);
+ let watching: String = watching
+ .iter()
+ .map(|d| d.to_string())
+ .collect::<Vec<String>>()
+ .join("\n");
+ println!("{}", &watching);
Ok(())
}
diff --git a/sys/nixpkgs/pkgs/yt/src/constants.rs b/sys/nixpkgs/pkgs/yt/src/constants.rs
index 5250820c..6385df54 100644
--- a/sys/nixpkgs/pkgs/yt/src/constants.rs
+++ b/sys/nixpkgs/pkgs/yt/src/constants.rs
@@ -1,6 +1,6 @@
use std::{env, fs, path::PathBuf};
-pub const HELP_STR: &'static str = include_str!("./help.str");
+pub const HELP_STR: &str = include_str!("./help.str");
pub const YT_DLP_FLAGS: [&str; 13] = [
// Ignore errors arising of unavailable sponsor block API
@@ -24,26 +24,23 @@ pub const CONCURRENT: u32 = 5;
pub const DOWNLOAD_DIR: &str = "/tmp/ytcc";
-const STATUS_PATH: &str = "ytcc/running";
-pub fn status_path() -> anyhow::Result<PathBuf> {
+fn get_runtime_path(component: &'static str) -> anyhow::Result<PathBuf> {
let out: PathBuf = format!(
"{}/{}",
env::var("XDG_RUNTIME_DIR").expect("This should always exist"),
- STATUS_PATH
+ component
)
.into();
- fs::create_dir_all(&out.parent().expect("Parent should exist"))?;
+ fs::create_dir_all(out.parent().expect("Parent should exist"))?;
Ok(out)
}
+const STATUS_PATH: &str = "ytcc/running";
+pub fn status_path() -> anyhow::Result<PathBuf> {
+ get_runtime_path(STATUS_PATH)
+}
+
const LAST_SELECT: &str = "ytcc/selected.yts";
pub fn last_select() -> anyhow::Result<PathBuf> {
- let out: PathBuf = format!(
- "{}/{}",
- env::var("XDG_RUNTIME_DIR").expect("This should always exist"),
- LAST_SELECT
- )
- .into();
- fs::create_dir_all(&out.parent().expect("Parent should exist"))?;
- Ok(out)
+ get_runtime_path(LAST_SELECT)
}
diff --git a/sys/nixpkgs/pkgs/yt/src/downloader.rs b/sys/nixpkgs/pkgs/yt/src/downloader.rs
index 34627f70..b30c49a2 100644
--- a/sys/nixpkgs/pkgs/yt/src/downloader.rs
+++ b/sys/nixpkgs/pkgs/yt/src/downloader.rs
@@ -21,6 +21,17 @@ pub struct Downloadable {
pub id: Option<u32>,
}
+impl std::fmt::Display for Downloadable {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
+ write!(
+ f,
+ "{}|{}",
+ self.url.as_str().replace('|', ";"),
+ self.id.unwrap_or(0),
+ )
+ }
+}
+
pub struct Downloader {
sent: usize,
download_thread: JoinHandle<Result<()>>,
@@ -34,8 +45,8 @@ impl Downloader {
let (itx, irx): (Sender<Downloadable>, Receiver<Downloadable>) = mpsc::channel();
let (otx, orx) = mpsc::channel();
let jh = thread::spawn(move || -> Result<()> {
- while let Some(pt) = irx.recv().ok() {
- debug!("Got '{}|{}' to be downloaded", pt.url, pt.id.unwrap_or(0));
+ while let Ok(pt) = irx.recv() {
+ debug!("Got '{}' to be downloaded", pt);
let path = download_url(&pt.url)
.with_context(|| format!("Failed to download url: '{}'", &pt.url))?;
otx.send((path, pt.id)).expect("Should not be dropped");
diff --git a/sys/nixpkgs/pkgs/yt/src/help.str b/sys/nixpkgs/pkgs/yt/src/help.str
index e5b21fce..130fe42a 100644
--- a/sys/nixpkgs/pkgs/yt/src/help.str
+++ b/sys/nixpkgs/pkgs/yt/src/help.str
@@ -1,7 +1,8 @@
# Commands:
-# w, watch <id> = watch id
-# d, drop <id> = mark id as watched
-# p, pick <id> = leave id as is; This is a noop
+# w, watch = watch id
+# d, drop = mark id as watched
+# u, url = open the associated URL in the `timesinks.youtube` Firefox profile
+# p, pick = leave id as is; This is a noop
#
# These lines can be re-ordered; they are executed from top to bottom.
# vim: filetype=yts conceallevel=2 concealcursor=nc colorcolumn=
diff --git a/sys/nixpkgs/pkgs/yt/src/lib.rs b/sys/nixpkgs/pkgs/yt/src/lib.rs
index 2571b6b6..7fa090af 100644
--- a/sys/nixpkgs/pkgs/yt/src/lib.rs
+++ b/sys/nixpkgs/pkgs/yt/src/lib.rs
@@ -1,4 +1,5 @@
use anyhow::{bail, Context};
+use downloader::Downloadable;
use serde::Deserialize;
use url::Url;
@@ -50,6 +51,7 @@ pub enum LineCommand {
Pick,
Drop,
Watch,
+ Url,
}
impl std::str::FromStr for LineCommand {
@@ -59,6 +61,7 @@ impl std::str::FromStr for LineCommand {
"pick" | "p" => Ok(Self::Pick),
"drop" | "d" => Ok(Self::Drop),
"watch" | "w" => Ok(Self::Watch),
+ "url" | "u" => Ok(Self::Url),
other => bail!("'{}' is not a recognized command!", other),
}
}
@@ -115,7 +118,7 @@ impl std::fmt::Display for Duration {
let base_hour = self.time - (self.time % HOUR);
let base_min = (self.time % HOUR) - ((self.time % HOUR) % MINUTE);
- let base_sec = ((self.time % HOUR) % MINUTE) - (((self.time % HOUR) % MINUTE) % SECOND);
+ let base_sec = (self.time % HOUR) % MINUTE;
let h = base_hour / HOUR;
let m = base_min / MINUTE;
@@ -154,3 +157,29 @@ pub fn ytcc_drop(id: u32) -> anyhow::Result<()> {
}
Ok(())
}
+
+pub fn filter_line(line: &str) -> anyhow::Result<Option<Downloadable>> {
+ // Filter out comments and empty lines
+ if line.starts_with('#') || line.trim().is_empty() {
+ return Ok(None);
+ }
+
+ let line = Line::from(line);
+ match line.cmd {
+ LineCommand::Pick => Ok(None),
+ LineCommand::Drop => ytcc_drop(line.id)
+ .with_context(|| format!("Failed to drop: {}", line.id))
+ .map(|_| None),
+ LineCommand::Watch => Ok(Some(Downloadable {
+ id: Some(line.id),
+ url: line.url,
+ })),
+ LineCommand::Url => {
+ let mut firefox = std::process::Command::new("firefox");
+ firefox.args(["-P", "timesinks.youtube"]);
+ firefox.arg(line.url.as_str());
+ let _handle = firefox.spawn().context("Failed to run firefox")?;
+ Ok(None)
+ }
+ }
+}