[vlc-devel] [PATCH] appletrailers.lua: Fix script for website changes

Pierre Ynard linkfanel at yahoo.fr
Wed Oct 26 17:24:16 CEST 2016


> -    return vlc.access == "http"
> -        and string.match( vlc.path, "trailers.apple.com" )
> -        and string.match( vlc.path, "web.inc" )
> +    return (vlc.access == "http" or vlc.access == "https")
> +        and string.match( vlc.path, "^trailers%.apple%.com/trailers/.+/.+" )

Isn't this script supposed to work in cooperation with the appletrailers
service discovery script? I think that's where the web.inc comes from.
Although it's a great feature to fix it to work with the HTML page
itself too.

> +-- JSON parser lazy initialization
> +local json = nil

Uuh apparently it's used in only one place in the script so you don't
really need that complexity.

> +    json["parse_url"] = function(url)
> +        local stream = vlc.stream(url)
> +        local string = ""
> +        local line   = ""
> +
> +        repeat
> +            line = stream:readline()
> +            string = string..line
> +        until line ~= nil

vlc.stream() can fail for any number of reasons, it returns nil and then
you hit a bug calling nil:readline()

> +        local movietitle = lookup_keys(info, "details/locale/en/movie_title")
> +        local desc       = lookup_keys(info, "details/locale/en/synopsis")

Is the "en" locale always available?

> +            item["name"]        = movietitle .. " (" .. clip["title"]  .. ")"

You should test that these fields exist, or else concatenation will
throw an error.

> +-- Get the user-preferred quality src
> +function get_preferred_src(clip)
> +    local resolution = vlc.var.inherit(nil, "preferred-resolution")
> +    if resolution == -1 then
> +        return lookup_keys(clip, "versions/enus/sizes/hd1080/srcAlt")
> +    end
> +    if resolution >= 1080 then
> +        return lookup_keys(clip, "versions/enus/sizes/hd1080/srcAlt")
> +    end
> +    if resolution >= 720 then
> +        return lookup_keys(clip, "versions/enus/sizes/hd720/srcAlt")
> +    end
> +    return lookup_keys(clip, "versions/enus/sizes/sd/srcAlt")
> +end

Not very flexible and future-proof, but okay. You can at least `or` the
-1 and 1080 conditions.

But really, anything that fixes it into something working is great,
thanks!

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."


More information about the vlc-devel mailing list