code:
#!/bin/bash
if [ ! -d ".git" ]; then
	#not running in git repo, so can't use git commands :-)
	echo "No .git repo found - skipping sanity checks"
	exit 0
fi

WARNING='\033[93m'
WARNING='\033[93m'
ENDC='\033[0m'

myprint() {
	while read data; do
		echo -n -e "[$1]$WARNING"
		echo "$data"
	done
}

GREP="git grep -n --color"
# Check for missing right angle bracket: <</if>
$GREP "<</[^>]*>[^>]" -- 'game/*'  | myprint "MissingClosingAngleBracket"
$GREP "<<[^>()]*>[^()<>"$'\r]*\r'"\?$" -- 'game/*' | myprint "MissingClosingAngleBracket"
# Check for missing left angle bracket: </if>>
$GREP "\([^<]\|^\)</\?\(if\|else\|case\|set\|print\|elseif\)" -- 'game/*' | myprint "MissingOpeningAngleBracket2"
# Check for accidental assignment.  e.g.:   <<if $foo = "hello">>
$GREP "<<[ ]*if[^>=]*[^><\!=]=[^=][^>]*>>" -- 'game/*' | myprint "AccidentalAssignmentInIf"
# Check for accidental assignment.  e.g.:   <<elseif $foo = "hello">>
$GREP "<<[ ]*elseif[^>=]*[^><\!=]=[^=][^>]*>>" -- 'game/*' | myprint "AccidentalAssignmentInElseIf"
# Check for missing ".  e.g.:   <<if $foo == "hello>>
# $GREP -e "<<[^\"<>]*\"[^\"<>]*>>" -- 'game/*' | myprint "MissingSpeechMark"
# Check for missing ".  e.g.:   <<if $foo = "hello)
# $GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'game/*' | myprint "MissingSpeechMark2"
# Check for colours like: @@color:red   - should be @@.red
$GREP -e "@@color:" --and --not -e  "@@color:rgb([0-9 ]\+,[0-9 ]\+,[0-9 ]\+)" -- "game/*" | myprint "UseCssColors"
# Check for missing $ in activeSlave or PC
$GREP "<<[ ]*[^\$><_\[]*\(activeSlave\|PC\)[.]"  -- "game/*" | myprint "MissingDollar"
# Check for closing bracket without opening bracket.  e.g.:  <<if foo)>>	  (but  <<case "foo")>>   is valid, so ignore those
$GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case"  -- "game/*" | myprint "MissingOpeningBracket"
# Check for opening bracket without closing bracket.  e.g.:  <<if (foo>>
$GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "game/*" | myprint "MissingClosingBracket"
# Check for two closing brackets but one opening bracket.  e.g.:  <<if (foo))>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>"  -- "game/*" | myprint "MissingOpeningBracket2"
# Check for one closing bracket but two opening brackets.  e.g.:  <<if ((foo)>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>"  -- "game/*" | myprint "MissingClosingBracket2"
$GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "game/*" | myprint "MissingClosingBracket3"
# Check for missing >>.  e.g.:   <<if $foo
$GREP "<<[^<>]*[^,\"\[{"$'\r]\r'"\?$" -- 'game/*' | myprint "MissingClosingAngleBrackets"
# Check for too many >>>.  e.g.: <</if>>>
$GREP "<<[^<>\"]*[<>]\?[^<>\"]*>>>" -- "game/*" | myprint "TooManyAngleBrackets"
# Check for too many <<<.  e.g.: <<</if>>
$GREP "<<<[^<>\"]*[<>]\?[^<>\"]*>>" -- "game/*" | myprint "TooManyAngleBrackets2"
# Check for wrong capitalisation on 'activeslave' and other common typos
$GREP  "\(csae\|[a-z] She \|attepmts\|youreslf\|advnaces\|canAcheive\|setBellySize\|SetbellySize\|setbellySize\|bellypreg\|pregBelly\|bellyimplant\|bellyfluid\|pronounCaps\|carress\)" -- 'game/*' | myprint "SpellCheck"
$GREP  "\(recieve\|recieves\)" -- 'game/*' | myprint "PregmodderCannotSpellReceive"
$GREP "\$slave\[" -- 'game/*' | myprint "ShouldBeSlaves"
# Check for strange spaces e.g.  $slaves[$i]. lips
$GREP "\$slaves\[\$i\]\. " -- 'game/*' | myprint "MissingPropertyAfterSlaves"
# Check, e.g., <<//if>>
$GREP "<</[a-zA-Z]*[^a-zA-Z<>]\+[a-zA-Z]*>>" -- 'game/*' | myprint "DoubleSlash"
# Check, e.g.  <<else $foo==4
$GREP "<<else >\?[^>]" -- 'game/*' | myprint "ShouldBeElseIf"
# Check, e.g., =to
$GREP "=to" -- 'game/*' | myprint "EqualAndTo"
# Check, e.g.  <<set foo == 4>>
$GREP "<<set[^{>=]*==" -- 'game/*' | myprint "DoubleEqualsInSet"
# Check for, e.g   <<if slaves[foo]>>
$GREP "<<\([^>]\|[^>]>[^>]\)*[^$]slaves\[" -- 'game/*' | myprint "MissingDollar"
# Check for missing $ or _ in variable name:
$GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- game/* | myprint "MissingDollar2"
# Check for missing command, e.g.  <<foo =
$GREP -e "<<[a-zA-Z]* = *" -- game/* | myprint "BadCommand"
# Check for duplicate words, e.g. with with
$GREP -e  " \(\b[a-zA-Z][a-zA-Z]\+\) \1\b " --and --not -e " her her " --and --not -e " you you " --and --not -e " New New " --and --not -e "Slave Slave " --and --not -e " that that " --and --not -e " in in " --and --not -e " is is " -- 'game/*' | myprint "Duplicate words"
# Check for obsolete SugarCube macros
$GREP -E "<<display |<<click|<<.*\.contains" -- game/* | myprint "ObsoleteMacro"
# Check for double articles
$GREP -E "\Wa an\W" -- game/* | myprint "DoubleArticle"
# Check for incorrect articles
$GREP -i -E "\Wa (a|e|i|o|u)." -- game/* | grep -a -i -vE "\Wa (un|eu|us|ut|on|ur|in)." | grep -a -i -vE "(&|<<s>>|UM)." | myprint "IncorrectArticle"
$GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- game/* | grep -a -i -vE "[A-Z]{3}" | myprint "IncorrectArticle"
# Check for $ sign mid-word
$GREP -i "\w$\w" -- game/* | myprint "VarSignMidWord"
# check for $ sign at beginning of macro
$GREP '<<\s*\$' -- 'game/*'  | myprint "VarSignAtMacroStart"
# check for missing ; before statement
$GREP 'if $ ' -- 'game/*'  | myprint "missing ; before statement"
$GREP 'elseif $ ' -- 'game/*'  | myprint "missing ; before statement"
# Check that we do not have any variables that we use only once.   e.g.	 $onlyUsedOnce
# Ignore  *Nationalities
(
cd game/
find . -name "*.twee" -exec cat '{}' ';' | tr -c '$a-zA-Z' '\n'  | sed -n '/^[$]/p' | sort | uniq -u | sed 's/^[$]/-e[$]/' | sed 's/$/\\\\W/' | xargs -r  git grep -n --color | myprint "OnlyUsedOnce"
find . -name "*.twee" -exec cat '{}' ';' | tr -c '.$a-zA-Z[]_' '\n' | sed 's/SugarCube\.State\.variables\./$/g' | sed -n -e 's/^[$]\(PC\|activeSlave\|\(slaves\|tanks\)\[[^]]*\]*\)[.]\([a-zA-Z]\+\).*$/[.]\3/p' | sort | uniq -u |sed 's/^\(.*\)$/-e\1\\\\\b/'  | xargs -r git grep -n --color | myprint "SlaveAttributeUsedOnce"
$GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot"

#Find all the variables listed in init.twee
VARIABLELIST=$(cat base-system/init.twee | tr -c '$a-zA-Z' '\n'  | sed -n '/^[$]/p' | sort | uniq)
# Find all variables anywhere.  Commented out because the output is too noisy currently
#VARIABLELIST=$(find . -name "*.twee" -exec cat '{}' ';' | tr -c '$a-zA-Z' '\n'  | sed -n '/^[$]/p' | sort | uniq)
MISSINGFROMVERSIONUPDATE=$(for variable in $VARIABLELIST; do grep -q "$variable" base-system/version-update.twee || echo "$variable"; done)
echo -e "base-system/version-update.twee$ENDC: $(echo $MISSINGFROMVERSIONUPDATE)" | myprint "MissingFromVersionUpdate"
)

git ls-files "game/*.twee" | xargs -d '\n'  ./devTools/check.py

path: sanityCheck


code:
/*CSS override*/
/*Remove comments to apply*/
/*#stats {
	top: 256px;
}

body.has-images #story-caption {
	margin-top: calc(278px - 2.5em);
}*/

