# Path: build/plugin/src/resources/libraries/youtube_dl/compat.py
# def compat_realpath(path):
#     while os.path.islink(path):
#         path = os.path.abspath(os.readlink(path))
#     return path
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/utils.py
# def encode_compat_str(string, encoding=preferredencoding(), errors='strict'):
#     return string if isinstance(string, compat_str) else compat_str(string, encoding, errors)
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/version.py



import io
import json
import traceback
import hashlib
import os
import subprocess
import sys
from zipimport import zipimporter
from .compat import compat_realpath
from .utils import encode_compat_str
from .version import __version__
    from hashlib import sha256

    def sha256sum():
        h = hashlib.sha256()
        b = bytearray(128 * 1024)
        mv = memoryview(b)
        with open(os.path.realpath(sys.executable), 'rb', buffering=0) as f:
            for n in iter(lambda: f.readinto(mv), 0):
                h.update(mv[:n])
        return h.hexdigest()

    to_screen('Current Build Hash %s' % sha256sum())

    if not isinstance(globals().get('__loader__'), zipimporter) and not hasattr(sys, 'frozen'):
        to_screen('It looks like you installed youtube-dlc with a package manager, pip, setup.py or a tarball. Please use that to update.')
        return

    # compiled file.exe can find itself by
    # to_screen(os.path.basename(sys.executable))
    # and path to py or exe
    # to_screen(os.path.realpath(sys.executable))

    # Check if there is a new version
    try:
        newversion = opener.open(VERSION_URL).read().decode('utf-8').strip()
    except Exception:
        if verbose:
            to_screen(encode_compat_str(traceback.format_exc()))
        to_screen('ERROR: can\'t find the current version. Please try again later.')
        to_screen('Visit https://github.com/blackjack4494/yt-dlc/releases/latest')
        return

# Path: build/plugin/src/resources/libraries/youtube_dl/compat.py
# def compat_realpath(path):
#     while os.path.islink(path):
#         path = os.path.abspath(os.readlink(path))
#     return path
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/utils.py
# def encode_compat_str(string, encoding=preferredencoding(), errors='strict'):
#     return string if isinstance(string, compat_str) else compat_str(string, encoding, errors)
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/version.py



# Path: build/plugin/src/resources/libraries/youtube_dl/update.py
import io
import json
import traceback
import hashlib
import os
import subprocess
import sys
from zipimport import zipimporter
from .compat import compat_realpath
from .utils import encode_compat_str
from .version import __version__
    from hashlib import sha256


    def sha256sum():
        h = hashlib.sha256()
        b = bytearray(128 * 1024)
        mv = memoryview(b)
        with open(os.path.realpath(sys.executable), 'rb', buffering=0) as f:
            for n in iter(lambda: f.readinto(mv), 0):
                h.update(mv[:n])
        return h.hexdigest()

    to_screen('Current Build Hash %s' % sha256sum())

    if not isinstance(globals().get('__loader__'), zipimporter) and not hasattr(sys, 'frozen'):
        to_screen('It looks like you installed youtube-dlc with a package manager, pip, setup.py or a tarball. Please use that to update.')
        return

    # compiled file.exe can find itself by
    # to_screen(os.path.basename(sys.executable))
    # and path to py or exe
    # to_screen(os.path.realpath(sys.executable))

    # Check if there is a new version
    try:
        newversion = opener.open(VERSION_URL).read().decode('utf-8').strip()
    except Exception:
        if verbose:
            to_screen(encode_compat_str(traceback.format_exc()))
        to_screen('ERROR: can\'t find the current version. Please try again later.')
        to_screen('Visit https://github.com/blackjack4494/yt-dlc/releases/latest')
        return

    if newversion == __version__: