<commit_before>(function() {

const VIDEO_TYPES = {
    'FLV': [
        { i: '5', n: '224p' },
        { i: '6', n: '270p' },
        { i: '34', n: '360p' },
        { i: '35', n: '480p' }
    ],
    '3GP': [
        { i: '17', n: '144p' },
        { i: '36', n: '240p' }
    ],
    'MP4': [
        { i: '18', n: '360p' },
        { i: '22', n: '720p' },
        { i: '37', n: '1080p' },
        { i: '38', n: '2304p' }
    ],
    'MP4 (3D)': [
        { i: '83', n: '240p' },
        { i: '82', n: '360p' },
        { i: '85', n: '520p' },
        { i: '84', n: '720p' }
    ],
    'MP4 (video-only)': [
        { i: '160', n: '144p' },
        { i: '133', n: '240p' },
        { i: '134', n: '360p' },
        { i: '135', n: '480p' },
        { i: '136', n: '720p' },
        { i: '137', n: '1080p' }
    ],
    'MP4 (audio-only)': [
        { i: '139', n: '48kbs' },
        { i: '140', n: '128kbs' },
        { i: '141', n: '256kbs' }
    ],
    'WebM': [
        { i: '43', n: '360p' },
        { i: '44', n: '480p' },
        { i: '45', n: '720p' }
    ],
    'WebM (3D)': [
        { i: '100', n: '360p' },
        { i: '101', n: '480p' },
        { i: '46', n: '540p' },
        { i: '102', n: '720p' }
    ]
};

const FMT_STREAM_MAP_PTN = /"url_encoded_fmt_stream_map": "([^"]+)"/;
const ADAPTIVE_FMT_STREAM_MAP_PTN = /"adaptive_fmts": "([^"]+)"/;
const FMT_ITAG_PTN = /itag=(\d+)/;
const FMT_URL_PTN = /url=([^&]+)/;
const FMT_SIG_PTN = /s=([^&]+)/;

function showDownloadLinks(title, fmtUrlList) {
    var links,
        type,
        videoList,
        inUrlList,
        item,
        index,
        fmt,
        anchor,
        button,
        panel;

    inUrlList = function(fmt) {
        return fmt.i in fmtUrlList;
    };

    links = $('<ul>').attr('id', 'download-list');
    for (type in VIDEO_TYPES) {
        videoList = VIDEO_TYPES[type].filter(inUrlList);
        if (!videoList.length) { continue; }

        item = $('<li>').attr({'style': 'padding: 3px 10px'});
        item.append($('<span>').attr({
            'style': 'display: inline-block; width: 120px'
        }).append(type + ':'));

        for (index in videoList) {
            fmt = videoList[index];
            item.append($('<a>').attr({
                'href': fmtUrlList[fmt.i] + '&title=' + title,
                'style': 'display: inline-block; width: 50px'
            }).append(fmt.n));
        }

        links = links.append(item);
    }

    panel = $('<div>').attr({
        'id': 'action-panel-download',
        'class': 'action-panel-content hid',
        'data-panel-loaded': 'true'
    }).append($('<div>').attr({
        'id': 'watch-actions-download',
        'class': 'watch-actions-panel'
    }).append(links));
    $('#action-panel-details').after(panel);

    anchor = $('#watch7-secondary-actions').find('span').first();
    button = anchor.clone();
    button.find('button')
        .attr('data-trigger-for', 'action-panel-download')
        .removeClass('yt-uix-button-toggled');
    button.find('span').text('下載');
    anchor.after(button);
}

function extractTitle() {
    var title = $('#eow-title').attr('title');
    return encodeURIComponent(title).replace(/%20/g, '+');
}

function extractSig(s) {
    return s.slice(5, 56) + s[3] + s.slice(57);
}

function extractUrl(text) {
    var urlMatch = FMT_URL_PTN.exec(text);
    return decodeURIComponent(urlMatch[1]);
}

function extractUrlWithSig(text) {
    var sigMatch = FMT_SIG_PTN.exec(text),
        sig = extractSig(sigMatch[1]);
    return extractUrl(text) + '&signature=' + sig;
}