repo_name: ammm/more

license: mit


code:
root = true

[**.py]
charset = utf-8
indent_size = 4
indent_style = space
trim_trailing_whitespace = true
insert_final_newline = true

repo_name: Lesmiscore/ytdl

path: .editorconfig


code:
* text=auto

Makefile* text whitespace=-tab-in-indent
*.sh text eol=lf
*.md diff=markdown
*.py diff=python

path: .gitattributes


code:
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username

custom: ['https://github.com/yt-dlp/yt-dlp/blob/master/Collaborators.md#collaborators']


code:
name: Broken site
description: Report broken or misfunctioning site
labels: [triage, site-bug]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a broken site
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
          required: true
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
          required: true
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell
    validations:
      required: true


code:
name: Site support request
description: Request support for a new site
labels: [triage, site-request]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a new site support request
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that none of provided URLs [violate any copyrights](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: example-urls
    attributes:
      label: Example URLs
      description: |
        Provide all kinds of example URLs for which support should be added
      placeholder: |
        - Single video: https://www.youtube.com/watch?v=BaW_jenozKc
        - Single video: https://youtu.be/BaW_jenozKc
        - Playlist: https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc
    validations:
      required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
          required: true
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
          required: true
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell
    validations:
      required: true


code:
name: Site feature request
description: Request a new functionality for a supported site
labels: [triage, site-enhancement]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm requesting a site-specific feature
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: example-urls
    attributes:
      label: Example URLs
      description: |
        Example URLs that can be used to demonstrate the requested feature
      placeholder: |
        https://www.youtube.com/watch?v=BaW_jenozKc
    validations:
      required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
          required: true
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
          required: true
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell
    validations:
      required: true


code:
name: Bug report
description: Report a bug unrelated to any particular site or extractor
labels: [triage, bug]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a bug unrelated to a specific site
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
          required: true
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
          required: true
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell
    validations:
      required: true


code:
name: Feature request
description: Request a new functionality unrelated to any particular site or extractor
labels: [triage, enhancement]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm requesting a feature unrelated to a specific site
          required: true
        - label: I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell


code:
name: Ask question
description: Ask yt-dlp related question
labels: [question]
body:
  - type: checkboxes
    attributes:
      label: DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
      description: Fill all fields even if you think it is irrelevant for the issue
      options:
        - label: I understand that I will be **blocked** if I remove or skip any mandatory\* field
          required: true
  - type: markdown
    attributes:
      value: |
        ### Make sure you are **only** asking a question and not reporting a bug or requesting a feature.
        If your question contains "isn't working" or "can you add", this is most likely the wrong template.
        If you are in doubt whether this is the right template, **USE ANOTHER TEMPLATE**!
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm asking a question and **not** reporting a bug or requesting a feature
          required: true
        - label: I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
          required: true
        - label: I've verified that I'm running yt-dlp version **2022.09.01** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar questions **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: question
    attributes:
      label: Please make sure the question is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information and as much context and examples as possible
    validations:
      required: true
  - type: checkboxes
    id: verbose
    attributes:
      label: Provide verbose output that clearly demonstrates the problem
      options:
        - label: Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
        - label: Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below
  - type: textarea
    id: log
    attributes:
      label: Complete Verbose Output
      description: |
        It should start like this:
      placeholder: |
        [debug] Command-line config: ['-vU', 'test:youtube']
        [debug] Portable config "yt-dlp.conf": ['-i']
        [debug] Encodings: locale cp65001, fs utf-8, pref cp65001, out utf-8, error utf-8, screen utf-8
        [debug] yt-dlp version 2022.09.01 [9d339c4] (win32_exe)
        [debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.22000-SP0
        [debug] Checking exe version: ffmpeg -bsfs
        [debug] Checking exe version: ffprobe -bsfs
        [debug] exe versions: ffmpeg N-106550-g072101bd52-20220410 (fdk,setts), ffprobe N-106624-g391ce570c8-20220415, phantomjs 2.1.1
        [debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
        [debug] Proxy map: {}
        [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
        Latest version: 2022.09.01, Current version: 2022.09.01
        yt-dlp is up to date (2022.09.01)
        <more lines>
      render: shell


code:
name: Extractor porting request to yt-dlp
description: Request for porting extractor to yt-dlp
labels: [triage, yt-dlp-port]
body:
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes:
      options:
        - label: I'm reporting a yt-dlp porting request
          required: true
        - label: I don't have opened site support request at yt-dlp repository. I understand this issue will be marked as duplicate, when there is
          required: true
        - label: I've searched the [list of supported website of yt-dlp](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md), and it's not supported
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I sware the extractor is not for piracy website. Also I understand and accept that reqeusting porting NSFW website **ia a commissioned work**
          required: true
        - label: I sware the extractor is ABSOLUTELY not for piracy website
          required: true
  - type: textarea
    id: example-urls
    attributes:
      label: Example URLs or extractor name
      description: |
        Example URLs or extractor name to identify which one is your requets.
      placeholder: |
        https://www.youtube.com/watch?v=BaW_jenozKc
        youtube
    validations:
      required: true


code:
blank_issues_enabled: false
contact_links:
  - name: Get help from the community on Discord
    url: https://discord.gg/H5MNcFW63r
    about: Join the yt-dlp Discord for community-powered support!
  - name: Matrix Bridge to the Discord server
    url: https://matrix.to/#/#yt-dlp:matrix.org
    about: For those who do not want to use Discord


code:
name: Broken site
description: Report broken or misfunctioning site
labels: [triage, site-bug]
body:
  %(no_skip)s
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a broken site
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  %(verbose)s


code:
name: Site support request
description: Request support for a new site
labels: [triage, site-request]
body:
  %(no_skip)s
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a new site support request
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that none of provided URLs [violate any copyrights](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: example-urls
    attributes:
      label: Example URLs
      description: |
        Provide all kinds of example URLs for which support should be added
      placeholder: |
        - Single video: https://www.youtube.com/watch?v=BaW_jenozKc
        - Single video: https://youtu.be/BaW_jenozKc
        - Playlist: https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc
    validations:
      required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  %(verbose)s


code:
name: Site feature request
description: Request a new functionality for a supported site
labels: [triage, site-enhancement]
body:
  %(no_skip)s
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm requesting a site-specific feature
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
        - label: I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required
  - type: input
    id: region
    attributes:
      label: Region
      description: Enter the country/region that the site is accessible from
      placeholder: India
  - type: textarea
    id: example-urls
    attributes:
      label: Example URLs
      description: |
        Example URLs that can be used to demonstrate the requested feature
      placeholder: |
        https://www.youtube.com/watch?v=BaW_jenozKc
    validations:
      required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  %(verbose)s


code:
name: Bug report
description: Report a bug unrelated to any particular site or extractor
labels: [triage, bug]
body:
  %(no_skip)s
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm reporting a bug unrelated to a specific site
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've checked that all provided URLs are playable in a browser with the same IP and same login details
          required: true
        - label: I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  %(verbose)s


code:
name: Feature request
description: Request a new functionality unrelated to any particular site or extractor
labels: [triage, enhancement]
body:
  %(no_skip)s
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm requesting a feature unrelated to a specific site
          required: true
        - label: I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: description
    attributes:
      label: Provide a description that is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information, any suggested solutions, and as much context and examples as possible
    validations:
      required: true
  %(verbose_optional)s


code:
name: Ask question
description: Ask yt-dlp related question
labels: [question]
body:
  %(no_skip)s
  - type: markdown
    attributes:
      value: |
        ### Make sure you are **only** asking a question and not reporting a bug or requesting a feature.
        If your question contains "isn't working" or "can you add", this is most likely the wrong template.
        If you are in doubt whether this is the right template, **USE ANOTHER TEMPLATE**!
  - type: checkboxes
    id: checklist
    attributes:
      label: Checklist
      description: |
        Carefully read and work through this check list in order to prevent the most common mistakes and misuse of yt-dlp:
      options:
        - label: I'm asking a question and **not** reporting a bug or requesting a feature
          required: true
        - label: I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
          required: true
        - label: I've verified that I'm running yt-dlp version **%(version)s** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
          required: true
        - label: I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar questions **including closed ones**. DO NOT post duplicates
          required: true
        - label: I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
          required: true
  - type: textarea
    id: question
    attributes:
      label: Please make sure the question is worded well enough to be understood
      description: See [is-the-description-of-the-issue-itself-sufficient](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-description-of-the-issue-itself-sufficient)
      placeholder: Provide any additional information and as much context and examples as possible
    validations:
      required: true
  %(verbose_optional)s


code:
**IMPORTANT**: PRs without the template will be CLOSED

### Description of your *pull request* and other information

</details>

<!--

Explanation of your *pull request* in arbitrary form goes here. Please **make sure the description explains the purpose and effect** of your *pull request* and is worded well enough to be understood. Provide as much **context and examples** as possible

-->

ADD DESCRIPTION HERE

Fixes #

<details open><summary>Template</summary> <!-- OPEN is intentional -->

<!--

# PLEASE FOLLOW THE GUIDE BELOW

- You will be asked some questions, please read them **carefully** and answer honestly
- Put an `x` into all the boxes `[ ]` relevant to your *pull request* (like [x])
- Use *Preview* tab to see how your *pull request* will actually look like

-->

### Before submitting a *pull request* make sure you have:
- [ ] At least skimmed through [contributing guidelines](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions) including [yt-dlp coding conventions](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#yt-dlp-coding-conventions)
- [ ] [Searched](https://github.com/yt-dlp/yt-dlp/search?q=is%3Apr&type=Issues) the bugtracker for similar pull requests
- [ ] Checked the code with [flake8](https://pypi.python.org/pypi/flake8) and [ran relevant tests](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#developer-instructions)

### In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under [Unlicense](http://unlicense.org/). Check one of the following options:
- [ ] I am the original author of this code and I am willing to release it under [Unlicense](http://unlicense.org/)
- [ ] I am not the original author of this code but it is in public domain or released under [Unlicense](http://unlicense.org/) (provide reliable evidence)

### What is the purpose of your *pull request*?
- [ ] Fix or improvement to an extractor (Make sure to add/update tests)
- [ ] New extractor ([Piracy websites will not be accepted](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#is-the-website-primarily-used-for-piracy))
- [ ] Core bug fix/improvement
- [ ] New feature (It is strongly [recommended to open an issue first](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#adding-new-feature-or-making-overarching-changes))


code:
name: Build Patched YTDL

on:
  push:
    paths:
      - yt_dlp/**
      - test/**
      - docker/**
      - .github/workflows/build.yml
      - Makefile
      - setup.py
    branches-ignore:
      - gh-pages
  pull_request:
    types: [ opened, synchronize, ready_for_review ]
  workflow_dispatch:
    inputs:

env:
  python_version: 3.9
  python_version_pyinst: 3.7
  windows_icon: red
  ZOPFLI_ITERATIONS: 40

jobs:
  prepare:
    runs-on: ubuntu-latest
    outputs:
      latest_version: ${{ steps.prepare.outputs.latest_version }}
      latest_version_normalized: ${{ steps.prepare.outputs.latest_version_normalized }}
      latest_version_numeric: ${{ steps.prepare.outputs.latest_version_numeric }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ env.python_version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ env.python_version }}
      - name: Install deps
        run: |
          sudo ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
          sudo apt update
          sudo env DEBIAN_FRONTEND=noninteractive apt install -y tzdata
          mkdir artifacts/
          touch artifacts/.keep
      - name: Prepare files
        id: prepare
        run: python3 devscripts/update-version.py
      - name: Upload artifacts for the next steps
        uses: actions/upload-artifact@v2
        with:
          name: ytdl-artifacts
          path: |
            yt_dlp/version.py
            yt_dlp/build_config.py
            artifacts/
  build-linux:
    runs-on: ubuntu-latest
    needs: prepare
    outputs:
      filehash_bin: ${{ steps.build.outputs.filehash_bin }}
      filehash_tar: ${{ steps.build.outputs.filehash_tar }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Download base
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - name: Create buildconfig.py
        run: python ./devscripts/make_buildconfig.py
      - name: Set up Python ${{ env.python_version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ env.python_version }}
      - name: Install deps
        run: |
          sudo ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
          sudo apt update
          sudo env DEBIAN_FRONTEND=noninteractive apt install -y curl zip make git gawk pandoc tzdata p7zip-full
          brew install advancecomp
      - name: Build patched YTDL for Linux
        run: |
          make ytdl-patched ytdl-patched.tar.gz
          mv ytdl-patched artifacts/
          mv ytdl-patched.tar.gz artifacts/
          echo "::set-output name=filehash_bin::$(sha256sum artifacts/ytdl-patched | awk '{print $1}')"
          echo "::set-output name=filehash_tar::$(sha256sum artifacts/ytdl-patched.tar.gz | awk '{print $1}')"
      - name: Upload artifacts for the next steps
        uses: actions/upload-artifact@v2
        with:
          name: ytdl-artifacts
          # README.md (or any other files in the repo) is required
          # to prevent upload-artifacts to find LCA
          path: |
            artifacts/
            README.md
  build-wheel:
    runs-on: ubuntu-latest
    needs: prepare
    outputs:
      filehash_wheel: ${{ steps.hash.outputs.filehash_wheel }}
      filehash_wheel_tar: ${{ steps.hash.outputs.filehash_wheel_tar }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Download base
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - name: Set up Python ${{ env.python_version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ env.python_version }}
      - name: Create buildconfig.py
        run: python ./devscripts/make_buildconfig.py
      - name: Install deps
        run: pip3 install -U pip build wheel setuptools
      - name: Build wheel
        run: python3 -m build
      - name: Calculate hashes
        id: hash
        run: |
          echo "::set-output name=filehash_wheel::$(sha256sum dist/yt_dlp-${{ needs.prepare.outputs.latest_version_normalized }}-py2.py3-none-any.whl | awk '{print $1}')"
          echo "::set-output name=filehash_wheel_tar::$(sha256sum dist/yt-dlp-${{ needs.prepare.outputs.latest_version_normalized }}.tar.gz | awk '{print $1}')"
      - name: Upload artifacts for the next steps
        uses: actions/upload-artifact@v2
        with:
          name: ytdl-artifacts
          # README.md (or any other files in the repo) is required
          # to prevent upload-artifacts to find LCA
          path: |
            dist/
            README.md
      - name: Show contents of dist/
        continue-on-error: true
        run: ls dist/

  build-windows:
    runs-on: windows-latest
    needs: prepare
    outputs:
      filehash_exe_red: ${{ steps.hash.outputs.filehash_exe_red }}
      filehash_exe_white: ${{ steps.hash.outputs.filehash_exe_white }}
    strategy:
      fail-fast: false
      matrix:
        icon: [red, white]
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Download base
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - name: Create buildconfig.py
        run: python ./devscripts/make_buildconfig.py variant=${{ matrix.icon }}
      - name: Set up Python ${{ env.python_version_pyinst }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ env.python_version_pyinst }}
      - name: Upgrade pip and enable wheel support
        run: python -m pip install --upgrade pip setuptools wheel
      - name: Install deps
        run: pip install -U "https://yt-dlp.github.io/Pyinstaller-Builds/x86_64/pyinstaller-4.10-py3-none-any.whl" zopflipy websockets python-dateutil mutagen pycryptodomex
      - name: Install UPX
        shell: pwsh
        run: pwsh ./devscripts/install_upx.ps1
      - name: Remove unneeded tests in InfoExtractor
        shell: bash
        run: python3 ./devscripts/reduce_code.py yt_dlp/extractor/*.py
        if: ${{ 0 == 1 }}  # always skip this step
      - name: Build patched YTDL for Windows
        shell: pwsh
        run: pwsh ./devscripts/build_windows_exe.ps1 PyInstaller ${{ matrix.icon }}
      - name: Compress generated EXE
        run: upx --lzma --best artifacts/ytdl-patched.exe
        continue-on-error: true
      - name: Calculate hash
        id: hash
        run: echo "::set-output name=filehash_exe_${{ matrix.icon }}::$((Get-FileHash artifacts/ytdl-patched.exe -Algorithm SHA256).Hash.ToLower())"
      - name: Rename file
        run: mv artifacts/ytdl-patched.exe artifacts/ytdl-patched-${{ matrix.icon }}.exe
      - name: Upload artifacts for the next steps
        uses: actions/upload-artifact@v2
        with:
          name: ytdl-artifacts
          # README.md (or any other files in the repo) is required
          # to prevent upload-artifacts to find LCA
          path: |
            artifacts/
            README.md

  upload-releases:
    needs: [prepare, build-linux, build-windows, build-wheel]
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/ytdlp' }}
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts

      - name: Create release (for master)
        id: create_release
        uses: actions/create-release@v1
        if: ${{ github.ref == 'refs/heads/ytdlp' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ needs.prepare.outputs.latest_version }}
          release_name: ${{ needs.prepare.outputs.latest_version }}
          draft: false
          prerelease: false
          body: |
            What to download?
            - for Linux/macOS - `ytdl-patched` (requires Python 3.x installed)
            - for Windows (no Python 3.x required)
                - red icon - `...-red.exe` (**default** in -U)
                - white icon - `...-white.exe`
            - for pip - `yt_dlp-wheel.tar.gz`

            This release is built from commit ${{ github.sha }}

            **ytdl-patched is now yt-dlp-based version**
      - name: Create release
        if: ${{ github.ref == 'refs/heads/ytdlp' }}
        run: echo "upload_url=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_ENV

      - name: Create release (for non-master)
        id: create_release_nm
        uses: actions/create-release@v1
        if: ${{ github.ref != 'refs/heads/ytdlp' }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ needs.prepare.outputs.latest_version }}
          release_name: ${{ needs.prepare.outputs.latest_version }}
          draft: false
          prerelease: true
          body: |
            - **NOTICE: THIS IS FOR DEVEOPMENT PURPOSES**
            - **注意: 開発者向けビルドです。**
            - `github.ref`: ${{ github.ref }}
            - `github.sha`: ${{ github.sha }}
            - expected version: ${{ needs.prepare.outputs.latest_version }}
      - name: Create release (for non-master)
        if: ${{ github.ref != 'refs/heads/ytdlp' }}
        run: echo "upload_url=${{ steps.create_release_nm.outputs.upload_url }}" >> $GITHUB_ENV

      - name: Upload bin (Releases)
        id: upload-1
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./artifacts/ytdl-patched
          asset_name: ytdl-patched
          asset_content_type: application/zip
      - name: Upload source tar (Releases)
        id: upload-2
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./artifacts/ytdl-patched.tar.gz
          asset_name: ytdl-patched.tar.gz
          asset_content_type: application/gzip

      - name: Upload red exe (Releases)
        id: upload-3
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./artifacts/ytdl-patched-red.exe
          asset_name: ytdl-patched-red.exe
          asset_content_type: application/vnd.microsoft.portable-executable
      - name: Upload white exe (Releases)
        id: upload-4
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./artifacts/ytdl-patched-white.exe
          asset_name: ytdl-patched-white.exe
          asset_content_type: application/vnd.microsoft.portable-executable

      - name: Upload wheel (Releases)
        id: upload-5
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./dist/yt_dlp-${{ needs.prepare.outputs.latest_version_normalized }}-py2.py3-none-any.whl
          asset_name: yt_dlp-py2.py3-none-any.whl
          asset_content_type: application/zip
      - name: Upload wheel tar (Releases)
        id: upload-6
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ env.upload_url }}
          asset_path: ./dist/yt-dlp-${{ needs.prepare.outputs.latest_version_normalized }}.tar.gz
          asset_name: yt_dlp-wheel.tar.gz
          asset_content_type: application/gzip

  upload-homebrew:
    needs: [prepare, build-wheel, upload-releases]
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/ytdlp' }}
    env:
      FILEHASH_TAR: ${{ needs.build-wheel.outputs.filehash_wheel_tar }}
      VERSION: ${{ needs.prepare.outputs.latest_version }}
      VERSION_NAME: ${{ needs.prepare.outputs.latest_version }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Upload to my homebrew repository
        run: |
          git config --global user.name lesmiscore
          git config --global user.email 10355528+Lesmiscore@users.noreply.github.com
          git clone https://lesmiscore:${{ secrets.GH_PAT }}@github.com/lesmiscore/homebrew-my.git
          cd homebrew-my
          echo $FILEHASH_TAR $VERSION
          python3 ../devscripts/update-formulae.py Formula/ytdl-patched.rb "$FILEHASH_TAR" "$VERSION" "https://github.com/ytdl-patched/ytdl-patched/releases/download/$VERSION/yt_dlp-wheel.tar.gz"
          git add .
          git commit -m "ytdl-patched: $VERSION"
          git push

  upload-internetarchive:
    needs: [prepare, build-linux, build-windows, build-wheel]
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/ytdlp' }}
    steps:
      - name: Install ia command and configure
        run: |
          sudo apt update
          sudo apt install -y squashfs-tools
          brew install internetarchive
          ia configure -u "${{ secrets.IA_USERNAME }}" -p "${{ secrets.IA_PASSWORD }}"

      - name: Download artifacts
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts

      - name: Upload bin (IA)
        run: |
          ia upload ytdl-patched-binaries \
            --remote-name "${{ needs.prepare.outputs.latest_version }}/ytdl-patched" \
            -H x-archive-keep-old-version:0 \
            -H x-archive-queue-derive:0 \
            ./artifacts/ytdl-patched
      - name: Upload source tar (IA)
        run: |
          ia upload ytdl-patched-binaries \
            --remote-name "${{ needs.prepare.outputs.latest_version }}/ytdl-patched.tar.gz" \
            -H x-archive-keep-old-version:0 \
            -H x-archive-queue-derive:0 \
            ./artifacts/ytdl-patched.tar.gz

      - name: Upload compressed exe files (IA)
        run: |
          mkdir exe_files/
          cp ./artifacts/ytdl-patched-red.exe ./artifacts/ytdl-patched-white.exe exe_files/
          mksquashfs exe_files/ win_exe.sqfs \
            -comp xz -progress -b 1M -Xdict-size 50% \
            -no-xattrs -force-uid 1000 -force-gid 1000
          ia upload ytdl-patched-binaries \
            --remote-name "${{ needs.prepare.outputs.latest_version }}/win_exe.sqfs" \
            -H x-archive-keep-old-version:0 \
            -H x-archive-queue-derive:0 \
            win_exe.sqfs

      - name: Upload wheel (IA)
        run: |
          ia upload ytdl-patched-binaries \
            --remote-name "${{ needs.prepare.outputs.latest_version }}/yt_dlp-py2.py3-none-any.whl" \
            -H x-archive-keep-old-version:0 \
            -H x-archive-queue-derive:0 \
            ./dist/yt_dlp-${{ needs.prepare.outputs.latest_version_normalized }}-py2.py3-none-any.whl
      - name: Upload wheel tar (IA)
        run: |
          ia upload ytdl-patched-binaries \
            --remote-name "${{ needs.prepare.outputs.latest_version }}/yt_dlp-wheel.tar.gz" \
            -H x-archive-keep-old-version:0 \
            -H x-archive-queue-derive:0 \
            ./dist/yt-dlp-${{ needs.prepare.outputs.latest_version_normalized }}.tar.gz

  binary-test:
    needs: [build-linux, build-windows]
    runs-on: ${{ matrix.environ.os }}
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        environ: [
          { os: "ubuntu-22.04" },
          { os: "ubuntu-20.04" },

          # { os: "macos-11.0" },
          # { os: "macos-10.15" },

          { os: "windows-2022" },
          { os: "windows-2019" },
        ]
        python_version: ["3.10", "3.9", "3.8", "3.7"]
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - name: Set up Python ${{ matrix.python_version }}
        uses: actions/setup-python@v1
        if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
        with:
          python-version: ${{ matrix.python_version }}
      - name: Move executable file
        if: ${{ runner.os == 'windows' }}
        run: |
          mv ./artifacts/ytdl-patched-white.exe ./artifacts/ytdl-patched.exe
      - name: ytdl-patched --help and --version
        shell: bash
        run: |
          chmod a+x ./artifacts/ytdl-patched || true
          ./artifacts/ytdl-patched --help
          ./artifacts/ytdl-patched --version
      - name: Download some videos
        shell: bash
        continue-on-error: true
        run: |
          ./artifacts/ytdl-patched \
              https://www.youtube.com/watch?v=XEY7UQJxw-o \
              https://twitter.com/twetchapp/status/1311686520793829376
  docker-linux:
    runs-on: ubuntu-latest
    needs: [prepare, build-linux]
    continue-on-error: true
    if: ${{ 1 == 0 && github.event_name != 'pull_request' && github.ref == 'refs/heads/ytdlp' }}
    steps:
      - uses: actions/checkout@v2
      - name: Download artifacts
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - run: ls artifacts/
      - name: Login
        uses: docker/login-action@v1
        with:
          username: nao20010128nao
          password: ${{ secrets.DHUB_TOKEN }}
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Build and Push (alpine)
        uses: docker/build-push-action@v2
        with:
          push: true
          platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/i386,linux/ppc64le
          file: ./docker/linux.Dockerfile
          context: .
          build-args: |
            base_tag=3-alpine
          tags: |
            nao20010128nao/ytdl-patched:latest
            nao20010128nao/ytdl-patched:alpine
            nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}
            nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-alpine
      - name: Build and Push (slim)
        uses: docker/build-push-action@v2
        with:
          push: true
          platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/i386,linux/ppc64le
          file: ./docker/linux.Dockerfile
          context: .
          build-args: |
            base_tag=3-slim
          tags: |
            nao20010128nao/ytdl-patched:slim
            nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-slim
  docker-windows:
    runs-on: ${{ matrix.windows.os }}
    needs: [prepare, build-windows]
    continue-on-error: true
    if: ${{ 1 == 0 && github.event_name != 'pull_request' && github.ref == 'refs/heads/ytdlp' }}
    strategy:
      matrix:
        windows: [
          {os: windows-2019, tag: '1809'},
          {os: windows-2016, tag: ltsc2016},
        ]
    steps:
      - uses: actions/checkout@v2
      - name: Download artifacts
        uses: actions/download-artifact@v2
        with:
          name: ytdl-artifacts
      - run: mv artifacts/ytdl-patched-${{ env.windows_icon }}.exe artifacts/ytdl-patched.exe
      - run: ls artifacts/
      - name: Login
        run: docker login --username nao20010128nao --password ${{ secrets.DHUB_TOKEN }}
      - name: Build and Push (1809)
        if: ${{ matrix.windows.tag == '1809' }}
        run: |
          docker build --build-arg base_tag=3-windowsservercore-1809 `
              -f ./docker/windows.Dockerfile `
              -t nao20010128nao/ytdl-patched:latest `
              -t nao20010128nao/ytdl-patched:windowsservercore-1809 `
              -t nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }} `
              -t nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-windowsservercore-1809 `
              .
          docker push nao20010128nao/ytdl-patched:latest
          docker push nao20010128nao/ytdl-patched:windowsservercore-1809
          docker push nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}
          docker push nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-windowsservercore-1809
      - name: Build and Push (ltsc2016)
        if: ${{ matrix.windows.tag == 'ltsc2016' }}
        run: |
          docker build --build-arg base_tag=3-windowsservercore-ltsc2016 `
              -f ./docker/windows.Dockerfile `
              -t nao20010128nao/ytdl-patched:windowsservercore-ltsc2016 `
              -t nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-windowsservercore-ltsc2016 `
              .
          docker push nao20010128nao/ytdl-patched:windowsservercore-ltsc2016
          docker push nao20010128nao/ytdl-patched:${{ needs.prepare.outputs.latest_version_numeric }}-windowsservercore-ltsc2016


code:
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
  push:
    branches: [master, yt-dlp]
    paths:
      - yt_dlp/**
      - test/**
  workflow_dispatch:
    inputs: {}
  pull_request:
    # The branches below must be a subset of the branches above
    branches: [master, yt-dlp]
  schedule:
    - cron: '0 19 * * 6'

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # Override automatic language detection by changing the below list
        # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
        language: ['python']
        # Learn more...
        # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    # Initializes the CodeQL tools for scanning.
    - name: Initialize CodeQL
      uses: github/codeql-action/init@v1
      with:
        languages: ${{ matrix.language }}
        # If you wish to specify custom queries, you can do so here or in a config file.
        # By default, queries listed here will override any specified in a config file.
        # Prefix the list here with "+" to use these queries and those in the config file.
        # queries: ./path/to/local/query, your-org/your-repo/queries@main

    # Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
    # If this step fails, then you should remove it and run the build manually (see below)
    - name: Autobuild
      uses: github/codeql-action/autobuild@v1

    # ℹ Command-line programs to run using the OS shell.
    # 📚 https://git.io/JvXDl

    # ✏ If the Autobuild fails above, remove it and uncomment the following three lines
    #    and modify them (or add more) to build your code if your project
    #    uses a compiled language

    #- run: |
    #   make bootstrap
    #   make release

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@v1


code:
name: Deploy repository to CDNs

on:
  push:
    branches:
      - yt-dlp
  workflow_dispatch:
    inputs: {}

jobs:
  netlify:
    runs-on: ubuntu-latest
    env:
      NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
      NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
    steps:
      - uses: actions/checkout@v2
      - name: Set up Node.js 14
        uses: actions/setup-node@v1
        with:
          node-version: 14
      - name: Set up Netlify
        run: npm install netlify-cli -g
      - name: Build and deploy
        run: |
          netlify build
          netlify deploy --prod
  vercel:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Node.js 14
        uses: actions/setup-node@v1
        with:
          node-version: 14
      - uses: amondnet/vercel-action@v20
        with:
          vercel-token: ${{ secrets.VERCEL_TOKEN }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
          vercel-args: '--prod'
          vercel-org-id: ${{ secrets.ORG_ID }}
          vercel-project-id: ${{ secrets.PROJECT_ID }}
          github-comment: false


code:
name: Docker image for Codespaces

on:
  push:
    paths:
      - docker/codespaces.Dockerfile
      - .github/workflows/docker-codespaces.yml
      - .devcontainer/**
    branches:
      - yt-dlp
  workflow_dispatch:
    inputs: {}
  schedule:
    - cron: "0 4 * * 0"

jobs:
  docker-codespaces:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Login
        uses: docker/login-action@v1
        with:
          username: ${{ github.repository_owner }}
          password: ${{ secrets.DHUB_TOKEN }}
      - name: Build and Push
        run: |
          docker build -t nao20010128nao/ytdl-patched:codespaces -f ./docker/codespaces.Dockerfile .
          docker push nao20010128nao/ytdl-patched:codespaces


code:
name: Automatically regenerate files

on:
  push:
    paths:
      - .github/workflows/generate-files-automatic.yml
      - devscripts/make_mastodon_instance_list.py
      - devscripts/make_peertube_instance_list.py
      - devscripts/make_misskey_version_list.py
      - devscripts/make_chrome_version_list.py
      - devscripts/scraper_helper.py
    branches:
      - ytdlp
  schedule:
    - cron: "0 2 * * 0"
  workflow_dispatch:
    inputs: {}

jobs:
  generate:
    runs-on: ubuntu-latest
    env:
      INSTANCE_SOCIAL_API_SECRET: ${{ secrets.INSTANCE_SOCIAL_API_SECRET }}
    steps:
    - uses: actions/checkout@v2
      with:
        ref: ytdlp
        fetch-depth: 0
    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      with:
        python-version: 3.9
    - name: Configure git
      run: |
        git config --global pull.rebase false
        git config --global core.editor true
        git config --global user.name Lesmiscore
        git config --global user.email nao20010128@gmail.com
        git config --unset  http.https://github.com/.extraheader
        git remote set-url origin https://Lesmiscore:${{ secrets.GH_PAT }}@github.com/ytdl-patched/ytdl-patched.git

    - name: Generate yt_dlp/extractor/mastodon/instances.py
      run: python ./devscripts/make_mastodon_instance_list.py
      continue-on-error: true
    - name: Generate yt_dlp/extractor/peertube/instances.py
      run: python ./devscripts/make_peertube_instance_list.py
      continue-on-error: true
    - name: Generate yt_dlp/extractor/misskey/instances.py
      run: python ./devscripts/make_misskey_instance_list.py
      continue-on-error: true
    - name: Generate yt_dlp/chrome_versions.py
      run: python ./devscripts/make_chrome_version_list.py
      continue-on-error: true

    - name: Commit yt_dlp/extractor/mastodon/instances.py
      run: "git commit -m\"automatic: regenerate yt_dlp/extractor/mastodon/instances.py @ $(date +'%Y%m%d')\" yt_dlp/extractor/mastodon/instances.py"
      continue-on-error: true
    - name: Commit yt_dlp/extractor/peertube/instances.py
      run: "git commit -m\"automatic: regenerate yt_dlp/extractor/peertube/instances.py @ $(date +'%Y%m%d')\" yt_dlp/extractor/peertube/instances.py"
      continue-on-error: true
    - name: Commit yt_dlp/extractor/misskey/instances.py
      run: "git commit -m\"automatic: regenerate yt_dlp/extractor/misskey/instances.py @ $(date +'%Y%m%d')\" yt_dlp/extractor/misskey/instances.py"
      continue-on-error: true
    - name: Commit yt_dlp/chrome_versions.py
      run: "git commit -m\"automatic: regenerate yt_dlp/chrome_versions.py @ $(date +'%Y%m%d')\" yt_dlp/chrome_versions.py"
      continue-on-error: true

    - name: Push to here
      run: git push origin HEAD:ytdlp


code:
name: Push to Keybase

on:
  schedule:
    - cron: "10 */12 * * *"
  workflow_dispatch:
    inputs:

jobs:
  push:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Pull all bracnhes
      run: |
        git push --all origin
        for i in $(git branch -a | grep remote | grep -v HEAD | grep -v master); do git branch --track ${i#remotes/origin/} $i; done
      continue-on-error: true
    - name: Install Keybase
      run: |
        wget https://prerelease.keybase.io/keybase_amd64.deb -O keybase.deb
        sudo apt install -y ./keybase.deb && sudo apt install -fy
    - name: Configure git
      run: |
        git remote add keybase keybase://public/nao20010128nao/ytdl-patched
        git remote set-url --add keybase keybase://private/nao20010128nao/ytdl-patched
        git branch -d gh-pages || true
    - name: Configure Keybase
      run: |
        keybase oneshot --username nao20010128nao --paperkey "${{ secrets.KEYBASE_PAPER_KEY }}"
        kbfsfuse &
    - name: Push to Keybase
      run: |
        git push --all --force keybase
    - name: GC repository on Keybase
      continue-on-error: true
      run: keybase git gc ytdl-patched

  tags:
    needs: [push]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Pull all bracnhes
      run: |
        git push --all origin
        for i in $(git branch -a | grep remote | grep -v HEAD | grep -v master); do git branch --track ${i#remotes/origin/} $i; done
      continue-on-error: true
    - name: Install Keybase
      run: |
        wget https://prerelease.keybase.io/keybase_amd64.deb -O keybase.deb
        sudo apt install -y ./keybase.deb && sudo apt install -fy
    - name: Configure git
      run: |
        git remote add keybase keybase://public/nao20010128nao/ytdl-patched
        git remote set-url --add keybase keybase://private/nao20010128nao/ytdl-patched
        git branch -d gh-pages || true
    - name: Configure Keybase
      run: |
        keybase oneshot --username nao20010128nao --paperkey "${{ secrets.KEYBASE_PAPER_KEY }}"
        kbfsfuse &
    - name: Push to Keybase
      run: |
        git push --tags --force keybase
    - name: GC repository on Keybase
      continue-on-error: true
      run: keybase git gc ytdl-patched


code:
name: Merge upstream

on:
  schedule:
    - cron: "0 */6 * * *"
  workflow_dispatch:
    inputs:

jobs:
  merge:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: ytdlp
        fetch-depth: 0
    - name: Configure git
      run: |
        set +e -x
        git config --global pull.rebase false
        git config --global core.editor "$(realpath ./devscripts/remove_ci_skip.py)"
        git config --global user.name nao20010128nao
        git config --global user.email nao20010128@gmail.com
        git config --unset  http.https://github.com/.extraheader
        git config --unset  credential.helper
        git remote add self https://nao20010128nao:${{ secrets.GH_PAT }}@github.com/ytdl-patched/ytdl-patched.git
        git remote add upstream https://github.com/yt-dlp/yt-dlp.git
    - name: Pull from yt-dlp/yt-dlp
      run: git pull upstream master --log
    - name: Regenerate docs/supportedsites.md
      continue-on-error: true
      run: |
        python ./devscripts/make_supportedsites.py ./supportedsites.md
        git commit -m"automatic: regenerate supportedsites.md @ $(date +'%Y%m%d')" ./supportedsites.md
    - name: Push to here
      run: git push self HEAD:ytdlp
    - name: Create tag
      continue-on-error: true
      run: |
        # git push self :refs/tags/yt-dlp || true
        git tag -d yt-dlp || true
        git tag -f yt-dlp upstream/master || true
        git push self -f --tags || true


code:
name: Run tests

on:
  push:
    paths:
      - yt_dlp/**
      - test/**
      - .github/workflows/tests.yml
      - devscripts/**
    branches-ignore:
      - gh-pages
  workflow_dispatch:
    inputs: {}

jobs:
  test:
    runs-on: ubuntu-latest
    continue-on-error: ${{ matrix.ytdl_test_set.may_fail || matrix.python.may_fail }}
    strategy:
      matrix:
        python: [
          { name: '3.10', may_fail: false, major: 3, special: '' },
          { name: '3.9', may_fail: false, major: 3, special: '' },
          { name: '3.8', may_fail: false, major: 3, special: '' },
          { name: '3.7', may_fail: false, major: 3, special: '' },
          { name: 'pypy-3.7', may_fail: false, major: 3, special: '' },
        ]
        ytdl_test_set: [
          # { name: 'download', may_fail: true },
          { name: 'core', may_fail: false },
        ]
    env:
      YTDL_TEST_SET: ${{ matrix.ytdl_test_set.name }}
    steps:
      - uses: actions/checkout@v2
      # standard CPython provided by GitHub Actions
      - name: Set up Python ${{ matrix.python.name }}
        uses: actions/setup-python@v2
        if: ${{ !matrix.python.special }}
        with:
          python-version: ${{ matrix.python.name }}
      - name: Install deps
        if: ${{ !matrix.python.special }}
        run: pip install -U pip pytest streamlink
      # main script
      - name: Run test
        continue-on-error: ${{ matrix.ytdl_test_set.may_fail || matrix.python.may_fail }}
        run: ./devscripts/run_tests.sh ${{ matrix.ytdl_test_set.name }}
  flake8:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Install deps
        run: pip install -U pip flake8
      - name: Run flake8 .
        run: flake8 .


code:
name: Update description

on:
  push:
    paths:
      - docs/description.yml
    branches:
      - ytdlp
  workflow_dispatch:
    inputs:

jobs:
  task:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'
    - name: Install js-yaml module
      run: npm init -y && npm i js-yaml
    - name: Update description and homepage
      uses: actions/github-script@v4
      with:
        github-token: ${{ secrets.GH_PAT }}
        script: |
          const fs = require("fs");
          const yaml = require("js-yaml");
          const doc = yaml.load(fs.readFileSync('docs/description.yml', 'utf8'));
          // don't pass doc object as-is to prevent attacks via PRs
          const {owner, repo} = context.repo;
          if (owner !== "ytdl-patched") throw new Error(`wwner doesn't match: ${owner}`);
          if (repo  !== "ytdl-patched") throw new Error(`repo doesn't match: ${repo}`);
          if (typeof doc.description !== "string") throw new Error(`.description has wrong type: ${typeof doc.description}`);
          if (typeof doc.homepage !== "string") throw new Error(`.homepage has wrong type: ${typeof doc.homepage}`);
          github.repos.update({
            owner: "ytdl-patched",
            repo: "ytdl-patched",
            description: doc.description,
            homepage: doc.homepage,
          });


code:
# Config
*.conf
cookies
*cookies.txt
.netrc

# Downloaded
*.annotations.xml
*.aria2
*.description
*.dump
*.frag
*.frag.aria2
*.frag.urls
*.info.json
*.live_chat.json
*.meta
*.part*
*.tmp
*.temp
*.unknown_video
*.ytdl
.cache/

*.3gp
*.ape
*.ass
*.avi
*.desktop
*.f4v
*.flac
*.flv
*.jpeg
*.jpg
*.m4a
*.mpga
*.m4v
*.mhtml
*.mkv
*.mov
*.mp3
*.mp4
*.ogg
*.opus
*.png
*.sbv
*.srt
*.swf
*.swp
*.ttml
*.url
*.vtt
*.wav
*.webloc
*.webm
*.webp
*.images

# Allow config/media files in testdata
!test/**

# Python
*.pyc
*.pyo
.pytest_cache
wine-py2exe/
py2exe.log
build/
dist/
zip/
tmp/
venv/
completions/

# Misc
*~
*.DS_Store
*.kate-swp
MANIFEST
test/local_parameters.json
.coverage
cover/
secrets/
updates_key.pem
*.egg-info
.tox
*.class
*.isorted

# Generated
AUTHORS
README.txt
.mailmap
*.1
*.bash-completion
*.fish
*.tar.gz
*.zsh
*.spec
test/testdata/sigs/player-*.js
yt_dlp/build_config.py

# Binary
/youtube-dl
/youtube-dlc
/yt-dlp
yt-dlp.zip
*.exe

# Downloaded
*.srt
*.ttml
*.sbv
*.vtt
*.flv
*.mp4
*.m4a
*.m4v
*.mp3
*.3gp
*.webm
*.wav
*.ape
*.mkv
*.swf
*.part
*.part-*
*.ytdl
*.dump
*.frag
*.frag.urls
*.aria2
*.swp
*.ogg
*.opus
*.info.json
*.live_chat.json
*.jpg
*.png
*.webp
*.annotations.xml
*.description
*.lock

# Config
*.conf
*.spec
cookies
cookies.txt

# Text Editor / IDE
.idea
*.iml
.vscode
*.sublime-*
*.code-workspace

# Lazy extractors
*/extractor/lazy_extractors.py

# Plugins
ytdlp_plugins/extractor/*
!ytdlp_plugins/extractor/__init__.py
!ytdlp_plugins/extractor/sample.py
ytdlp_plugins/postprocessor/*
!ytdlp_plugins/postprocessor/__init__.py
!ytdlp_plugins/postprocessor/sample.py

# Added by GH Codespaces
pythonenv3.8/
.venv/

path: .gitignore