Skip to content

Commit fd08e61

Browse files
committed
first release ver
1 parent 9e63a86 commit fd08e61

File tree

7 files changed

+91
-54
lines changed

7 files changed

+91
-54
lines changed

.github/workflows/test_n_pub.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Run Tests
22

33
on:
44
push:
5-
branches:
6-
- "main"
75
tags:
86
- "v*.*.*"
97
pull_request:
@@ -22,15 +20,15 @@ jobs:
2220
exclude:
2321
- os: macos-latest
2422
python-version: 3.7
25-
- os: windows-latest
23+
- os: ubuntu-latest
2624
python-version: 3.7
2725
- os: macos-latest
2826
python-version: 3.8
29-
- os: windows-latest
27+
- os: ubuntu-latest
3028
python-version: 3.8
3129
- os: macos-latest
3230
python-version: 3.9
33-
- os: windows-latest
31+
- os: ubuntu-latest
3432
python-version: 3.9
3533

3634
steps:
@@ -52,7 +50,12 @@ jobs:
5250
run: pip install -q .
5351

5452
- name: Run tests
55-
run: pytest -vv
53+
# run: pytest -vv
54+
uses: nick-fields/retry@v2
55+
with:
56+
timeout_seconds: 15
57+
max_attempts: 3
58+
command: pytest -vv
5659

5760
distribute:
5861
name: Distribution

README.rst

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
`ffmpeg-downloader`: Python FFmpeg binary downloader
2-
===================================================
1+
`ffmpeg-downloader`: Python FFmpeg release build binary downloader
2+
==================================================================
33

44
|pypi| |pypi-status| |pypi-pyvers| |github-license| |github-status|
55

@@ -14,22 +14,58 @@
1414
.. |github-status| image:: https://img.shields.io/github/workflow/status/python-ffmpegio/python-ffmpeg-downloader/Run%20Tests
1515
:alt: GitHub Workflow Status
1616

17-
Python `ffmpeg-downloader` package automatically downloads FFmpeg binaries for Windows, Linux, & MacOS. Note
17+
Python `ffmpeg-downloader` package automatically downloads the latest FFmpeg release binaries for Windows, Linux, & MacOS. Note
1818
while it supports Linux and MacOS, it is intended for Windows users, for whom there is no installer is currently
1919
available. Linux and MacOS users should install via OS package manager (e.g., `apt-get` for Ubuntu and `brew` for MacOS).
2020

21-
Install `ffmpeg-downloader` package via ``pip``:
21+
The FFmpeg release builds are downloaded from 3rd party hosts:
22+
23+
======= =========================================================================
24+
Windows `https://www.gyan.dev/ffmpeg/builds <https://www.gyan.dev/ffmpeg/builds>`_
25+
Linux `https://johnvansickle.com/ffmpeg <https://johnvansickle.com/ffmpeg>`_
26+
MacOS `https://evermeet.cx/ffmpeg <https://evermeet.cx/ffmpeg>`_
27+
======= =========================================================================
28+
29+
If you appreciate their efforts to build and host these builds, please consider donating on their websites.
30+
31+
Installation
32+
------------
2233

2334
.. code-block:: bash
2435
2536
pip install ffmpeg-downloader
2637
27-
Console Command
28-
---------------
38+
Console Commands
39+
----------------
40+
41+
To download and install FFmpeg binaries:
42+
43+
.. code-block:: bash
44+
45+
python -m ffmpeg_downloader
46+
47+
To check for a newer release and update:
48+
49+
.. code-block:: bash
50+
51+
python -m ffmpeg_downloader --update
52+
53+
To uninstall:
54+
55+
.. code-block:: bash
56+
57+
python -m ffmpeg_downloader --remove
58+
59+
In Python
60+
---------
2961

30-
*
62+
This package exposes the following 4 attributes:
3163

