Jaded-Encoding-Thaumaturgy / vs-preview

Previewer for VapourSynth scripts.
Apache License 2.0
57 stars 16 forks source link

dataclasses.py missing in vspreview 0.7.1 pip3 buggy package #158

Closed sosie-js closed 4 days ago

sosie-js commented 4 days ago

I am still tying to make it work from pip3 with python 3.10 after my attempt on ubuntu 22.04 which provides python 3.10 only

pip3 install vspreview==0.7.1

then I patched due to encode/decode error

window=`python3 -c "import vspreview as _; print(str.replace(_.__file__,'__init__','main/window'))"`;sed 's/decode/encode/g' $window > $window.tmp ; cp $window.tmp  $window; rm $window.tmp`

vspreview VTS_09_1.vpy works fine wit this content

import vapoursynth as vs
from vapoursynth import core
from dataclasses import dataclass, field

#vs.core.log_message(vs.MESSAGE_TYPE_DEBUG, 'hello there')

input=r'VTS_09_1.VOB'

#LibavSource2
#video = core.lsmas.LWLibavSource(input)  #for ts, m2ts, mts
#audio = core.bas.Source(input, track=-1)
#
#video = core.ffms2.Source(source=input)

#from _AI_ https://forum.doom9.org/showthread.php?t=184300
@dataclass 
class Clip:
    def __init__(self, video = None, audio=None, attribute_audio_path=None):
        self.video = video
        self.audio = audio
        if self.video is None:
            self.video = core.std.BlankClip()
        if self.audio is None:
            if attribute_audio_path is None:
                raise ValueError('argument attribute_audio_path is needed to get default audio for images (could be a really short video')
            attr_audio = core.bas.Source(attribute_audio_path)
            length = int(attr_audio.sample_rate/self.video.fps*self.video.num_frames)
            self.audio = attr_audio.std.BlankAudio(length=length)

    def trim(self, first=0, last=None, length=None):
        afirst  = self.to_samples(first)    if first  is not None else None
        alast   = self.to_samples(last+1)-1 if last   is not None else None
        alength = self.to_samples(length)   if length is not None else None
        return Clip( self.video.std.Trim(first=first, last=last, length=length),
                     self.audio.std.AudioTrim(first=afirst,last=alast,length=alength)
                    )
    def to_samples(self, frame):
        return int((self.audio.sample_rate/self.video.fps)*frame)

    def __add__(self, other):
        return Clip(self.video + other.video, self.audio + other.audio)

    def __mul__(self, multiple):
        return Clip(self.video*multiple, self.audio*multiple)

    def __getitem__(self, val):
        if isinstance(val, slice):
            if val.step is not None:
                raise ValueError('Using steps while slicing AudioNode together with VideoNode makes no sense')
            start = self.to_samples(val.start) if val.start is not None else None
            stop =  self.to_samples(val.stop)  if val.stop  is not None else None
            return Clip( self.video.__getitem__(val),
                         self.audio.__getitem__(slice(start,stop))
                         )
        elif isinstance(val, int):
            start = self.to_samples(val)
            stop = int(start + self.audio.sample_rate/self.video.fps)
            return Clip( self.video[val],
                         self.audio.__getitem__(slice(start,stop))
                         )        
    def __repr__(self):
        return '{}\n{}\n{}'.format('Clip():\n-------', repr(self.video), repr(self.audio))

    def __str__(self):
        return '{}\n{}\n{}'.format('Clip():\n-------', str(self.video), str(self.audio))

def AudioDub(video, audio):
    video.set_output(0)
    audio.set_output(1)

##################################
## @ atrack  - audio track number. Default auto. If -2, ignore audio.
## @ fpsnum, fpsden - framerate. Default auto.
## @ format  - force specified output pixel format. Default auto.
##    (see documentation for valid color formats)
## @ cache - if true (the default), create an index file.
##
##
def BSSource(source, atrack = -1, vtrack = -1, variableformat = False, fpsnum = -1, fpsden = 1):
    video =  core.bs.VideoSource(source=input, track = -1)
    if (atrack==-2) :
        video.set_output(0)
    else:
        AudioDub(video, core.bs.AudioSource(source=input, track = -1) )
    return video
video=BSSource(input)

but when I copy it to test.py and trigger vspreview test.vpy I got:

2024-07-02 16:22:45.471: root: WARNING: Storage (Local) parsing failed on line 28 column 30. 
(while constructing a Python object
cannot find module 'vspreview.core.types.dataclasses' (No module named 'vspreview.core.types.dataclasses'))

I found a way to regenerate the missing dataclasses

window=`python3 -c "import vspreview as _; print(str.replace(_.__file__,'__init__.py','core/types'))"`;python3 -m pip install -t $window dataclasses

It installs dataclasses-0.6 and dataclasses.py lacking in core/types but lacks of CroppingInfo support, leading this a mess.

2024-07-02 16:56:55.794: root: WARNING: Storage (Local) parsing failed on line 28 column 30. 
(while constructing a Python object
cannot find 'CroppingInfo' in the module 'vspreview.core.types.dataclasses')

Where can we find a correct dataclasses ?. It seems outdated stuff but anoying to start vspreview é_è with a simple blank vpy script!

sosie-js commented 4 days ago

I opened issue on github dataclasses.

Setsugennoao commented 4 days ago

What the hell?

sosie-js commented 4 days ago

Buggy pip3 package combined to a lack of dataclasses support that 'normally' python3 handles itself since 3.7 but it is not the case. This is my guess..

LightArrowsEXE commented 4 days ago

This is entirely user error. Post one more poor issue and I will revoke your ability to make any in the future.

Setsugennoao commented 4 days ago

You said that the moment I was blocking him from the org 😭

LightArrowsEXE commented 4 days ago

@Setsugennoao has already banned you, but you can appeal this in our support discord if you believe it was in error.