Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python linting #1

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: lunarmodules/luacheck@v1

python-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
6 changes: 6 additions & 0 deletions DOCS/interface-changes/sub-ass-use-video-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Remove sub-ass-vsfilter-aspect-compat.
Remove sub-ass-vsfilter-blur-compat.
Add sub-ass-use-video-data.
Add sub-ass-video-aspect-override.
Change default V keybind to cycle sub-ass-use-video-data
instead of toggling the now removed sub-ass-vsfilter-aspect-compat.
4 changes: 2 additions & 2 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ u
style. See ``--sub-ass-override`` for more info.

V
Toggle subtitle VSFilter aspect compatibility mode. See
``--sub-ass-vsfilter-aspect-compat`` for more info.
Cycle through which video data gets used for ASS rendering.
See ``--sub-ass-use-video-data`` for more info.

r and R
Move subtitles up/down. The ``t`` key does the same as ``R`` currently, but
Expand Down
41 changes: 19 additions & 22 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2568,31 +2568,28 @@ Subtitles

Default: yes.

``--sub-ass-vsfilter-aspect-compat=<yes|no>``
Stretch SSA/ASS subtitles when playing anamorphic videos for compatibility
with traditional VSFilter behavior. This switch has no effect when the
video is stored with square pixels.

The renderer historically most commonly used for the SSA/ASS subtitle
formats, VSFilter, had questionable behavior that resulted in subtitles
being stretched too if the video was stored in anamorphic format that
required scaling for display. This behavior is usually undesirable and
newer VSFilter versions may behave differently. However, many existing
scripts compensate for the stretching by modifying things in the opposite
direction. Thus, if such scripts are displayed "correctly", they will not
appear as intended. This switch enables emulation of the old VSFilter
behavior (undesirable but expected by many existing scripts).
``--sub-ass-use-video-data=<none|aspect-ratio|all>``
Controls which information about the video stream is passed to libass.
Any option but ``all`` is incompatible with standard ASS and VSFilters.

Enabled by default.
For certain kinds of broken ASS files which got repurposed across
several video resolutions without either setting ``LayoutRes`` headers
or adjusting affected effects, it may be desirable to withhold storage resolution
information from libass to ensure consistent rendering across resolutions.
Among others this affects 3D rotations and blurs.
When encountering such files, try setting ``aspect-ratio``.

Even more broken files on anamorphic video might also exhibit stretching
unless aspect ratio information is also faked, in this case you can try
using ``none``. This has never an effect on non-anamorphic video.

Default: ``all``

``--sub-ass-vsfilter-blur-compat=<yes|no>``
Scale ``\blur`` tags by video resolution instead of script resolution
(enabled by default). This is bug in VSFilter, which according to some,
can't be fixed anymore in the name of compatibility.
``--sub-ass-video-aspect-override=<no|ratio>``
Allows passing any arbitrary aspect ratio to libass instead of the video’s
actual aspect ratio. Zero or negative aspect ratios are identical to ``no``.

Note that this uses the actual video resolution for calculating the
offset scale factor, not what the video filter chain or the video output
use.
This has no effect if ``sub-ass-use-video-data`` is set to none.

``--sub-vsfilter-bidi-compat=<yes|no>``
Set implicit bidi detection to ``ltr`` instead of ``auto`` to match ASS'
Expand Down
2 changes: 1 addition & 1 deletion TOOLS/docutils-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def remove(path):
proc = subprocess.run(argv, check=True)
if depfile is not None:
convert_depfile(output, depfile)
except:
except Exception:
remove(output)
if depfile is not None:
remove(depfile)
Expand Down
20 changes: 10 additions & 10 deletions TOOLS/dylib_unhell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def is_user_lib(objfile, libname):
return not sys_re.match(libname) and \
not usr_re.match(libname) and \
not exe_re.match(libname) and \
not "libobjc." in libname and \
not "libSystem." in libname and \
not "libc." in libname and \
not "libgcc." in libname and \
"libobjc." not in libname and \
"libSystem." not in libname and \
"libc." not in libname and \
"libgcc." not in libname and \
not os.path.basename(libname) == 'Python' and \
not os.path.basename(objfile) in libname and \
not "libswift" in libname
os.path.basename(objfile) not in libname and \
"libswift" not in libname

