c31ee338dc
* Add option for automatic subtitle character encoding normalization The rationale behind this function is that some services use ISO-8859-1 (latin1) or Windows-1252 (CP-1252) instead of UTF-8 encoding, whether intentionally or accidentally. Some services even stream subtitles with malformed/mixed encoding (each segment has a different encoding). * Remove Subtitle parameter `auto_fix_encoding` Just always attempt to fix encoding. If the subtitle is neither UTF-8 nor CP-1252, then it should realistically error out instead of producing garbage Subtitle data anyway. * Move Subtitle encoding fixing code out of if drm tree * Use chardet as a last ditch effort fixing Subs, or return original data * Move Subtitle.fix_encoding method to utilities as try_ensure_utf8 * Add Shivelight as a contributor --------- Co-authored-by: rlaphoenix <rlaphoenix@pm.me> |
||
---|---|---|
.github | ||
.vscode | ||
devine | ||
.deepsource.toml | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.pre-commit-config.yaml | ||
CHANGELOG.md | ||
CONFIG.md | ||
CONTRIBUTING.md | ||
LICENSE | ||
README.md | ||
poetry.lock | ||
pyproject.toml |
README.md
Devine
Open-Source Movie, TV, and Music Downloading Solution
Features
-
🚀 Seamless Installation via pip
-
🎥 Movie, Episode, and Song Service Frameworks
-
🔒 Widevine DRM integration via pywidevine
-
💾 Local & Remote DRM Key-vaults
-
🌍 Local & Remote Widevine CDMs
-
👥 Multi-profile Authentication per-service with Credentials and/or Cookies
-
🤖 Automatic P2P filename structure with Group Tag
-
⚙️ YAML for Configuration
-
❤️ Fully Open-Source! Pull Requests Welcome
Installation
$ pip install devine
[!NOTE] If pip gives you a warning about a path not being in your PATH environment variable then promptly add that path then close all open command prompt/terminal windows, or
devine
won't work as it will not be found.
Voilà 🎉 — You now have the devine
package installed!
A command-line interface is now available, try devine --help
.
Dependencies
The following is a list of programs that need to be installed manually. I recommend installing these with winget,
chocolatey or such where possible as it automatically adds them to your PATH
environment variable and will be
easier to update in the future.
- aria2(c) for downloading streams and large manifests.
- CCExtractor for extracting Closed Caption data like EIA-608 from video streams and converting as SRT.
- FFmpeg (and ffprobe) for repacking/remuxing streams on specific services, and evaluating stream data.
- MKVToolNix v54+ for muxing individual streams to an
.mkv
file. - shaka-packager for decrypting CENC-CTR and CENC-CBCS video and audio streams.
For portable downloads, make sure you put them in your current working directory, in the installation directory,
or put the directory path in your PATH
environment variable. If you do not do this then their binaries will not be
able to be found.
Usage
First, take a look at devine --help
for a full help document, listing all commands available and giving you more
information on what can be done with Devine.
Here's a checklist on what I recommend getting started with, in no particular order,
- Add Services, these will be used in
devine dl
. - Add Profiles, these are your cookies and credentials.
- Add Widevine Provisions, also known as CDMs, these are used for DRM-protected content.
- Set your Group Tag, the text at the end of the final filename, e.g.,
devine cfg tag NOGRP
for...-NOGRP
. - Set Up a Local Key Vault, take a look at the Key Vaults Config.
And here's some more advanced things you could take a look at,
- Setting default Headers that the Request Session uses.
- Setting default Profiles and CDM Provisions to use for services.
- NordVPN and Hola Proxy Providers for automatic proxies.
- Hosting and/or Using Remote Key Vaults.
- Serving and/or Using Remote CDM Provisions.
Documentation on the config is available in the CONFIG.md file, it has a lot of handy settings.
If you start to get sick of putting something in your CLI call, then I recommend taking a look at it!
Services
Unlike similar project's such as youtube-dl, Devine does not currently come with any Services. You must develop your own Services and only use Devine with Services you have the legal right to do so.
[!NOTE] If you made a Service for Devine that does not use Widevine or any other DRM systems, feel free to make a Pull Request and make your service available to others. Any Service on youtube-dl (or yt-dlp) would be able to be added to the Devine repository as they both use the Unlicense license therefore direct reading and porting of their code would be legal.
Creating a Service
[!WARNING] Only create or use Service Code with Services you have full legal right to do so.
A Service consists of a folder with an __init__.py
file. The file must contain a class of the same name as the folder.
The class must inherit the Service class and implement all the abstracted methods. It must finally implement a new
method named cli
where you define CLI arguments.
- Make a new folder within
/devine/services
. The folder name you choose will be what's known as the Service Tag. This "tag" is used in the final output filename of downloaded files, for various code-checks, lookup keys in key-vault databases, and more. - Within the new folder create an
__init__.py
file and write a class inheriting the Service class. It must be named the exact same as the folder. It is case-sensitive. - Implement all the methods of the Service class you are inheriting that are marked as abstract.
- Define CLI arguments by implementing a
cli
method. This method must be static (i.e.@staticmethod
). For example to implement the bare minimum to receive a Title ID of sorts:
You must implement this@staticmethod @click.command(name="YT", short_help="https://youtube.com", help=__doc__) @click.argument("title", type=str) @click.pass_context def cli(ctx, **kwargs): return YT(ctx, **kwargs)
cli
method, even if you do not want or need any CLI arguments. It is required for the core CLI functionality to be able to find and call the class. - Accept the CLI arguments by overriding the constructor (the
__init__()
method):def __init__(self, ctx, title): self.title = title super().__init__(ctx) # important # ... the title is now available across all methods by calling self.title
[!NOTE]
- All methods of your class inherited from
Service
marked as abstract (@abstractmethod
) MUST be implemented by your class.- When overriding any method (e.g.,
__init__()
method) you MUST super call it, e.g.,super().__init__()
at the top of the override. This does not apply to any abstract methods, as they are unimplemented.- If preparing your Requests Session with global headers or such, then you should override the
get_session
method, then modifyself.session
. Do not manually makeself.session
from scratch.
[!TIP]
- To make web requests use the
self.session
class instance variable, e.g.self.session.get(url)
.- If you make a
config.yaml
file next to your__init__.py
, you can access it withself.config
.- You can include any arbitrary file within your Service folder for use by your Service. For example TLS certificate files, or other python files with helper functions and classes.
Service Tags
Service tags generally follow these rules:
- Tag must be between 2-4 characters long, consisting of just
[A-Z0-9i]{2,4}
.- Lower-case
i
is only used for select services. Specifically BBC iPlayer and iTunes.
- Lower-case
- If the Service's commercial name has a
+
orPlus
, the last character should be aP
. E.g.,ATVP
forApple TV+
,DSCP
forDiscovery+
,DSNP
forDisney+
, andPMTP
forParamount+
.
These rules are not exhaustive and should only be used as a guide. You don't strictly have to follow these rules, but I recommend doing so for consistency.
Sharing Services
Sending and receiving zipped Service folders is quite cumbersome. Let's explore alternative routes to collaborating on Service Code.
[!WARNING] Please be careful with who you trust and what you run. The users you collaborate with on Service code could update it with malicious code that you would run via devine on the next call.
Forking
If you are collaborating with a team on multiple services then forking the project is the best way to go.
- Fork the project and make sure it is Private.
- (optionally) Hard reset to the latest stable version by tag. E.g.,
git reset --hard v1.0.0
. - Add all your Services to the
/devine/services
folder and commit them to your fork.
Now commit changes or additions within that services folder to your forked repository.
Once committed all your other team members can easily pull changes as well as push new changes.
When a new update comes out you can easily rebase your fork to that commit to update. However, please make sure you look at changes between each version before rebasing and resolve any breaking changes and deprecations when rebasing to a new version.
If you are new to git
then take a look at GitHub Desktop.
[!TIP] A huge benefit with this method is that you can also sync dependencies by your own Services as well! Just use
poetry
to add or modify dependencies appropriately and commit the changedpoetry.lock
. However, if the core project also has dependency changes yourpoetry.lock
changes will conflict and you will need to learn how to do conflict resolution/rebasing. It is worth it though!
Symlinking
This is a great option for those who wish to do something like the forking method, but may not care what changes happened or when and just want changes synced across a team.
This also opens up the ways you can host or collaborate on Service code. As long as you can receive a directory that updates with just the services within it, then you're good to go. Options could include an FTP server, Shared Google Drive, a non-fork repository with just services, and more.
- Use any Cloud Source that gives you a pseudo-directory to access the Service files like a normal drive. E.g., rclone, Google Drive Desktop (aka File Stream), Air Drive, CloudPool, etc.
- Create a
services
directory somewhere in it and have all your services within it. - Symlink the
services
directory to the/devine
folder. You should end up with/devine/services
folder containing services, not/devine/services/services
.
You have to make sure the original folder keeps receiving and downloading/streaming those changes. You must also make sure that the version of devine you have locally is supported by the Service code.
[!NOTE] If you're using a cloud source that downloads the file once it gets opened, you don't have to worry as those will automatically download. Python importing the files triggers the download to begin. However, it may cause a delay on startup.
Profiles (Cookies & Credentials)
Just like a streaming service, devine associates both a cookie and/or credential as a Profile. You can associate up to one cookie and one credential per-profile, depending on which (or both) are needed by the Service. This system allows you to configure multiple accounts per-service and choose which to use at any time.
Credentials are stored in the config, and Cookies are stored in the data directory. You can find the location of these
by running devine env info
. However, you can manage profiles with devine auth --help
. E.g. to add a new John
profile to Netflix with a Cookie and Credential, take a look at the following CLI call,
devine auth add John NF --cookie "C:\Users\John\Downloads\netflix.com.txt --credential "john@gmail.com:pass123"
You can also delete a credential with devine auth delete
. E.g., to delete the cookie for John that we just added, run
devine auth delete John --cookie
. Take a look at devine auth delete --help
for more information.
Note Profile names are case-sensitive and unique per-service. They also have no arbitrary character or length limit, but for convenience I don't recommend using any special characters as your terminal may get confused.
Cookie file format and Extensions
Cookies must be in the standard Netscape cookies file format.
Recommended Cookie exporter extensions:
-
Firefox: "Export Cookies" by
Rotem Dan
-
Chromium: "Open Cookies.txt" by
Ninh Pham
,or "Get cookies.txt" byRahul Shaw
Any other extension that exports to the standard Netscape format should theoretically work.
Warning The Get cookies.txt extension by Rahul Shaw is essentially spyware. Do not use it. There are some safe versions floating around (usually just older versions of the extension), but since there are safe alternatives I'd just avoid it altogether. Source: https://reddit.com/r/youtubedl/comments/10ar7o7
Widevine Provisions
A Widevine Provision is needed for acquiring licenses containing decryption keys for DRM-protected content. They are not needed if you will be using devine on DRM-free services. Please do not ask for any Widevine Device Files, Keys, or Provisions as they cannot be provided.
Devine only supports .WVD
files (Widevine Device Files). However, if you have the Provision RSA Private Key and
Device Client Identification Blob as blob files (e.g., device_private_key
and device_client_id_blob
), then you can
convert them to a .WVD
file by running pywidevine create-device --help
.
Once you have .WVD
files, place them in the WVDs directory which can be found by calling devine env info
.
You can then set in your config which WVD (by filename only) to use by default with devine cfg cdm.default wvd_name
.
From here you can then set which WVD to use for each specific service. It's best to use the lowest security-level
provision where possible.
An alternative would be using a pywidevine Serve-compliant CDM API. Of course, you would need to know someone who is serving one, and they would need to give you access. Take a look at the remote_cdm config option for setup information. For further information on it see the pywidevine repository.
End User License Agreement
Devine and it's community pages should be treated with the same kindness as other projects. Please refrain from spam or asking for questions that infringe upon a Service's End User License Agreement.
- Do not use Devine for any purposes of which you do not have the rights to do so.
- Do not share or request infringing content; this includes Widevine Provision Keys, Content Encryption Keys, or Service API Calls or Code.
- The Core codebase is meant to stay Free and Open-Source while the Service code should be kept private.
- Do not sell any part of this project, neither alone nor as part of a bundle. If you paid for this software or received it as part of a bundle following payment, you should demand your money back immediately.
- Be kind to one another and do not single anyone out.
Contributors
Licensing
This software is licensed under the terms of GNU General Public License, Version 3.0.
You can find a copy of the license in the LICENSE file in the root folder.
© rlaphoenix 2019-2023