#!python

"""
threefive command line SCTE35 decoder.

( type 'make cli' or 'make pypy3-cli' as root
to install to /usr/local/bin )

use like:

    cat myvideo.ts | threefive

    threefive https://futzu.com/xaa.ts

    threefive myvideo.ts yourvideo.ts someothervideo.ts

    threefive mpegts_dir/*.ts

    threefive '/DBZAAAAAAAA///wBQb+AAAAAABDAkFDVUVJAAAACn//AAApMuAPLXVybjp1dWlkOmFhODViYmI2LTVjNDMtNGI2YS1iZWJiLWVlM2IxM2ViNzk5ORAAAFz7UQA='
"""


import sys
import threefive

if __name__ == "__main__":
    if sys.argv and sys.argv[1].lower() in [b'version','version']:
        print(f'{threefive.version}')
        sys.exit()
    if len(sys.argv) > 1:
        if sys.argv[1].lower() in [b'pts','pts']:
            strm = threefive.Stream(sys.argv[2])
            strm.show_pts()
            sys.exit()
        if sys.argv[1].lower() in [b'show','show']:
            strm = threefive.Stream(sys.argv[2])
            strm.show()
            sys.exit()
        for arg in sys.argv[1:]:
            threefive.decode(arg)
    else:
        threefive.decode(sys.stdin.buffer)
