From bb8b501d46872909afd72643a3c5acac309ab7f1 Mon Sep 17 00:00:00 2001 From: lubien Date: Wed, 21 Sep 2016 22:27:17 -0300 Subject: [PATCH 1/4] Add --start parameter --- lib/sipper/cli.ex | 1 + lib/sipper/config.ex | 2 +- lib/sipper/parameter_parser.ex | 1 + lib/sipper/runner.ex | 9 +++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/sipper/cli.ex b/lib/sipper/cli.ex index a195f6e..63cdd7b 100644 --- a/lib/sipper/cli.ex +++ b/lib/sipper/cli.ex @@ -19,6 +19,7 @@ defmodule Sipper.CLI do config = %Sipper.Config{ auth: {user, pw}, dir: Dict.get(options, :dir, "./downloads") |> Path.expand, + start: Dict.get(options, :start, 1), max: Dict.get(options, :max, :unlimited), ignore: String.split(ignore, ",", trim: true), oldest_first: Dict.get(options, :oldest_first, false), diff --git a/lib/sipper/config.ex b/lib/sipper/config.ex index 7672c16..60611e6 100644 --- a/lib/sipper/config.ex +++ b/lib/sipper/config.ex @@ -1,3 +1,3 @@ defmodule Sipper.Config do - defstruct auth: nil, dir: nil, max: nil, ignore: [], oldest_first: false + defstruct auth: nil, dir: nil, start: nil, max: nil, ignore: [], oldest_first: false end diff --git a/lib/sipper/parameter_parser.ex b/lib/sipper/parameter_parser.ex index b714ae9..9f2fbcb 100644 --- a/lib/sipper/parameter_parser.ex +++ b/lib/sipper/parameter_parser.ex @@ -4,6 +4,7 @@ defmodule Sipper.ParameterParser do strict: [ user: :string, pw: :string, + start: :string, max: :integer, dir: :string, ignore: :string, diff --git a/lib/sipper/runner.ex b/lib/sipper/runner.ex index 567edc8..8a2af74 100644 --- a/lib/sipper/runner.ex +++ b/lib/sipper/runner.ex @@ -4,6 +4,7 @@ defmodule Sipper.Runner do |> parse_feed |> change_download_order(config.oldest_first) |> ignore_episodes(config.ignore) + |> skip_until(config.start) |> limit_to(config.max) |> download(config) end @@ -25,6 +26,14 @@ defmodule Sipper.Runner do defp change_download_order(episodes, true), do: Enum.reverse(episodes) defp change_download_order(episodes, false), do: episodes + defp skip_until(episodes, first) do + first = first |> String.pad_leading(3, "0") + + Enum.drop_while(episodes, fn {title, _} -> + not String.contains?(title, first) + end) + end + defp limit_to(episodes, :unlimited), do: episodes defp limit_to(episodes, max), do: episodes |> Enum.take(max) From c44b22a3880ce2c7392f3536f268720def98bb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Wed, 21 Sep 2016 22:32:11 -0300 Subject: [PATCH 2/4] Add --start parameter documentation to README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a1879ca..1137b12 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ By default, episodes are downloaded newest-first. If you want to instead downloa If you want to ignore some episodes (e.g. deprecated content), do: ./sipper --user me@example.com --pw mypassword --ignore "007,008,009" + +You may want to start downloading from N, do: + + ./sipper --user me@example.com --pw mypassword --oldest-first --start N By default, files end up in `./downloads`. You can specify another destination (automatically created if it doesn't exist): From 7f254b3c8d7ca736328b69f61d0618ac1671e0db Mon Sep 17 00:00:00 2001 From: lubien Date: Wed, 21 Sep 2016 22:57:03 -0300 Subject: [PATCH 3/4] Add case where you may not want to skip episodes --- lib/sipper/cli.ex | 2 +- lib/sipper/runner.ex | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sipper/cli.ex b/lib/sipper/cli.ex index 63cdd7b..1c3401a 100644 --- a/lib/sipper/cli.ex +++ b/lib/sipper/cli.ex @@ -19,7 +19,7 @@ defmodule Sipper.CLI do config = %Sipper.Config{ auth: {user, pw}, dir: Dict.get(options, :dir, "./downloads") |> Path.expand, - start: Dict.get(options, :start, 1), + start: Dict.get(options, :start, :none), max: Dict.get(options, :max, :unlimited), ignore: String.split(ignore, ",", trim: true), oldest_first: Dict.get(options, :oldest_first, false), diff --git a/lib/sipper/runner.ex b/lib/sipper/runner.ex index 8a2af74..f658d22 100644 --- a/lib/sipper/runner.ex +++ b/lib/sipper/runner.ex @@ -26,6 +26,7 @@ defmodule Sipper.Runner do defp change_download_order(episodes, true), do: Enum.reverse(episodes) defp change_download_order(episodes, false), do: episodes + defp skip_until(episodes, :none), do: episodes defp skip_until(episodes, first) do first = first |> String.pad_leading(3, "0") From 1c7b5a7a0a46e956810c6714a3dd5b73a1ca314a Mon Sep 17 00:00:00 2001 From: lubien Date: Wed, 5 Oct 2016 11:33:45 -0300 Subject: [PATCH 4/4] Minor changes * Rename --start parameter to --start-from-episode * Use Regex to match the first episode and reject the ones before it --- lib/sipper/cli.ex | 12 ++++++------ lib/sipper/config.ex | 2 +- lib/sipper/parameter_parser.ex | 2 +- lib/sipper/runner.ex | 9 +++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/sipper/cli.ex b/lib/sipper/cli.ex index 1c3401a..c865d53 100644 --- a/lib/sipper/cli.ex +++ b/lib/sipper/cli.ex @@ -17,12 +17,12 @@ defmodule Sipper.CLI do ignore = Dict.get(options, :ignore, "") config = %Sipper.Config{ - auth: {user, pw}, - dir: Dict.get(options, :dir, "./downloads") |> Path.expand, - start: Dict.get(options, :start, :none), - max: Dict.get(options, :max, :unlimited), - ignore: String.split(ignore, ",", trim: true), - oldest_first: Dict.get(options, :oldest_first, false), + auth: {user, pw}, + dir: Dict.get(options, :dir, "./downloads") |> Path.expand, + start_episode: Dict.get(options, :start_from_episode, :none), + max: Dict.get(options, :max, :unlimited), + ignore: String.split(ignore, ",", trim: true), + oldest_first: Dict.get(options, :oldest_first, false), } Sipper.Runner.run(config) diff --git a/lib/sipper/config.ex b/lib/sipper/config.ex index 60611e6..3dc3355 100644 --- a/lib/sipper/config.ex +++ b/lib/sipper/config.ex @@ -1,3 +1,3 @@ defmodule Sipper.Config do - defstruct auth: nil, dir: nil, start: nil, max: nil, ignore: [], oldest_first: false + defstruct auth: nil, dir: nil, start_episode: nil, max: nil, ignore: [], oldest_first: false end diff --git a/lib/sipper/parameter_parser.ex b/lib/sipper/parameter_parser.ex index 9f2fbcb..f01a84c 100644 --- a/lib/sipper/parameter_parser.ex +++ b/lib/sipper/parameter_parser.ex @@ -4,7 +4,7 @@ defmodule Sipper.ParameterParser do strict: [ user: :string, pw: :string, - start: :string, + start_from_episode: :string, max: :integer, dir: :string, ignore: :string, diff --git a/lib/sipper/runner.ex b/lib/sipper/runner.ex index f658d22..d39af93 100644 --- a/lib/sipper/runner.ex +++ b/lib/sipper/runner.ex @@ -4,7 +4,7 @@ defmodule Sipper.Runner do |> parse_feed |> change_download_order(config.oldest_first) |> ignore_episodes(config.ignore) - |> skip_until(config.start) + |> skip_until(config.start_episode) |> limit_to(config.max) |> download(config) end @@ -27,11 +27,12 @@ defmodule Sipper.Runner do defp change_download_order(episodes, false), do: episodes defp skip_until(episodes, :none), do: episodes - defp skip_until(episodes, first) do - first = first |> String.pad_leading(3, "0") + defp skip_until(episodes, start_episode) do + start_episode = start_episode |> String.pad_leading(3, "0") + start_episode_regex = Regex.compile!("^" <> start_episode) Enum.drop_while(episodes, fn {title, _} -> - not String.contains?(title, first) + not Regex.match?(start_episode_regex, title) end) end