Skip to content

Commit

Permalink
Version 3 (#25)
Browse files Browse the repository at this point in the history
* Start of version 3, complete rewrite

* Replace tests

* Update dependencies

* Update tox config

* Update CLI

* Add type hints

* Update docs 1st pass

* Change version

* Remove old notebooks

* Ignore VS Code settings

* Change entrypoint

* Update documentation

* Add return type

* Add README to PyPi
  • Loading branch information
marhoy committed Apr 27, 2022
1 parent dbe71b4 commit 382a97a
Show file tree
Hide file tree
Showing 36 changed files with 2,015 additions and 6,570 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
# Make flake8 compatible with black
max-line-length = 88
extend-ignore = E203, W503
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ target/
.idea/nrk-download.iml
.idea/

# VS Code settings
.vscode/settings.json

# pyenv
.python-version

Expand Down
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
hooks:
- id: mypy
additional_dependencies:
- pydantic
- types-requests
- types-setuptools

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

# - repo: https://github.com/PyCQA/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
# files: ^src/
# additional_dependencies:
# - toml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: "v1.1.13"
hooks:
- id: remove-crlf

- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
hooks:
- id: nbstripout
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
For information on how to contribute, [see the documentation](https://nrkdownload.readthedocs.io/en/latest/90_contributing.html).
For information on how to contribute, [see the
documentation](https://nrkdownload.readthedocs.io/en/latest/90_contributing.html).
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# nrkdownload
![Supports python 2.7, 3.6, 3.7, 3.8](https://img.shields.io/badge/python-2.7%2C%203.6%2C%203.7%2C%203.8-brightgreen.svg "Supported Python versions")

This is a commandline tool to download programs and series from NRK (Norwegian public broadcaster). It supports both TV, Radio and Podcast content. The tool is written in Python, and is compatible with Python 2.7 and 3.x. It has been tested under Linux, Mac OS X and Windows.
!["Latest version"](https://img.shields.io/github/v/release/marhoy/nrk-download?include_prereleases)

!["Supported Python versions"](https://img.shields.io/pypi/pyversions/nrkdownload)

This is a commandline tool to download programs and series from NRK (Norwegian public
broadcaster). It supports both TV, Radio and Podcast content. The tool is written in
Python, and is compatible with Python 3.7 or newer. It has been tested under Linux, Mac
OS X and Windows.

# Documentation
The documentation for nrkdownload is availabe here:
https://nrkdownload.readthedocs.org

The documentation for nrkdownload is availabe here: https://nrkdownload.readthedocs.org

# Setting up a development environment
Install [poetry](https://python-poetry.org/), and a recent Python version (>=3.6).
If you want to run tests with multiple Python versions, install [pyenv](https://github.com/pyenv/pyenv).
Set up the development environment:

Install [poetry](https://python-poetry.org/), and a recent Python version (>=3.7). If
you want to run tests with multiple Python versions, install
[pyenv](https://github.com/pyenv/pyenv). Set up the development environment:

```bash
poetry install
```


# Making a new release

- Make sure all tests are ok by running `tox`
- Make a pull requst on GitHub
- Use the "new release" functionallity of GitHub. Make a new tag.
- Update `pyproject.toml` to match the new version number.
- Update `pyproject.toml` and `__init__.py` to match the new version number.
- `poetry build`
- `poetry publish`
66 changes: 26 additions & 40 deletions docs/10_features.rst
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
Features
========

This is a commandline tool to download content from NRK
(Norwegian public broadcaster). It supports downloading TV, radio and podcasts.
The tool is written in Python, and is compatible with Python 2.7
and 3.x. It has been tested under Linux, Mac OS X and Windows.
This is a commandline tool for downloading content from NRK (Norwegian public
broadcaster). It supports downloading TV series and programs. The tool is written in
Python, and is compatible with Python 3.8 or newer. It has been tested under Linux, Mac
OS X and Windows.

As of autumn 2018, NRK has started to require a secret key in the header of
the API requests. This download-tool works even after those restrictions.
Users outside of Norway should note that some of the content is
geo-restricted.
Please only use this tool for personal purposes. You are responsible for not breaking
any Intellectual Property Rights. Users outside of Norway should note that some of the
content is geo-restricted.


How is this tools different than others?
----------------------------------------
Downloading media and metadata
------------------------------

When you download a program with this tool, it doesn't just download one
file. If the program is part of a series, directories for the series and
season is created. And the file is automatically named according to its
episode and season number. Subtitles and additional images are also
automatically downloaded. The subtitles are automatically embedded in the
.m4v-file, so you could decide to delete the .srt-file. (I have found that in
some tools (like VLC), the support for included subtitles is not perfect.
That's why the separate .srt-file is also there.)
The idea behind the tool is that the downloaded programs should integrate seamlessly
into you favorite media server, e.g. Plex. If you for example download all the episodes
of the popular series Førstegangstjenesten, you would get a directory-structure like
this::

The idea behind all of this is that the downloaded programs should integrate
seamlessly into you favorite media server, e.g. Plex. If you for example
download all the episodes of the popular series SKAM, you would get a
directory-structure like this::

SKAM
├── poster.jpg
Førstegangstjenesten
├── banner.jpg
├── Season 01
│ ├── SKAM - S01E01 - 1of11.jpg
│ ├── SKAM - S01E01 - 1of11.m4v
│ ├── SKAM - S01E01 - 1of11.no.srt
├── Season 02
│ ├── SKAM - S02E01 - 1of12.jpg
│ ├── SKAM - S02E01 - 1of12.m4v
│ ├── SKAM - S02E01 - 1of12.no.srt
│  ├── Førstegangstjenesten - s01e01 - 1. Pilot - del 1.jpg
│  ├── Førstegangstjenesten - s01e01 - 1. Pilot - del 1.m4v
│  ├── Førstegangstjenesten - s01e01 - 1. Pilot - del 1.no.srt
└── Season 03
├── SKAM - S03E01 - 1of10.jpg
├── SKAM - S03E01 - 1of10.m4v
├── SKAM - S03E01 - 1of10.no.srt
└── Season 02
├── Førstegangstjenesten - s02e01 - 1. episode.jpg
├── Førstegangstjenesten - s02e01 - 1. episode.m4v
├── Førstegangstjenesten - s02e01 - 1. episode.no.srt
├── SKAM - S03E10 - 10of10.jpg
├── SKAM - S03E10 - 10of10.m4v
└── SKAM - S03E10 - 10of10.no.srt
├── Førstegangstjenesten - s02e08 - 8. episode.jpg
├── Førstegangstjenesten - s02e08 - 8. episode.m4v
├── Førstegangstjenesten - s02e08 - 8. episode.no.srt
└── Season02.jpg

116 changes: 12 additions & 104 deletions docs/20_installing_nrkdownload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,15 @@ Installing nrkdownload
Installing or upgrading to the latest release of nrkdownload
------------------------------------------------------------

To install or upgrade to the latest release from
`PyPI <https://pypi.org/project/nrkdownload/>`_ , use the following
command::

$ pip install -U --user nrkdownload

For considerations on Python 2 vs. 3 and the ``--user`` option,
see the section on :ref:`considerations` below.


Installing in development mode:
-------------------------------

If you want to change (and possibly contribute to) the code, first
clone the GitHub repository. This will create a directory containing a local
copy. Then install in develop mode from this directory::

$ git clone https://github.com/marhoy/nrk-download.git
$ pip install --user -e nrk-download

You will then be able to use the tool as usual, but the installation
will be a pointer to your local repository. Whatever changes you make
in your local repository will have immediate effect on the "installation".

You are welcome to help developing ``nrkdownload``, please see the section
on :ref:`contributing`.


Uninstalling nrkdownload
------------------------

To uninstall nrkdownload, just type::

$ pip uninstall nrkdownload

NOTE: This will not uninstall the required packages that might have
been installed together with nrkdownload. Type ``pip list --user`` to
list all user-installed packages, and uninstall them if you know that
you don't need them anymore.


.. _considerations:

OS considerations
-----------------

This tool is compatible with both Python 2 and 3. But unless you have
other reasons to use Python 2, the latest Python 3.x is recommended.

If your system-wide Python installation is under control of a package
manager like rpm or deb, you should avoid pip-installing python
packages as root. This can be solved in several ways:

#. Install Python packages under your own home-directory by passing the
``--user`` option to the pip installer.
#. Install your own user-specific Python distribution, where you can
later install packages. Anaconda (or Miniconda) is a good choice.
It also has good support for environment (see next).
#. Create a virtual environment using standard Python or conda
(used by Anaconda/Miniconda) and install packages in that environment.



Special considerations for MacOS (OS X)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

MacOS comes by default with an installation of Python 2.7. You can decide
to go with this (i.e. not installing Anaconda as mentioned above).
In order to install packages you need the package installer pip, and
under macOS pip is not installed by default. You can install it by
typing ``sudo easy_install pip``.
In order to utilize the ``--user`` scheme described above, you must
also add ``~/Library/Python/2.7/bin`` to your
``$PATH`` (edit your ``~/.bash_profile``).
This enables installed Python scripts (like nrkdownload) to be
available in the Terminal.

Also, if you get an ``UnicodeEncodeError``, add the following line
to your ``~/.bash_profile``:
``export LC_CTYPE=en_US.UTF-8``



Special considerations for Linux
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Your system might have both Python 2 and 3 installed as a part of
the Linux-distribution. If Python 2 is the default, ``pip`` will be
pointing to the Python 2 installation, whereas ``pip3`` will point
to the Python 3 installation. If that is the case for you, and you
explicitly want to run nrkdownload under Python 3, you must
replace ``pip`` with ``pip3`` in the examples above.



Special considerations for Windows
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Windows does not come with an installation of Python.
You can choose to install version 2.7.x or the latest 3.x from
python.org. If you want to learn and develop Python I would suggest
Anaconda, which installs in your home-directory and comes with
a nice selection of packages.

The package is avaible via `PyPI <https://pypi.org/project/nrkdownload/>`_. The
recommended way to install ``nrkdownload`` is by using `pipx
<https://pypa.github.io/pipx/installation/>`_. ``pipx`` is a tool that installs and runs
Python applications in isolated environments. If you haven't already done so, start by
installing pipx, and then install, upgrade or uninstall ``nrkdownload`` like this::
$ pipx install nrkdownload
$ pipx upgrade nrkdownload
$ pipx uninstall nrkdownload

Note that in order to download video and subtitles, an installation of ``ffmpeg`` is
needed. See :doc:`/30_installing_ffmpeg`.
71 changes: 22 additions & 49 deletions docs/40_usage.rst
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
Usage
==================

Before NRK restricted the API, it was possible to search for content. With
the current restrictions, you will need to specify an URL for the content you
want to download: Start by browsing https://tv.nrk.no (possibly
https://tv.nrksuper.no/) or https://radio.nrk.no
until you find what you want. Copy the URLs and give it as arguments for this
tool. You can list several URLs on the command line (separated by space),
or line by line in a file. Content that are already downloaded will be skipped.
Start by browsing https://tv.nrk.no until you find what you want. Copy the URLs and give
it as an argument for this tool. You can list several URLs on the command line
(separated by space). Content that are already downloaded will be skipped.


Options
-------

usage: nrkdownload [-h] [--version] [-d DIRECTORY] [-v] [-c] [-a | -l]
[-f FILE]
[URL [URL ...]]
Usage: nrkdownload [OPTIONS] URLS...

Download series or programs from NRK, complete with images and subtitles.
Arguments:
URLS... One or more valid URLs from https://tv.nrk.no/ [required]

positional arguments:
URL Specify download source(s). Browse https://tv.nrk.no/
or https://radio.nrk.no/ and copy the URL. The URL can
point to a whole series, or just one episode.
Options:
-d, --download-dir PATH Download directory. Can also be specified by
setting the environment variable NRKDOWNLOAD_DIR
[default: /Users/marhoy/Downloads/nrkdownload]
--version Print version string
-v Increase logger verbosity. Can be repeated up to
four times. [default: 0; x<=4]
--help Show this message and exit.

optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-d DIRECTORY The directory where the downloaded files will be
placed
-v, --verbose Increase verbosity. Can be repeated up to two times.
-c, --cache Enable persistent caching of the API requests.
-a, --all If URL matches several episodes: Download all episodes
without asking.
-l, --last If URL matches several episodes: Download the latest
without asking.
-f FILE, --file FILE Specify a file containing URLs, one URL per line.
Specifying urls from a file will automatically enable
--all and download all episodes from series.

The files are by default downloaded to ~/Downloads/nrkdownload. This can be
changed by using the option -d as described above, or you can define the
environment variable NRKDOWNLOAD_DIR
The files are by default downloaded to ~/Downloads/nrkdownload. This can be changed by
using the option -d as described above, or you can define the environment variable
NRKDOWNLOAD_DIR


URL Parsing and actions
-----------------------

Configurable download directory
-------------------------------

If you don't specify anything, the files and directories will be created
inside ``~/Downloads/nrkdownload``, where ``~`` means your home directory.
If you want the downloads somewhere else, there are two ways to specify a
different download directory:

* Define an environment variable named ``NRKDOWNLOAD_DIR``
* Specify the download directory on the command line with the option
``-d download_dir``

If you do both at the same time, the option from the command line will take
precedence.

If you don't know how to define an environment variable under your operating system, try to Google create environment variable and the name of you operating system. (Under Linux and macOS, you would want to edit your ~/.bash_profile)

If the URL points to the top-level of a series, all episodes in all seasons will be
downloaded. If the URL points to a specific season, only the episodes within that season
will be downloaded.

0 comments on commit 382a97a

Please sign in to comment.