function createFmtUrlList(fmtStreamMap, urlExtractor, fmtUrlList) {
    var fmtStreamList,
        index,
        text,
        itagMatch;

    fmtStreamList = fmtStreamMap
        .replace(/\\u0026/g, '&')
        .split(',');

    fmtUrlList = fmtUrlList || {};
    for (index in fmtStreamList) {
        text = fmtStreamList[index];
        itagMatch = FMT_ITAG_PTN.exec(text);
        fmtUrlList[itagMatch[1]] = urlExtractor(text);
    }

    return fmtUrlList;<commit_msg>Update url extraction rule<commit_after>(function() {

const VIDEO_TYPES = {
    'FLV': [
        { i: '5', n: '224p' },
        { i: '6', n: '270p' },
        { i: '34', n: '360p' },
        { i: '35', n: '480p' }
    ],
    '3GP': [
        { i: '17', n: '144p' },
        { i: '36', n: '240p' }
    ],
    'MP4': [
        { i: '18', n: '360p' },
        { i: '22', n: '720p' },
        { i: '37', n: '1080p' },
        { i: '38', n: '2304p' }
    ],
    'MP4 (3D)': [
        { i: '83', n: '240p' },
        { i: '82', n: '360p' },
        { i: '85', n: '520p' },
        { i: '84', n: '720p' }
    ],
    'MP4 (video-only)': [
        { i: '160', n: '144p' },
        { i: '133', n: '240p' },
        { i: '134', n: '360p' },
        { i: '135', n: '480p' },
        { i: '136', n: '720p' },
        { i: '137', n: '1080p' }
    ],
    'MP4 (audio-only)': [
        { i: '139', n: '48kbs' },
        { i: '140', n: '128kbs' },
        { i: '141', n: '256kbs' }
    ],
    'WebM': [
        { i: '43', n: '360p' },
        { i: '44', n: '480p' },
        { i: '45', n: '720p' }
    ],
    'WebM (3D)': [
        { i: '100', n: '360p' },
        { i: '101', n: '480p' },
        { i: '46', n: '540p' },
        { i: '102', n: '720p' }
    ]
};

const FMT_STREAM_MAP_PTN = /"url_encoded_fmt_stream_map": "([^"]+)"/;
const ADAPTIVE_FMT_STREAM_MAP_PTN = /"adaptive_fmts": "([^"]+)"/;
const FMT_ITAG_PTN = /itag=(\d+)/;
const FMT_URL_PTN = /url=([^&]+)/;
const FMT_SIG_PTN = /sig=([^&]+)/;
const FMT_ENCODED_SIG_PTN = /s=([^&]+)/;

function showDownloadLinks(title, fmtUrlList) {
    var links,
        type,
        videoList,
        inUrlList,
        item,
        index,
        fmt,
        anchor,
        button,
        panel;

    inUrlList = function(fmt) {
        return fmt.i in fmtUrlList;
    };

    links = $('<ul>').attr('id', 'download-list');
    for (type in VIDEO_TYPES) {
        videoList = VIDEO_TYPES[type].filter(inUrlList);
        if (!videoList.length) { continue; }

        item = $('<li>').attr({'style': 'padding: 3px 10px'});
        item.append($('<span>').attr({
            'style': 'display: inline-block; width: 120px'
        }).append(type + ':'));

        for (index in videoList) {
            fmt = videoList[index];
            item.append($('<a>').attr({
                'href': fmtUrlList[fmt.i] + '&title=' + title,
                'style': 'display: inline-block; width: 50px'
            }).append(fmt.n));
        }

        links = links.append(item);
    }

    panel = $('<div>').attr({
        'id': 'action-panel-download',
        'class': 'action-panel-content hid',
        'data-panel-loaded': 'true'
    }).append($('<div>').attr({
        'id': 'watch-actions-download',
        'class': 'watch-actions-panel'
    }).append(links));
    $('#action-panel-details').after(panel);

    anchor = $('#watch7-secondary-actions').find('span').first();
    button = anchor.clone();
    button.find('button')
        .attr('data-trigger-for', 'action-panel-download')
        .removeClass('yt-uix-button-toggled');
    button.find('span').text('下載');
    anchor.after(button);
}

function extractTitle() {
    var title = $('#eow-title').attr('title');
    return encodeURIComponent(title).replace(/%20/g, '+');
}

function extractSig(s) {
    return s.slice(5, 56) + s[3] + s.slice(57);
}

function extractUrl(text) {
    var urlMatch = FMT_URL_PTN.exec(text);
    return decodeURIComponent(urlMatch[1]);
}

function extractUrlWithSig(text) {
    var sigMatch,
        url;

    url = extractUrl(text);
    if ((sigMatch = FMT_SIG_PTN.exec(text)) !== null) {
        url += '&signature=' + sigMatch[1];
    }
    else if ((sigMatch = FMT_ENCODED_SIG_PTN.exec(text)) !== null) {
        url += '&signature=' + extractSig(sigMatch[1]);
    }

    return url;
}

function createFmtUrlList(fmtStreamMap, urlExtractor, fmtUrlList) {
    var fmtStreamList,
        index,
        text,
        itagMatch;

    fmtStreamList = fmtStreamMap
        .replace(/\\u0026/g, '&')
        .split(',');

    fmtUrlList = fmtUrlList || {};
    for (index in fmtStreamList) {
        text = fmtStreamList[index];
        itagMatch = FMT_ITAG_PTN.exec(text);
        fmtUrlList[itagMatch[1]] = urlExtractor(text);
    }

    return fmtUrlList;
{'fraction_non_alphanumeric': 0.21657657657657658, 'fraction_numerical': 0.046486486486486484, 'mean_word_length': 2.1125233644859813, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1835848', 'n_tokens_mistral': 3408, 'n_tokens_neox': 3146, 'n_words': 614}