def otool(objfile, rapths):
command = "otool -L '%s' | grep -e '\t' | awk '{ print $1 }'" % objfile
Expand All @@ -46,7 +46,7 @@ def get_rapths(objfile):

try:
result = subprocess.check_output(command, shell = True, universal_newlines=True)
except:
except Exception:
return rpaths

for line in result.splitlines():
Expand Down Expand Up @@ -90,17 +90,17 @@ def resolve_lib_path(objfile, lib, rapths):

def check_vulkan_max_version(version):
try:
result = subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True)
subprocess.check_output("pkg-config vulkan --max-version=" + version, shell = True)
return True
except:
except Exception:
return False

def get_homebrew_prefix():
# set default to standard ARM path, intel path is already in the vulkan loader search array
result = "/opt/homebrew"
try:
result = subprocess.check_output("brew --prefix", universal_newlines=True, shell=True, stderr=subprocess.DEVNULL).strip()
except:
except Exception:
pass

return result
Expand Down
4 changes: 1 addition & 3 deletions TOOLS/macos-sdk-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# This checks for the sdk path, the sdk version, and
# the sdk build version.

import re
import os
import string
import subprocess
import sys
from shutil import which
Expand Down Expand Up @@ -33,7 +31,7 @@ def find_macos_sdk():
try:
sdk_version = check_output([xcodebuild, '-sdk', 'macosx', '-version', 'ProductVersion'],
encoding="UTF-8", stderr=subprocess.DEVNULL)
except:
except Exception:
pass

