Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
11 changes: 6 additions & 5 deletions lib/sipper/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/sipper/config.ex
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/sipper/parameter_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Sipper.ParameterParser do
strict: [
user: :string,
pw: :string,
start_from_episode: :string,
max: :integer,
dir: :string,
ignore: :string,
Expand Down
11 changes: 11 additions & 0 deletions lib/sipper/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down