32-
In-Python Use
33-
-------------
64+
.. code-block:: python
65+
66+
import ffmpeg_downloader as ffdl
3467
35-
*
68+
ffdl.ffmpeg_dir # FFmpeg binaries directory
69+
ffdl.ffmpeg_version # version string of the intalled FFmpeg
70+
ffdl.ffmpeg_path # full path of the FFmpeg binary
71+
ffdl.ffprobe_path # full path of the FFprobe binary

setup.cfg

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
[metadata]
22
name = ffmpeg_downloader
33
version = attr: ffmpeg_downloader.__version__
4-
description = FFmpeg Executable Downloader
4+
description = FFmpeg Release Build Downloader
55
# long_description_content_type = text/x-rst
66
# long_description = file: README.md
7-
keywords = multimedia
7+
keywords = multimedia, ffmpeg, ffprobe
88
license = GPL-2.0 License
9-
# url=https://python-ffmpegio.github.io/python-ffmpegio-downloader
9+
url=https://github.com/python-ffmpegio/python-ffmpeg-downloader
1010
project_urls=
11-
Repository=https://github.com/python-ffmpegio/python-ffmpeg-downloader
1211
Issues=https://github.com/python-ffmpegio/python-ffmpegio-downloader/issues
1312
Pull Requests=https://github.com/python-ffmpegio/python-ffmpegio-downloader/pulls
1413
classifiers =
@@ -32,6 +31,6 @@ packages=ffmpeg_downloader
3231
install_requires =
3332
tqdm
3433
# patool;platform_system!='Linux'
35-
pylzma
34+
# pylzma
3635
appdirs
3736
python_requires = >=3.7,

src/ffmpeg_downloader/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
__version__ = "0.0.0"
1+
__version__ = "0.1.0"
22
__all__ = [
33
"ffmpeg_dir",
44
"ffmpeg_version",
55
"ffmpeg_path",
66
"ffprobe_path",
7-
"has_update",
8-
"update",
9-
"remove",
107
]
118

129
from os import listdir, path, rmdir, name as os_name
@@ -15,7 +12,7 @@
1512
from appdirs import user_data_dir
1613

1714

18-
if sys.platform in ("win32", "cygwin"):
15+
if os_name == "nt":
1916
from ._win32 import (
2017
download_n_install,
2118
get_version as get_latest_version,
@@ -77,7 +74,9 @@ def __getattr__(name): # per PEP 562
7774
"ffmpeg_path": lambda: _ffmpeg_version()
7875
and path.join(_ffmpeg_dir(), "ffmpeg" if os_name != "nt" else "ffmpeg.exe"),
7976
"ffprobe_path": lambda: _ffmpeg_version()
80-
and path.join(_ffmpeg_dir(), "ffprobe" if os_name != "nt" else "ffprobe.exe"),
77+
and path.join(
78+
_ffmpeg_dir(), "ffprobe" if os_name != "nt" else "ffprobe.exe"
79+
),
8180
"ffmpeg_version": _ffmpeg_version,
8281
}[name]()
8382
except:

src/ffmpeg_downloader/_download_helper.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
from urllib import request
22
from contextlib import contextmanager
3-
import os, stat
3+
import os, stat, ssl
4+
5+
ctx = ssl.create_default_context()
6+
ctx.check_hostname = False
7+
ctx.verify_mode = ssl.CERT_NONE
48

59

610
@contextmanager
7-
def download_base(url, content_type, ctx=None):
8-
with request.urlopen(url, timeout=1.0, context=ctx) as response:
11+
def download_base(url, content_type, timeout=None):
12+
with request.urlopen(url, timeout=timeout or 1.0, context=ctx) as response:
913
# pprint(response.headers.get_content_type())
1014
if response.headers.get_content_type() != content_type:
1115
raise RuntimeError(f'"{url}" is not the expected content type.')
@@ -16,15 +20,15 @@ def download_base(url, content_type, ctx=None):
1620
yield response, nbytes
1721

1822

19-
def download_info(url, content_type, ctx=None):
20-
with download_base(url, content_type, ctx) as (response, nbytes):
23+
def download_info(url, content_type, timeout=None):
24+
with download_base(url, content_type, timeout) as (response, nbytes):
2125
info = response.read().decode("utf-8")
2226
return info
2327