if not isinstance(sdk_version, str):
Expand Down
21 changes: 11 additions & 10 deletions TOOLS/matroska.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
Can also be used to directly parse Matroska files and display their contents.
"""

import sys
from math import ldexp
from binascii import hexlify

#
# This file is part of mpv.
#
Expand Down Expand Up @@ -242,14 +246,11 @@
)


import sys
from math import ldexp
from binascii import hexlify

def byte2num(s):
return int(hexlify(s), 16)

class EOF(Exception): pass
class EOF(Exception):
pass

def camelcase_to_words(name):
parts = []
Expand Down Expand Up @@ -291,9 +292,9 @@ def add_subelements(self, subelements):

elementd = {}
elementlist = []
def parse_elems(l, namespace):
def parse_elems(elements, namespace):
subelements = []
for el in l:
for el in elements:
if isinstance(el, str):
name, hexid, eltype = [x.strip() for x in el.split(',')]
hexid = hexid.lower()
Expand Down Expand Up @@ -328,10 +329,10 @@ def generate_C_header(out):
continue
printf(out)
printf(out, 'struct {0.structname} {{'.format(el))
l = max(len(subel.valname) for subel, multiple in el.subelements)+1
length = max(len(subel.valname) for subel, multiple in el.subelements)+1
for subel, multiple in el.subelements:
printf(out, ' {e.valname:{l}} {star}{e.fieldname};'.format(
e=subel, l=l, star=' *'[multiple]))
printf(out, ' {e.valname:{length}} {star}{e.fieldname};'.format(
e=subel, length=length, star=' *'[multiple]))
printf(out)
for subel, multiple in el.subelements:
printf(out, ' int n_{0.fieldname};'.format(subel))
Expand Down
2 changes: 1 addition & 1 deletion TOOLS/stats-conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def mkColor(t):

for e in G.sevents:
cur = ax[1 if e.type == "value" else 0]
if not cur in G.curveno:
if cur not in G.curveno:
G.curveno[cur] = 0
args = {'name': e.name,'antialias':True}
color = mkColor(colors[G.curveno[cur] % len(colors)])
Expand Down
8 changes: 6 additions & 2 deletions audio/out/ao_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state)
// Give it a number of chances to recover. This tries to deal with the fact
// that the API is asynchronous, and to account for some past cargo-cult
// (where things were retried in a loop).
for (int n = 0; n < 10; n++) {
for (int n = 0; n <= 10; n++) {
err = snd_pcm_status(p->alsa, st);
if (err == -EPIPE) {
// ALSA APIs can return -EPIPE when an XRUN happens,
Expand All @@ -943,6 +943,9 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state)
pcmst = snd_pcm_status_get_state(st);
}

if (n == 10)
pcmst = SND_PCM_STATE_DISCONNECTED;

if (pcmst == SND_PCM_STATE_PREPARED ||
pcmst == SND_PCM_STATE_RUNNING ||
pcmst == SND_PCM_STATE_PAUSED)
Expand All @@ -959,7 +962,8 @@ static bool recover_and_get_state(struct ao *ao, struct mp_pcm_state *state)
case SND_PCM_STATE_XRUN:
case SND_PCM_STATE_DRAINING:
err = snd_pcm_prepare(p->alsa);
CHECK_ALSA_ERROR("pcm prepare error");
if (err < 0)
MP_ERR(ao, "pcm prepare error: %s\n", snd_strerror(err));
continue;
// Hardware suspend.
case SND_PCM_STATE_SUSPENDED:
Expand Down
6 changes: 5 additions & 1 deletion ci/lint-commit-msg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env python3
import os, sys, json, subprocess, re
import os
import sys
import json
import subprocess
import re
from typing import Dict, Tuple, Callable, Optional

def call(cmd) -> str:
Expand Down
2 changes: 1 addition & 1 deletion etc/input.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
#t add sub-pos +1 # move subtitles down
#v cycle sub-visibility # hide or show the subtitles
#Alt+v cycle secondary-sub-visibility # hide or show the secondary subtitles
#V cycle sub-ass-vsfilter-aspect-compat # toggle stretching SSA/ASS subtitles with anamorphic videos to match the historical renderer
#V cycle sub-ass-use-video-data # cycle which video data gets used in ASS rendering to fix broken files
#u cycle-values sub-ass-override "force" "scale" # toggle overriding SSA/ASS subtitle styles with the normal styles
#j cycle sub # switch subtitle track
#J cycle sub down # switch subtitle track backwards
Expand Down
13 changes: 8 additions & 5 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,14 @@ const struct m_sub_options mp_subtitle_sub_opts = {
M_RANGE(-1000, 1000)},
{"sub-use-margins", OPT_BOOL(sub_use_margins)},
{"sub-ass-force-margins", OPT_BOOL(ass_use_margins)},
{"sub-ass-vsfilter-aspect-compat", OPT_BOOL(ass_vsfilter_aspect_compat)},
{"sub-ass-vsfilter-color-compat", OPT_CHOICE(ass_vsfilter_color_compat,
{"no", 0}, {"basic", 1}, {"full", 2}, {"force-601", 3})},
{"sub-ass-vsfilter-blur-compat", OPT_BOOL(ass_vsfilter_blur_compat)},
{"sub-vsfilter-bidi-compat", OPT_BOOL(sub_vsfilter_bidi_compat)},
{"sub-ass-vsfilter-aspect-compat", OPT_REMOVED("replaced by sub-ass-use-video-data=aspect-ratio")},
{"sub-ass-vsfilter-blur-compat", OPT_REMOVED("replaced by sub-ass-use-video-data=all")},
{"sub-ass-use-video-data", OPT_CHOICE(ass_use_video_data,
{"none", 0}, {"aspect-ratio", 1}, {"all", 2})},
{"sub-ass-video-aspect-override", OPT_ASPECT(ass_video_aspect), M_RANGE(0, 10)},
{"embeddedfonts", OPT_BOOL(use_embedded_fonts), .flags = UPDATE_SUB_HARD},
{"sub-ass-style-overrides", OPT_STRINGLIST(ass_style_override_list),
.flags = UPDATE_SUB_HARD},
Expand Down Expand Up @@ -354,9 +357,9 @@ const struct m_sub_options mp_subtitle_sub_opts = {
.sub_scale_with_window = true,
.teletext_page = 0,
.sub_scale = 1,
.ass_vsfilter_aspect_compat = true,
.ass_vsfilter_color_compat = 1,
.ass_vsfilter_blur_compat = true,
.ass_use_video_data = 2,
.ass_video_aspect = 0,
.ass_shaper = 1,
.use_embedded_fonts = true,
},
Expand Down Expand Up @@ -1137,7 +1140,7 @@ static const struct MPOpts mp_default_opts = {
"sub-scale",
"sub-use-margins",
"sub-ass-force-margins",
"sub-ass-vsfilter-aspect-compat",
"sub-ass-use-video-data"
"sub-ass-override",
"secondary-sid",
"secondary-sub-delay",
Expand Down
4 changes: 2 additions & 2 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ struct mp_subtitle_opts {
float ass_line_spacing;
bool ass_use_margins;
bool sub_use_margins;
bool ass_vsfilter_aspect_compat;
int ass_vsfilter_color_compat;
bool ass_vsfilter_blur_compat;
bool sub_vsfilter_bidi_compat;
int ass_use_video_data;
double ass_video_aspect;
bool use_embedded_fonts;
char **ass_style_override_list;
char *ass_styles_file;
Expand Down
3 changes: 2 additions & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4464,7 +4464,8 @@ static const struct property_osd_display {
"${?secondary-sub-visibility==yes:visible${?secondary-sid==no: (but no secondary subtitles selected)}}"},
{"sub-forced-events-only", "Forced sub only"},
{"sub-scale", "Sub Scale"},
{"sub-ass-vsfilter-aspect-compat", "Subtitle VSFilter aspect compat"},
{"sub-ass-use-video-data", "Subtitle using video properties"},
{"sub-ass-video-aspect-override", "Subtitle aspect override"},
{"sub-ass-override", "ASS subtitle style override"},
{"secondary-sub-ass-override", "Secondary sub ASS subtitle style override"},
{"vf", "Video filters", .msg = "Video filters:\n${vf}"},
Expand Down
23 changes: 21 additions & 2 deletions player/lua/ytdl_hook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,29 @@ end

-- youtube-dl JSON name to mpv tag name
local tag_list = {
["artist"] = "artist",
["album"] = "album",
["album_artist"] = "album_artist",
["composer"] = "composer",
["upload_date"] = "date",
["genre"] = "genre",
["series"] = "series",
["track"] = "title",
["track_number"] = "track",
["uploader"] = "uploader",
["channel_url"] = "channel_url",
-- these titles tend to be a bit too long, so hide them on the terminal
-- (default --display-tags does not include this name)

-- These tags are not displayed by default, but can be shown with
-- --display-tags
["playlist"] = "ytdl_playlist",
["playlist_index"] = "ytdl_playlist_index",
["playlist_title"] = "ytdl_playlist_title",
["playlist_id"] = "ytdl_playlist_id",
["chapters"] = "ytdl_chapters",
["season"] = "ytdl_season",
["episode"] = "ytdl_episode",
["is_live"] = "ytdl_is_live",
["release_year"] = "ytdl_release_year",
["description"] = "ytdl_description",
-- "title" is handled by force-media-title
-- tags don't work with all_formats=yes
Expand Down
10 changes: 6 additions & 4 deletions sub/sd_ass.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,12 @@ static struct sub_bitmaps *get_bitmaps(struct sd *sd, struct mp_osd_res dim,

double scale = dim.display_par;
if (!converted && (!shared_opts->ass_style_override[sd->order] ||
opts->ass_vsfilter_aspect_compat))
opts->ass_use_video_data >= 1))
{
// Let's use the original video PAR for vsfilter compatibility:
double par = ctx->video_params.p_w / (double)ctx->video_params.p_h;
// Let's factor in video PAR for vsfilter compatibility:
double par = opts->ass_video_aspect > 0 ?
opts->ass_video_aspect :
ctx->video_params.p_w / (double)ctx->video_params.p_h;
if (isnormal(par))
scale *= par;
}
Expand All @@ -717,7 +719,7 @@ static struct sub_bitmaps *get_bitmaps(struct sd *sd, struct mp_osd_res dim,
}
ass_set_pixel_aspect(renderer, scale);
if (!converted && (!shared_opts->ass_style_override[sd->order] ||
opts->ass_vsfilter_blur_compat))
opts->ass_use_video_data >= 2))
{
ass_set_storage_size(renderer, ctx->video_params.w, ctx->video_params.h);
} else {
Expand Down
Loading