mirror of
https://github.com/transmission/transmission
synced 2025-01-03 05:25:52 +00:00
transmission-edit: Allow changes to torrent source flag (#3760)
This commit is contained in:
parent
1bba2a8c61
commit
339b9580cf
2 changed files with 39 additions and 3 deletions
|
@ -28,13 +28,15 @@ struct app_options
|
||||||
char const* add = nullptr;
|
char const* add = nullptr;
|
||||||
char const* deleteme = nullptr;
|
char const* deleteme = nullptr;
|
||||||
std::array<char const*, 2> replace;
|
std::array<char const*, 2> replace;
|
||||||
|
char const* source = nullptr;
|
||||||
bool show_version = false;
|
bool show_version = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static auto constexpr Options = std::array<tr_option, 5>{
|
static auto constexpr Options = std::array<tr_option, 6>{
|
||||||
{ { 'a', "add", "Add a tracker's announce URL", "a", true, "<url>" },
|
{ { 'a', "add", "Add a tracker's announce URL", "a", true, "<url>" },
|
||||||
{ 'd', "delete", "Delete a tracker's announce URL", "d", true, "<url>" },
|
{ 'd', "delete", "Delete a tracker's announce URL", "d", true, "<url>" },
|
||||||
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", true, "<old> <new>" },
|
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", true, "<old> <new>" },
|
||||||
|
{ 's', "source", "Set the source", "s", true, "<source>" },
|
||||||
{ 'V', "version", "Show version number and exit", "V", false, nullptr },
|
{ 'V', "version", "Show version number and exit", "V", false, nullptr },
|
||||||
{ 0, nullptr, nullptr, nullptr, false, nullptr } }
|
{ 0, nullptr, nullptr, nullptr, false, nullptr } }
|
||||||
};
|
};
|
||||||
|
@ -68,6 +70,10 @@ static int parseCommandLine(app_options& opts, int argc, char const* const* argv
|
||||||
opts.replace[1] = optarg;
|
opts.replace[1] = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
opts.source = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
opts.show_version = true;
|
opts.show_version = true;
|
||||||
break;
|
break;
|
||||||
|
@ -296,6 +302,28 @@ static bool addURL(tr_variant* metainfo, char const* url)
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool setSource(tr_variant* metainfo, char const* source_value)
|
||||||
|
{
|
||||||
|
auto current_source = std::string_view{};
|
||||||
|
bool const had_source = tr_variantDictFindStrView(metainfo, TR_KEY_source, ¤t_source);
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (!had_source)
|
||||||
|
{
|
||||||
|
printf("\tAdded \"%s\" as source\n", source_value);
|
||||||
|
tr_variantDictAddStr(metainfo, TR_KEY_source, source_value);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
else if (current_source.compare(source_value) != 0)
|
||||||
|
{
|
||||||
|
printf("\tUpdated source: \"%s\" -> \"%s\"\n", current_source.data(), source_value);
|
||||||
|
tr_variantDictAddStr(metainfo, TR_KEY_source, source_value);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
int tr_main(int argc, char* argv[])
|
int tr_main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int changedCount = 0;
|
int changedCount = 0;
|
||||||
|
@ -322,9 +350,9 @@ int tr_main(int argc, char* argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.add == nullptr && options.deleteme == nullptr && options.replace[0] == nullptr)
|
if (options.add == nullptr && options.deleteme == nullptr && options.replace[0] == nullptr && options.source == nullptr)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Must specify -a, -d or -r\n");
|
fprintf(stderr, "ERROR: Must specify -a, -d, -r or -s\n");
|
||||||
tr_getopt_usage(MyName, Usage, std::data(Options));
|
tr_getopt_usage(MyName, Usage, std::data(Options));
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -360,6 +388,11 @@ int tr_main(int argc, char* argv[])
|
||||||
changed |= replaceURL(&top, options.replace[0], options.replace[1]);
|
changed |= replaceURL(&top, options.replace[0], options.replace[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.source != nullptr)
|
||||||
|
{
|
||||||
|
changed = setSource(&top, options.source);
|
||||||
|
}
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
++changedCount;
|
++changedCount;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
.Op Fl a Ar url
|
.Op Fl a Ar url
|
||||||
.Op Fl d Ar url
|
.Op Fl d Ar url
|
||||||
.Op Fl r Ar search Ar replace
|
.Op Fl r Ar search Ar replace
|
||||||
|
.Op Fl s Ar source
|
||||||
.Ar torrentfile(s)
|
.Ar torrentfile(s)
|
||||||
.Ek
|
.Ek
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
|
@ -26,6 +27,8 @@ Add an announce URL to the torrent's announce-list if it's not already in the li
|
||||||
Remove an announce URL from the torrent's announce-list
|
Remove an announce URL from the torrent's announce-list
|
||||||
.It Fl r Fl -replace Ar search Ar replace
|
.It Fl r Fl -replace Ar search Ar replace
|
||||||
Substring search-and-replace inside a torrent's announce URLs. This can be used to change an announce URL when the tracker moves or your passcode changes.
|
Substring search-and-replace inside a torrent's announce URLs. This can be used to change an announce URL when the tracker moves or your passcode changes.
|
||||||
|
.It Fl s Fl -source Ar source
|
||||||
|
Set the source tag within a torrent
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Update a tracker passcode in all your torrents:
|
Update a tracker passcode in all your torrents:
|
||||||
|
|
Loading…
Reference in a new issue