from yt_dlp import YoutubeDL
from custom_pornhub import CustomPornHubIE
import logging

# 配置日志记录
logger = logging.getLogger('yt_dlp')
logger.setLevel(logging.DEBUG)  # 设置为 DEBUG 级别
handler = logging.StreamHandler()  # 输出到终端
logger.addHandler(handler)

# 自定义选项
ydl_opts = {
    'extract_flat': True,  # 仅提取元数据
    'skip_download': True,  # 跳过视频下载
    'verbose': True,        # 启用详细日志
    'logger': logger,       # 使用自定义日志记录器
}

with YoutubeDL(ydl_opts) as ydl:
    # 添加自定义提取器
    ydl.add_info_extractor(CustomPornHubIE())

    # 打印已注册的提取器列表
    print("调试: 已注册的提取器列表:")
    for ie_name in ydl._ies:
        print(ie_name)

    # 提取视频信息
    info = ydl.extract_info("https://www.pornhub.com/view_video.php?viewkey=6710f3bc00200")
    
    # 输出信息
    print(info)

    # 输出收藏次数
    print(f"收藏次数: {info.get('favorites_count', '未找到')}")