2428

25-
def download_file(outfile, url, content_type, ctx=None, progress=None):
29+
def download_file(outfile, url, content_type, progress=None, timeout=None):
2630

27-
with download_base(url, content_type, ctx) as (response, nbytes):
31+
with download_base(url, content_type, timeout) as (response, nbytes):
2832
if progress:
2933
progress(0, nbytes)
3034

src/ffmpeg_downloader/_linux.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,9 @@
88

99
def get_version():
1010

11-
ctx = ssl.create_default_context()
12-
ctx.check_hostname = False
13-
ctx.verify_mode = ssl.CERT_NONE
14-
1511
return re.search(
1612
r"version: (\d+\.\d+(?:\.\d+)?)",
17-
download_info(
18-
f"{home_url}/release-readme.txt",
19-
"text/plain",
20-
ctx,
21-
),
13+
download_info(f"{home_url}/release-readme.txt", "text/plain", 10),
2214
)[1]
2315

2416

@@ -29,16 +21,14 @@ def download_n_install(install_dir, progress=None, arch=None):
2921
elif arch not in archs:
3022
raise ValueError(f"Invalid arch specified. Must be one of {arch}")
3123

32-
ctx = ssl.create_default_context()
33-
ctx.check_hostname = False
34-
ctx.verify_mode = ssl.CERT_NONE
35-
3624
with TemporaryDirectory() as tmpdir:
3725
tarpath = path.join(tmpdir, "ffmpeg_linux.tar.xz")
3826
url = f"{home_url}/releases/ffmpeg-release-{arch}-static.tar.xz"
3927

4028
with TemporaryDirectory() as tmpdir:
41-
download_file(tarpath, url, "application/x-xz", ctx, progress=progress)
29+
download_file(
30+
tarpath, url, "application/x-xz", progress=progress, timeout=10
31+
)
4232

4333
with tarfile.open(tarpath, "r") as f:
4434
f.extractall(tmpdir)
@@ -54,6 +44,7 @@ def download_n_install(install_dir, progress=None, arch=None):
5444
except:
5545
pass
5646

47+
# os.makedirs(install_dir, exist_ok=True)
5748
shutil.move(src_dir_path, install_dir)
5849

5950
for cmd in ("ffmpeg", "ffprobe"):

src/ffmpeg_downloader/_macos.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tempfile import TemporaryDirectory
22
from os import path
3-
import json, os, zipfile
3+
import json, os, zipfile, shutil
44
from ._download_helper import download_info, download_file, chmod, download_base
55

66
home_url = "https://evermeet.cx/ffmpeg"
@@ -16,10 +16,14 @@ def download_n_install(install_dir, progress=None):
1616

1717
ntotal = 0
1818

19-
nfiles = [
20-
download_base(f"{home_url}/getrelease/{cmd}/zip")
21-
for cmd in ("ffmpeg", "ffprobe")
22-
]
19+
def get_nbytes(cmd):
20+
with download_base(f"{home_url}/getrelease/{cmd}/zip", "application/zip") as (
21+
_,
22+
nbytes,
23+
):
24+
return nbytes
25+
26+
nfiles = [get_nbytes(cmd) for cmd in ("ffmpeg", "ffprobe")]
2327
ntotal = sum(nfiles)
2428
n1 = nfiles[0]
2529
prog = (
@@ -47,7 +51,8 @@ def download_n_install(install_dir, progress=None):
4751
os.remove(dst_path)
4852
except:
4953
pass
50-
os.rename(path.join(tmpdir, cmd), dst_path)
54+
os.makedirs(install_dir, exist_ok=True)
55+
shutil.move(path.join(tmpdir, cmd), dst_path)
5156
chmod(dst_path)
5257

5358
with open(path.join(install_dir, "VERSION"), "wt") as f:

0 commit comments

Comments
 (0)