Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. all: lazy-extractors yt-dlp doc pypi-files
  2. clean: clean-test clean-dist
  3. clean-all: clean clean-cache
  4. completions: completion-bash completion-fish completion-zsh
  5. doc: README.md CONTRIBUTING.md CONTRIBUTORS issuetemplates supportedsites
  6. ot: offlinetest
  7. tar: yt-dlp.tar.gz
  8. # Keep this list in sync with pyproject.toml includes/artifacts
  9. # intended use: when building a source distribution,
  10. # make pypi-files && python3 -m build -sn .
  11. pypi-files: AUTHORS Changelog.md LICENSE README.md README.txt supportedsites \
  12. completions yt-dlp.1 pyproject.toml setup.cfg devscripts/* test/*
  13. .PHONY: all clean clean-all clean-test clean-dist clean-cache \
  14. completions completion-bash completion-fish completion-zsh \
  15. doc issuetemplates supportedsites ot offlinetest codetest test \
  16. tar pypi-files lazy-extractors install uninstall
  17. clean-test:
  18. rm -rf test/testdata/sigs/player-*.js tmp/ *.annotations.xml *.aria2 *.description *.dump *.frag \
  19. *.frag.aria2 *.frag.urls *.info.json *.live_chat.json *.meta *.part* *.tmp *.temp *.unknown_video *.ytdl \
  20. *.3gp *.ape *.ass *.avi *.desktop *.f4v *.flac *.flv *.gif *.jpeg *.jpg *.lrc *.m4a *.m4v *.mhtml *.mkv *.mov *.mp3 *.mp4 \
  21. *.mpg *.mpga *.oga *.ogg *.opus *.png *.sbv *.srt *.ssa *.swf *.tt *.ttml *.url *.vtt *.wav *.webloc *.webm *.webp
  22. clean-dist:
  23. rm -rf yt-dlp.1.temp.md yt-dlp.1 README.txt MANIFEST build/ dist/ .coverage cover/ yt-dlp.tar.gz completions/ \
  24. yt_dlp/extractor/lazy_extractors.py *.spec CONTRIBUTING.md.tmp yt-dlp yt-dlp.exe yt_dlp.egg-info/ AUTHORS
  25. clean-cache:
  26. find . \( \
  27. -type d -name ".*_cache" -o -type d -name __pycache__ -o -name "*.pyc" -o -name "*.class" \
  28. \) -prune -exec rm -rf {} \;
  29. completion-bash: completions/bash/yt-dlp
  30. completion-fish: completions/fish/yt-dlp.fish
  31. completion-zsh: completions/zsh/_yt-dlp
  32. lazy-extractors: yt_dlp/extractor/lazy_extractors.py
  33. PREFIX ?= /usr/local
  34. BINDIR ?= $(PREFIX)/bin
  35. MANDIR ?= $(PREFIX)/man
  36. SHAREDIR ?= $(PREFIX)/share
  37. PYTHON ?= /usr/bin/env python3
  38. GNUTAR ?= tar
  39. # set markdown input format to "markdown-smart" for pandoc version 2+ and to "markdown" for pandoc prior to version 2
  40. PANDOC_VERSION_CMD = pandoc -v 2>/dev/null | head -n1 | cut -d' ' -f2 | head -c1
  41. PANDOC_VERSION != $(PANDOC_VERSION_CMD)
  42. PANDOC_VERSION ?= $(shell $(PANDOC_VERSION_CMD))
  43. MARKDOWN_CMD = if [ "$(PANDOC_VERSION)" = "1" -o "$(PANDOC_VERSION)" = "0" ]; then echo markdown; else echo markdown-smart; fi
  44. MARKDOWN != $(MARKDOWN_CMD)
  45. MARKDOWN ?= $(shell $(MARKDOWN_CMD))
  46. install: lazy-extractors yt-dlp yt-dlp.1 completions
  47. mkdir -p $(DESTDIR)$(BINDIR)
  48. install -m755 yt-dlp $(DESTDIR)$(BINDIR)/yt-dlp
  49. mkdir -p $(DESTDIR)$(MANDIR)/man1
  50. install -m644 yt-dlp.1 $(DESTDIR)$(MANDIR)/man1/yt-dlp.1
  51. mkdir -p $(DESTDIR)$(SHAREDIR)/bash-completion/completions
  52. install -m644 completions/bash/yt-dlp $(DESTDIR)$(SHAREDIR)/bash-completion/completions/yt-dlp
  53. mkdir -p $(DESTDIR)$(SHAREDIR)/zsh/site-functions
  54. install -m644 completions/zsh/_yt-dlp $(DESTDIR)$(SHAREDIR)/zsh/site-functions/_yt-dlp
  55. mkdir -p $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d
  56. install -m644 completions/fish/yt-dlp.fish $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d/yt-dlp.fish
  57. uninstall:
  58. rm -f $(DESTDIR)$(BINDIR)/yt-dlp
  59. rm -f $(DESTDIR)$(MANDIR)/man1/yt-dlp.1
  60. rm -f $(DESTDIR)$(SHAREDIR)/bash-completion/completions/yt-dlp
  61. rm -f $(DESTDIR)$(SHAREDIR)/zsh/site-functions/_yt-dlp
  62. rm -f $(DESTDIR)$(SHAREDIR)/fish/vendor_completions.d/yt-dlp.fish
  63. codetest:
  64. ruff check .
  65. autopep8 --diff .
  66. test:
  67. $(PYTHON) -m pytest -Werror
  68. $(MAKE) codetest
  69. offlinetest: codetest
  70. $(PYTHON) -m pytest -Werror -m "not download"
  71. CODE_FOLDERS_CMD = find yt_dlp -type f -name '__init__.py' | sed 's,/__init__.py,,' | grep -v '/__' | sort
  72. CODE_FOLDERS != $(CODE_FOLDERS_CMD)
  73. CODE_FOLDERS ?= $(shell $(CODE_FOLDERS_CMD))
  74. CODE_FILES_CMD = for f in $(CODE_FOLDERS) ; do echo "$$f" | sed 's,$$,/*.py,' ; done
  75. CODE_FILES != $(CODE_FILES_CMD)
  76. CODE_FILES ?= $(shell $(CODE_FILES_CMD))
  77. yt-dlp: $(CODE_FILES)
  78. mkdir -p zip
  79. for d in $(CODE_FOLDERS) ; do \
  80. mkdir -p zip/$$d ;\
  81. cp -pPR $$d/*.py zip/$$d/ ;\
  82. done
  83. (cd zip && touch -t 200001010101 $(CODE_FILES))
  84. mv zip/yt_dlp/__main__.py zip/
  85. (cd zip && zip -q ../yt-dlp $(CODE_FILES) __main__.py)
  86. rm -rf zip
  87. echo '#!$(PYTHON)' > yt-dlp
  88. cat yt-dlp.zip >> yt-dlp
  89. rm yt-dlp.zip
  90. chmod a+x yt-dlp
  91. README.md: $(CODE_FILES) devscripts/make_readme.py
  92. COLUMNS=80 $(PYTHON) yt_dlp/__main__.py --ignore-config --help | $(PYTHON) devscripts/make_readme.py
  93. CONTRIBUTING.md: README.md devscripts/make_contributing.py
  94. $(PYTHON) devscripts/make_contributing.py README.md CONTRIBUTING.md
  95. issuetemplates: devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/1_broken_site.yml .github/ISSUE_TEMPLATE_tmpl/2_site_support_request.yml .github/ISSUE_TEMPLATE_tmpl/3_site_feature_request.yml .github/ISSUE_TEMPLATE_tmpl/4_bug_report.yml .github/ISSUE_TEMPLATE_tmpl/5_feature_request.yml yt_dlp/version.py
  96. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/1_broken_site.yml .github/ISSUE_TEMPLATE/1_broken_site.yml
  97. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/2_site_support_request.yml .github/ISSUE_TEMPLATE/2_site_support_request.yml
  98. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/3_site_feature_request.yml .github/ISSUE_TEMPLATE/3_site_feature_request.yml
  99. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/4_bug_report.yml .github/ISSUE_TEMPLATE/4_bug_report.yml
  100. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/5_feature_request.yml .github/ISSUE_TEMPLATE/5_feature_request.yml
  101. $(PYTHON) devscripts/make_issue_template.py .github/ISSUE_TEMPLATE_tmpl/6_question.yml .github/ISSUE_TEMPLATE/6_question.yml
  102. supportedsites:
  103. $(PYTHON) devscripts/make_supportedsites.py supportedsites.md
  104. README.txt: README.md
  105. pandoc -f $(MARKDOWN) -t plain README.md -o README.txt
  106. yt-dlp.1: README.md devscripts/prepare_manpage.py
  107. $(PYTHON) devscripts/prepare_manpage.py yt-dlp.1.temp.md
  108. pandoc -s -f $(MARKDOWN) -t man yt-dlp.1.temp.md -o yt-dlp.1
  109. rm -f yt-dlp.1.temp.md
  110. completions/bash/yt-dlp: $(CODE_FILES) devscripts/bash-completion.in
  111. mkdir -p completions/bash
  112. $(PYTHON) devscripts/bash-completion.py
  113. completions/zsh/_yt-dlp: $(CODE_FILES) devscripts/zsh-completion.in
  114. mkdir -p completions/zsh
  115. $(PYTHON) devscripts/zsh-completion.py
  116. completions/fish/yt-dlp.fish: $(CODE_FILES) devscripts/fish-completion.in
  117. mkdir -p completions/fish
  118. $(PYTHON) devscripts/fish-completion.py
  119. _EXTRACTOR_FILES_CMD = find yt_dlp/extractor -name '*.py' -and -not -name 'lazy_extractors.py'
  120. _EXTRACTOR_FILES != $(_EXTRACTOR_FILES_CMD)
  121. _EXTRACTOR_FILES ?= $(shell $(_EXTRACTOR_FILES_CMD))
  122. yt_dlp/extractor/lazy_extractors.py: devscripts/make_lazy_extractors.py devscripts/lazy_load_template.py $(_EXTRACTOR_FILES)
  123. $(PYTHON) devscripts/make_lazy_extractors.py $@
  124. yt-dlp.tar.gz: all
  125. @$(GNUTAR) -czf yt-dlp.tar.gz --transform "s|^|yt-dlp/|" --owner 0 --group 0 \
  126. --exclude '*.DS_Store' \
  127. --exclude '*.kate-swp' \
  128. --exclude '*.pyc' \
  129. --exclude '*.pyo' \
  130. --exclude '*~' \
  131. --exclude '__pycache__' \
  132. --exclude '.*_cache' \
  133. --exclude '.git' \
  134. -- \
  135. README.md supportedsites.md Changelog.md LICENSE \
  136. CONTRIBUTING.md Collaborators.md CONTRIBUTORS AUTHORS \
  137. Makefile yt-dlp.1 README.txt completions .gitignore \
  138. setup.cfg yt-dlp yt_dlp pyproject.toml devscripts test
  139. AUTHORS: Changelog.md
  140. @if [ -d '.git' ] && command -v git > /dev/null ; then \
  141. echo 'Generating $@ from git commit history' ; \
  142. git shortlog -s -n HEAD | cut -f2 | sort > $@ ; \
  143. fi
  144. CONTRIBUTORS: Changelog.md
  145. @if [ -d '.git' ] && command -v git > /dev/null ; then \
  146. echo 'Updating $@ from git commit history' ; \
  147. $(PYTHON) devscripts/make_changelog.py -v -c > /dev/null ; \
  148. fi