# Path: yledl/utils.py
# def ffmpeg_loglevel(py_loglevel):
#     """Convert a Python log level to the corresponding ffmpeg log level."""
#     if py_loglevel >= logging.CRITICAL:
#         return 'fatal'
#     elif py_loglevel >= logging.ERROR:
#         return 'error'
#     elif py_loglevel >= logging.DEBUG:
#         return 'warning'
#     else:
#         return 'info'


import json
import logging
import re
import subprocess
from .utils import ffmpeg_loglevel


logger = logging.getLogger('yledl')


class Ffprobe:
    def __init__(self, ffprobe_binary, ffmpeg_binary, x_forwarded_for):
        self.ffprobe_binary = ffprobe_binary
        self.ffmpeg_binary = ffmpeg_binary
        self.x_forwarded_for = x_forwarded_for

    def show_programs_for_url(self, url):
        args = [
            self.ffprobe_binary,
            '-loglevel', ffmpeg_loglevel(logger.getEffectiveLevel()),
            '-headers', f'X-Forwarded-For: {self.x_forwarded_for}\r\n',
            '-show_programs',
            '-print_format', 'json=c=1',
            '-probesize', '80000000',
            '-i', url,

# Path: yledl/utils.py
# def ffmpeg_loglevel(py_loglevel):
#     """Convert a Python log level to the corresponding ffmpeg log level."""
#     if py_loglevel >= logging.CRITICAL:
#         return 'fatal'
#     elif py_loglevel >= logging.ERROR:
#         return 'error'
#     elif py_loglevel >= logging.DEBUG:
#         return 'warning'
#     else:
#         return 'info'


# Path: yledl/ffprobe.py
import json
import logging
import re
import subprocess
from .utils import ffmpeg_loglevel



logger = logging.getLogger('yledl')


class Ffprobe:
    def __init__(self, ffprobe_binary, ffmpeg_binary, x_forwarded_for):
        self.ffprobe_binary = ffprobe_binary
        self.ffmpeg_binary = ffmpeg_binary
        self.x_forwarded_for = x_forwarded_for

    def show_programs_for_url(self, url):
        args = [
            self.ffprobe_binary,
            '-loglevel', ffmpeg_loglevel(logger.getEffectiveLevel()),
            '-headers', f'X-Forwarded-For: {self.x_forwarded_for}\r\n',
            '-show_programs',
            '-print_format', 'json=c=1',
            '-probesize', '80000000',
            '-i', url,

        ]