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): diff --git a/lib/sipper/cli.ex b/lib/sipper/cli.ex index a195f6e..c865d53 100644 --- a/lib/sipper/cli.ex +++ b/lib/sipper/cli.ex @@ -17,11 +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, - 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 7672c16..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, 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 b714ae9..f01a84c 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_from_episode: :string, max: :integer, dir: :string, ignore: :string, diff --git a/lib/sipper/runner.ex b/lib/sipper/runner.ex index 567edc8..d39af93 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_episode) |> limit_to(config.max) |> download(config) end @@ -25,6 +26,16 @@ 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, 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 Regex.match?(start_episode_regex, title) + end) + end + defp limit_to(episodes, :unlimited), do: episodes defp limit_to(episodes, max), do: episodes |> Enum.take(max)