paper-dl 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +83 -0
- data/LICENSE.md +21 -0
- data/README.md +111 -0
- data/exe/paper-dl +5 -0
- data/lib/paper/downloader/ambiguous.rb +19 -0
- data/lib/paper/downloader/cli.rb +38 -0
- data/lib/paper/downloader/clients.rb +25 -0
- data/lib/paper/downloader/error.rb +5 -0
- data/lib/paper/downloader/route.rb +8 -0
- data/lib/paper/downloader/router.rb +42 -0
- data/lib/paper/downloader/source.rb +13 -0
- data/lib/paper/downloader/sources.rb +42 -0
- data/lib/paper/downloader/unrecognized.rb +11 -0
- data/lib/paper/downloader/version.rb +5 -0
- data/lib/paper/downloader.rb +24 -0
- data/sig/paper/downloader.rbs +5 -0
- metadata +171 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fcda01e32d0f47340f2b69d8bfcb9c0ee3af1bbe1d0c72daa72d110ab277b967
|
|
4
|
+
data.tar.gz: abb8eab47483f8ff234028d7aa1d46eeb706489f9c683f4e261d533c296933fc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cd86509ba785b1177e0897768e2a4ef8bdcc150307596c989d1bcfafeee1c826f342fc2e832d50091d2243579a11391014904000c5f6d8aa8c25dd5d26ff79f0
|
|
7
|
+
data.tar.gz: e007aea5469f6a379eaae64d6db026c8c11ba67b87898a7662a11e978a80b83b5f4536e111ac77851776764bd703a5fe671c51f3c5b5064b921a964205e5ad5e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
## [0.1.0]
|
|
2
|
+
|
|
3
|
+
First working version. One command for papers from any supported source, built on [dl-core](https://github.com/xoengineering/dl-core).
|
|
4
|
+
|
|
5
|
+
- Routes each paper ID or URL to the one gem that recognizes it: arxiv-dl, jstor-dl, hal-dl, ntrs-dl, osf-dl, or zenodo-dl.
|
|
6
|
+
- Input more than one source accepts, like a bare number, raises `Paper::Downloader::Ambiguous` naming the candidates. A `<source>:` prefix (`jstor:4385670`) chooses.
|
|
7
|
+
- Each source's papers go in their own subfolder of the root, and each source gets its own polite HTTP client. A source is never asked to go faster than its own gem's default.
|
|
8
|
+
- CLI with `--input FILE|-`, per-target error reporting, and exit status 1 on any failure, from dl-core.
|
|
9
|
+
|
|
10
|
+
## [0.0.1]
|
|
11
|
+
|
|
12
|
+
Placeholder release to reserve the name. No functionality yet.
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Contributor Covenant 3.0 Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We pledge to make our community welcoming, safe, and equitable for all.
|
|
6
|
+
|
|
7
|
+
We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
|
|
8
|
+
|
|
9
|
+
## Encouraged Behaviors
|
|
10
|
+
|
|
11
|
+
While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
|
|
12
|
+
|
|
13
|
+
With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
|
|
14
|
+
|
|
15
|
+
1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
|
|
16
|
+
2. Engaging **kindly and honestly** with others.
|
|
17
|
+
3. Respecting **different viewpoints** and experiences.
|
|
18
|
+
4. **Taking responsibility** for our actions and contributions.
|
|
19
|
+
5. Gracefully giving and accepting **constructive feedback**.
|
|
20
|
+
6. Committing to **repairing harm** when it occurs.
|
|
21
|
+
7. Behaving in other ways that promote and sustain the **well-being of our community**.
|
|
22
|
+
|
|
23
|
+
## Restricted Behaviors
|
|
24
|
+
|
|
25
|
+
We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
|
|
26
|
+
|
|
27
|
+
1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
|
|
28
|
+
2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
|
|
29
|
+
3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
|
|
30
|
+
4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
|
|
31
|
+
5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission.
|
|
32
|
+
6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
|
|
33
|
+
7. Behaving in other ways that **threaten the well-being** of our community.
|
|
34
|
+
|
|
35
|
+
### Other Restrictions
|
|
36
|
+
|
|
37
|
+
1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
|
|
38
|
+
2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
|
|
39
|
+
3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community.
|
|
40
|
+
4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
|
|
41
|
+
|
|
42
|
+
## Reporting an Issue
|
|
43
|
+
|
|
44
|
+
Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
|
|
45
|
+
|
|
46
|
+
When an incident does occur, it is important to report it promptly. To report a possible violation, **email the maintainer at [veganstraightedge@gmail.com](mailto:veganstraightedge@gmail.com).**
|
|
47
|
+
|
|
48
|
+
Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
|
|
49
|
+
|
|
50
|
+
## Addressing and Repairing Harm
|
|
51
|
+
|
|
52
|
+
If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
|
|
53
|
+
|
|
54
|
+
1. Warning
|
|
55
|
+
1. Event: A violation involving a single incident or series of incidents.
|
|
56
|
+
2. Consequence: A private, written warning from the Community Moderators.
|
|
57
|
+
3. Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
|
|
58
|
+
2. Temporarily Limited Activities
|
|
59
|
+
1. Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
|
|
60
|
+
2. Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
|
|
61
|
+
3. Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
|
|
62
|
+
3. Temporary Suspension
|
|
63
|
+
1. Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation.
|
|
64
|
+
2. Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
|
|
65
|
+
3. Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
|
|
66
|
+
4. Permanent Ban
|
|
67
|
+
1. Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member.
|
|
68
|
+
2. Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
|
|
69
|
+
3. Repair: There is no possible repair in cases of this severity.
|
|
70
|
+
|
|
71
|
+
This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community.
|
|
72
|
+
|
|
73
|
+
## Scope
|
|
74
|
+
|
|
75
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
76
|
+
|
|
77
|
+
## Attribution
|
|
78
|
+
|
|
79
|
+
This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
|
|
80
|
+
|
|
81
|
+
Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
|
|
82
|
+
|
|
83
|
+
For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion).
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shane Becker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# paper-dl
|
|
2
|
+
|
|
3
|
+
Download papers for offline archives, from any supported source, with one command.
|
|
4
|
+
|
|
5
|
+
`paper-dl` routes each paper ID or URL to the `<site>-dl` gem that handles it:
|
|
6
|
+
|
|
7
|
+
| Source | Gem | Example input |
|
|
8
|
+
| ------ | --- | ------------- |
|
|
9
|
+
| arxiv.org | [arxiv-dl](https://github.com/xoengineering/arxiv-dl) | `2508.16190`, `https://arxiv.org/abs/2508.16190` |
|
|
10
|
+
| JSTOR Early Journal Content, via the Internet Archive | [jstor-dl](https://github.com/xoengineering/jstor-dl) | `10.2307/4385670`, `https://www.jstor.org/stable/4385670` |
|
|
11
|
+
| HAL, France's national open archive | [hal-dl](https://github.com/xoengineering/hal-dl) | `hal-01207234v1`, `https://hal.science/hal-01207234` |
|
|
12
|
+
| NASA Technical Reports Server | [ntrs-dl](https://github.com/xoengineering/ntrs-dl) | `https://ntrs.nasa.gov/citations/19700020471` |
|
|
13
|
+
| OSF Preprints (PsyArXiv, SocArXiv, and more) | [osf-dl](https://github.com/xoengineering/osf-dl) | `cjy8e_v1`, `https://osf.io/preprints/psyarxiv/cjy8e_v1/` |
|
|
14
|
+
| Zenodo publications | [zenodo-dl](https://github.com/xoengineering/zenodo-dl) | `10.5281/zenodo.884117`, `https://zenodo.org/records/884117` |
|
|
15
|
+
|
|
16
|
+
Each gem's README covers what it saves, its layout, and its source's terms. Read those before archiving from a source, especially [ntrs-dl's](https://github.com/xoengineering/ntrs-dl#nasas-terms-read-before-using).
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
gem install paper-dl
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This installs every `<site>-dl` gem above too.
|
|
25
|
+
|
|
26
|
+
## CLI usage
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
paper-dl <PAPER_ID_OR_URL> [<PAPER_ID_OR_URL>...]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Papers from different sources can be mixed in one run.
|
|
33
|
+
|
|
34
|
+
### Ambiguous input
|
|
35
|
+
|
|
36
|
+
Some input fits more than one source. A bare number could be a JSTOR stable ID or a Zenodo record ID, and an 11-digit number could also be an NTRS ID. `paper-dl` doesn't guess. It reports the candidates:
|
|
37
|
+
|
|
38
|
+
```txt
|
|
39
|
+
4385670: 4385670 could be jstor or zenodo. Prefix it to choose, like jstor:4385670
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Prefix the input with a source name to choose: `jstor:4385670`, `zenodo:884117`, `ntrs:19700020471`, `hal:hal-01207234`, `osf:cjy8e`, `arxiv:2508.16190`. URLs and DOIs are never ambiguous.
|
|
43
|
+
|
|
44
|
+
### Flags
|
|
45
|
+
|
|
46
|
+
| Flag | Description |
|
|
47
|
+
| ------------------------- | ----------------------------------------------------------------------------- |
|
|
48
|
+
| `-i FILE`, `--input FILE` | Read IDs/URLs from FILE, one per line (`-` for stdin, blanks and `#` skipped) |
|
|
49
|
+
| `-p PATH`, `--path PATH` | Root download directory |
|
|
50
|
+
| `--rate-limit SECONDS` | Seconds between HTTP requests to each source (never faster than its gem's default) |
|
|
51
|
+
| `-v`, `--verbose` | Print step lines and per-request URL/byte logs to stdout |
|
|
52
|
+
| `-q`, `--quiet` | Print nothing to stdout. Errors still go to stderr. |
|
|
53
|
+
| `--version` | Print the gem version and exit |
|
|
54
|
+
| `-h`, `--help` | Print help and exit |
|
|
55
|
+
|
|
56
|
+
`-v` and `-q` are mutually exclusive.
|
|
57
|
+
|
|
58
|
+
### Environment variables
|
|
59
|
+
|
|
60
|
+
| Variable | Effect |
|
|
61
|
+
| --------------------- | ----------------------------------------------------------- |
|
|
62
|
+
| `PAPER_DOWNLOAD_PATH` | Root download directory (default: `$HOME/Downloads/Papers`) |
|
|
63
|
+
| `PAPER_RATE_LIMIT` | Seconds between HTTP requests (default: `3`, `0` disables) |
|
|
64
|
+
|
|
65
|
+
Precedence: CLI flag, then ENV var, then default.
|
|
66
|
+
|
|
67
|
+
### Errors and exit status
|
|
68
|
+
|
|
69
|
+
A target that fails (unrecognized, ambiguous, not found, not available, HTTP error, network failure) is reported on stderr as `<target>: <message>`, and the remaining targets still download. Exit status is `0` when every target succeeds and `1` when any fails.
|
|
70
|
+
|
|
71
|
+
## Output layout
|
|
72
|
+
|
|
73
|
+
Each source's papers go in their own subfolder of the root, laid out as that source's gem lays them out:
|
|
74
|
+
|
|
75
|
+
```txt
|
|
76
|
+
$PAPER_DOWNLOAD_PATH/ # default: $HOME/Downloads/Papers
|
|
77
|
+
arxiv/YYYY/MM/DD/<category>/<id>-<slug>/
|
|
78
|
+
hal/YYYY/MM/DD/<domain>/<hal-id>-<slug>/
|
|
79
|
+
jstor/YYYY/MM/DD/<journal>/<jstor-id>-<slug>/
|
|
80
|
+
ntrs/YYYY/MM/DD/<subject>/<ntrs-id>-<slug>/
|
|
81
|
+
osf/YYYY/MM/DD/<server>/<osf-id>-<slug>/
|
|
82
|
+
zenodo/YYYY/MM/DD/<type>/<concept-id>-<slug>/
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Each source gets its own polite HTTP client, with that gem's User-Agent and its own rate limit, since each is a different server. A source is never asked to go faster than its own gem's default. OSF allows only about 100 anonymous requests an hour, so OSF requests stay 36 seconds apart even when `--rate-limit` is lower.
|
|
86
|
+
|
|
87
|
+
## Library usage
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
require 'paper/downloader'
|
|
91
|
+
|
|
92
|
+
route = Paper::Downloader::Router.new.route 'https://www.jstor.org/stable/4385670'
|
|
93
|
+
route.source.name # => "jstor"
|
|
94
|
+
route.identifier # => a Jstor::Downloader::Identifier
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
script/setup # install dependencies
|
|
101
|
+
script/test # run specs and rubocop
|
|
102
|
+
script/console # interactive prompt
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT. See [LICENSE.md](LICENSE.md).
|
|
108
|
+
|
|
109
|
+
## Code of Conduct
|
|
110
|
+
|
|
111
|
+
This project follows the [Contributor Covenant](https://www.contributor-covenant.org/version/3/0/) 3.0. See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
|
data/exe/paper-dl
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
class Ambiguous < Error
|
|
4
|
+
def initialize input:, sources:
|
|
5
|
+
names = sources.map(&:name).sort
|
|
6
|
+
|
|
7
|
+
super("#{input} could be #{list names}. Prefix it to choose, like #{names.first}:#{input}")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def list names
|
|
13
|
+
return names.join(' or ') if names.size <= 2
|
|
14
|
+
|
|
15
|
+
"#{names[0..-2].join ', '}, or #{names.last}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
# dl-core's CLI, routing each target to its source. Each source's papers go
|
|
4
|
+
# in their own subfolder of the root (<root>/arxiv/, <root>/jstor/, …).
|
|
5
|
+
class CLI < DL::Core::CLI
|
|
6
|
+
SOURCE_URL = 'https://github.com/xoengineering/paper-dl'.freeze
|
|
7
|
+
|
|
8
|
+
def program = 'paper-dl'
|
|
9
|
+
|
|
10
|
+
def target_name = 'PAPER_ID_OR_URL'
|
|
11
|
+
|
|
12
|
+
# PAPER_DOWNLOAD_PATH, PAPER_RATE_LIMIT
|
|
13
|
+
def env_prefix = 'PAPER'
|
|
14
|
+
|
|
15
|
+
def default_path = File.join(Dir.home, 'Downloads', 'Papers')
|
|
16
|
+
|
|
17
|
+
def version = VERSION
|
|
18
|
+
|
|
19
|
+
def user_agent = "paper-dl/#{VERSION} (+#{SOURCE_URL})"
|
|
20
|
+
|
|
21
|
+
def client_for(rate_limit:, log:) = Clients.new(rate_limit:, log:)
|
|
22
|
+
|
|
23
|
+
def identifier_for(target) = router.route(target)
|
|
24
|
+
|
|
25
|
+
def archive_for route, root:, client:
|
|
26
|
+
source = route.source
|
|
27
|
+
|
|
28
|
+
source.archive_class.new route.identifier, root: File.join(root, source.name), client: client.for(source)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def router
|
|
34
|
+
@router ||= Router.new
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
# One polite client per source, made when first needed. Each source is a
|
|
4
|
+
# different server, so each gets its own rate limit and its gem's User-Agent.
|
|
5
|
+
# A source is never asked to go faster than its own gem's default (OSF allows
|
|
6
|
+
# far fewer requests than the others).
|
|
7
|
+
class Clients
|
|
8
|
+
def initialize rate_limit:, log:
|
|
9
|
+
@rate_limit = rate_limit
|
|
10
|
+
@log = log
|
|
11
|
+
@by_source = {}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def for source
|
|
15
|
+
@by_source[source.name] ||= source.client_class.new rate_limit: rate_limit_for(source), log: @log
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def rate_limit_for source
|
|
21
|
+
[@rate_limit, source.client_class::DEFAULT_RATE_LIMIT].max
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
# Matches each target to the one source that recognizes it. A "<source>:" prefix
|
|
4
|
+
# (jstor:4385670) picks the source outright, for input several sources accept.
|
|
5
|
+
class Router
|
|
6
|
+
def initialize sources: SOURCES
|
|
7
|
+
@sources = sources
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def route input
|
|
11
|
+
text = input.to_s.strip
|
|
12
|
+
source = prefixed_source text
|
|
13
|
+
return Route.new(source:, identifier: source.identifier_class.new(unprefixed(text))) if source
|
|
14
|
+
|
|
15
|
+
route_unprefixed text
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def route_unprefixed text
|
|
21
|
+
matches = @sources.filter_map do |source|
|
|
22
|
+
identifier = source.recognize text
|
|
23
|
+
Route.new(source:, identifier:) if identifier
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
raise Unrecognized.new(input: text, sources: @sources) if matches.empty?
|
|
27
|
+
raise Ambiguous.new(input: text, sources: matches.map(&:source)) if matches.size > 1
|
|
28
|
+
|
|
29
|
+
matches.first
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def prefixed_source text
|
|
33
|
+
prefix = text.split(':', 2).first.downcase
|
|
34
|
+
@sources.find { it.name == prefix } if text.include? ':'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def unprefixed text
|
|
38
|
+
text.split(':', 2).last
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
# One <site>-dl gem: its name (also its subfolder and prefix) and its classes
|
|
4
|
+
Source = Data.define :name, :identifier_class, :archive_class, :client_class do
|
|
5
|
+
# the source's identifier for input, or nil when it does not recognize it
|
|
6
|
+
def recognize input
|
|
7
|
+
identifier_class.new input
|
|
8
|
+
rescue DL::Core::Error
|
|
9
|
+
nil
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Paper
|
|
2
|
+
module Downloader
|
|
3
|
+
SOURCES = [
|
|
4
|
+
Source.new(
|
|
5
|
+
name: 'arxiv',
|
|
6
|
+
identifier_class: Arxiv::Downloader::Identifier,
|
|
7
|
+
archive_class: Arxiv::Downloader::Archive,
|
|
8
|
+
client_class: Arxiv::Downloader::Client
|
|
9
|
+
),
|
|
10
|
+
Source.new(
|
|
11
|
+
name: 'jstor',
|
|
12
|
+
identifier_class: Jstor::Downloader::Identifier,
|
|
13
|
+
archive_class: Jstor::Downloader::Archive,
|
|
14
|
+
client_class: Jstor::Downloader::Client
|
|
15
|
+
),
|
|
16
|
+
Source.new(
|
|
17
|
+
name: 'hal',
|
|
18
|
+
identifier_class: HAL::Downloader::Identifier,
|
|
19
|
+
archive_class: HAL::Downloader::Archive,
|
|
20
|
+
client_class: HAL::Downloader::Client
|
|
21
|
+
),
|
|
22
|
+
Source.new(
|
|
23
|
+
name: 'ntrs',
|
|
24
|
+
identifier_class: NTRS::Downloader::Identifier,
|
|
25
|
+
archive_class: NTRS::Downloader::Archive,
|
|
26
|
+
client_class: NTRS::Downloader::Client
|
|
27
|
+
),
|
|
28
|
+
Source.new(
|
|
29
|
+
name: 'osf',
|
|
30
|
+
identifier_class: OSF::Downloader::Identifier,
|
|
31
|
+
archive_class: OSF::Downloader::Archive,
|
|
32
|
+
client_class: OSF::Downloader::Client
|
|
33
|
+
),
|
|
34
|
+
Source.new(
|
|
35
|
+
name: 'zenodo',
|
|
36
|
+
identifier_class: Zenodo::Downloader::Identifier,
|
|
37
|
+
archive_class: Zenodo::Downloader::Archive,
|
|
38
|
+
client_class: Zenodo::Downloader::Client
|
|
39
|
+
)
|
|
40
|
+
].freeze
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'dl/core'
|
|
2
|
+
require 'arxiv/downloader'
|
|
3
|
+
require 'hal/downloader'
|
|
4
|
+
require 'jstor/downloader'
|
|
5
|
+
require 'ntrs/downloader'
|
|
6
|
+
require 'osf/downloader'
|
|
7
|
+
require 'zenodo/downloader'
|
|
8
|
+
|
|
9
|
+
require_relative 'downloader/error' # before the errors below that subclass Error
|
|
10
|
+
require_relative 'downloader/source' # before sources: SOURCES is a list of Source
|
|
11
|
+
require_relative 'downloader/version'
|
|
12
|
+
|
|
13
|
+
require_relative 'downloader/ambiguous' # after error
|
|
14
|
+
require_relative 'downloader/cli'
|
|
15
|
+
require_relative 'downloader/clients'
|
|
16
|
+
require_relative 'downloader/route'
|
|
17
|
+
require_relative 'downloader/router'
|
|
18
|
+
require_relative 'downloader/sources' # after source
|
|
19
|
+
require_relative 'downloader/unrecognized' # after error
|
|
20
|
+
|
|
21
|
+
module Paper
|
|
22
|
+
module Downloader
|
|
23
|
+
end
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: paper-dl
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shane Becker
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: arxiv-dl
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.3'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.3.2
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.3'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.3.2
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: dl-core
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0.3'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - "~>"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0.3'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: hal-dl
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - "~>"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0.1'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0.1'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: jstor-dl
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0.1'
|
|
67
|
+
type: :runtime
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0.1'
|
|
74
|
+
- !ruby/object:Gem::Dependency
|
|
75
|
+
name: ntrs-dl
|
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0.1'
|
|
81
|
+
type: :runtime
|
|
82
|
+
prerelease: false
|
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - "~>"
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0.1'
|
|
88
|
+
- !ruby/object:Gem::Dependency
|
|
89
|
+
name: osf-dl
|
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - "~>"
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0.1'
|
|
95
|
+
type: :runtime
|
|
96
|
+
prerelease: false
|
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - "~>"
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0.1'
|
|
102
|
+
- !ruby/object:Gem::Dependency
|
|
103
|
+
name: zenodo-dl
|
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - "~>"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0.1'
|
|
109
|
+
type: :runtime
|
|
110
|
+
prerelease: false
|
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - "~>"
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0.1'
|
|
116
|
+
description: |
|
|
117
|
+
Umbrella for the <site>-dl gems (arxiv-dl, jstor-dl, hal-dl, and more).
|
|
118
|
+
Routes each paper ID or URL to the gem that handles it. In development.
|
|
119
|
+
email:
|
|
120
|
+
- veganstraightedge@gmail.com
|
|
121
|
+
executables:
|
|
122
|
+
- paper-dl
|
|
123
|
+
extensions: []
|
|
124
|
+
extra_rdoc_files: []
|
|
125
|
+
files:
|
|
126
|
+
- CHANGELOG.md
|
|
127
|
+
- CODE_OF_CONDUCT.md
|
|
128
|
+
- LICENSE.md
|
|
129
|
+
- README.md
|
|
130
|
+
- exe/paper-dl
|
|
131
|
+
- lib/paper/downloader.rb
|
|
132
|
+
- lib/paper/downloader/ambiguous.rb
|
|
133
|
+
- lib/paper/downloader/cli.rb
|
|
134
|
+
- lib/paper/downloader/clients.rb
|
|
135
|
+
- lib/paper/downloader/error.rb
|
|
136
|
+
- lib/paper/downloader/route.rb
|
|
137
|
+
- lib/paper/downloader/router.rb
|
|
138
|
+
- lib/paper/downloader/source.rb
|
|
139
|
+
- lib/paper/downloader/sources.rb
|
|
140
|
+
- lib/paper/downloader/unrecognized.rb
|
|
141
|
+
- lib/paper/downloader/version.rb
|
|
142
|
+
- sig/paper/downloader.rbs
|
|
143
|
+
homepage: https://github.com/xoengineering/paper-dl
|
|
144
|
+
licenses:
|
|
145
|
+
- MIT
|
|
146
|
+
metadata:
|
|
147
|
+
allowed_push_host: https://rubygems.org
|
|
148
|
+
homepage_uri: https://github.com/xoengineering/paper-dl
|
|
149
|
+
source_code_uri: https://github.com/xoengineering/paper-dl
|
|
150
|
+
bug_tracker_uri: https://github.com/xoengineering/paper-dl/issues
|
|
151
|
+
changelog_uri: https://github.com/xoengineering/paper-dl/blob/main/CHANGELOG.md
|
|
152
|
+
rubygems_mfa_required: 'true'
|
|
153
|
+
rdoc_options: []
|
|
154
|
+
require_paths:
|
|
155
|
+
- lib
|
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
|
+
requirements:
|
|
158
|
+
- - ">="
|
|
159
|
+
- !ruby/object:Gem::Version
|
|
160
|
+
version: 4.0.10
|
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
166
|
+
requirements: []
|
|
167
|
+
rubygems_version: 4.0.20
|
|
168
|
+
specification_version: 4
|
|
169
|
+
summary: Download papers from arxiv, JSTOR, HAL, and more for offline archives, with
|
|
170
|
+
one command.
|
|
171
|
+
test_files: []
|