setup.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/env python3
  2. # Allow execution from anywhere
  3. import os
  4. import sys
  5. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  6. import subprocess
  7. import warnings
  8. try:
  9. from setuptools import Command, find_packages, setup
  10. setuptools_available = True
  11. except ImportError:
  12. from distutils.core import Command, setup
  13. setuptools_available = False
  14. from devscripts.utils import read_file, read_version
  15. VERSION = read_version()
  16. DESCRIPTION = 'A youtube-dl fork with additional features and patches'
  17. LONG_DESCRIPTION = '\n\n'.join((
  18. 'Official repository: <https://github.com/yt-dlp/yt-dlp>',
  19. '**PS**: Some links in this document will not work since this is a copy of the README.md from Github',
  20. read_file('README.md')))
  21. REQUIREMENTS = read_file('requirements.txt').splitlines()
  22. def packages():
  23. if setuptools_available:
  24. return find_packages(exclude=('youtube_dl', 'youtube_dlc', 'test', 'ytdlp_plugins', 'devscripts'))
  25. return [
  26. 'yt_dlp', 'yt_dlp.extractor', 'yt_dlp.downloader', 'yt_dlp.postprocessor', 'yt_dlp.compat',
  27. ]
  28. def py2exe_params():
  29. warnings.warn(
  30. 'py2exe builds do not support pycryptodomex and needs VC++14 to run. '
  31. 'It is recommended to run "pyinst.py" to build using pyinstaller instead')
  32. return {
  33. 'console': [{
  34. 'script': './yt_dlp/__main__.py',
  35. 'dest_base': 'yt-dlp',
  36. 'icon_resources': [(1, 'devscripts/logo.ico')],
  37. }],
  38. 'version_info': {
  39. 'version': VERSION,
  40. 'description': DESCRIPTION,
  41. 'comments': LONG_DESCRIPTION.split('\n')[0],
  42. 'product_name': 'yt-dlp',
  43. 'product_version': VERSION,
  44. },
  45. 'options': {
  46. 'bundle_files': 0,
  47. 'compressed': 1,
  48. 'optimize': 2,
  49. 'dist_dir': './dist',
  50. 'excludes': ['Crypto', 'Cryptodome'], # py2exe cannot import Crypto
  51. 'dll_excludes': ['w9xpopen.exe', 'crypt32.dll'],
  52. # Modules that are only imported dynamically must be added here
  53. 'includes': ['yt_dlp.compat._legacy', 'yt_dlp.compat._deprecated',
  54. 'yt_dlp.utils._legacy', 'yt_dlp.utils._deprecated'],
  55. },
  56. 'zipfile': None,
  57. }
  58. def build_params():
  59. files_spec = [
  60. ('share/bash-completion/completions', ['completions/bash/yt-dlp']),
  61. ('share/zsh/site-functions', ['completions/zsh/_yt-dlp']),
  62. ('share/fish/vendor_completions.d', ['completions/fish/yt-dlp.fish']),
  63. ('share/doc/yt_dlp', ['README.txt']),
  64. ('share/man/man1', ['yt-dlp.1'])
  65. ]
  66. data_files = []
  67. for dirname, files in files_spec:
  68. resfiles = []
  69. for fn in files:
  70. if not os.path.exists(fn):
  71. warnings.warn(f'Skipping file {fn} since it is not present. Try running " make pypi-files " first')
  72. else:
  73. resfiles.append(fn)
  74. data_files.append((dirname, resfiles))
  75. params = {'data_files': data_files}
  76. if setuptools_available:
  77. params['entry_points'] = {
  78. 'console_scripts': ['yt-dlp = yt_dlp:main'],
  79. 'pyinstaller40': ['hook-dirs = yt_dlp.__pyinstaller:get_hook_dirs'],
  80. }
  81. else:
  82. params['scripts'] = ['yt-dlp']
  83. return params
  84. class build_lazy_extractors(Command):
  85. description = 'Build the extractor lazy loading module'
  86. user_options = []
  87. def initialize_options(self):
  88. pass
  89. def finalize_options(self):
  90. pass
  91. def run(self):
  92. if self.dry_run:
  93. print('Skipping build of lazy extractors in dry run mode')
  94. return
  95. subprocess.run([sys.executable, 'devscripts/make_lazy_extractors.py'])
  96. def main():
  97. if sys.argv[1:2] == ['py2exe']:
  98. params = py2exe_params()
  99. try:
  100. from py2exe import freeze
  101. except ImportError:
  102. import py2exe # noqa: F401
  103. warnings.warn('You are using an outdated version of py2exe. Support for this version will be removed in the future')
  104. params['console'][0].update(params.pop('version_info'))
  105. params['options'] = {'py2exe': params.pop('options')}
  106. else:
  107. return freeze(**params)
  108. else:
  109. params = build_params()
  110. setup(
  111. name='yt-dlp',
  112. version=VERSION,
  113. maintainer='pukkandan',
  114. maintainer_email='pukkandan.ytdlp@gmail.com',
  115. description=DESCRIPTION,
  116. long_description=LONG_DESCRIPTION,
  117. long_description_content_type='text/markdown',
  118. url='https://github.com/yt-dlp/yt-dlp',
  119. packages=packages(),
  120. install_requires=REQUIREMENTS,
  121. python_requires='>=3.7',
  122. project_urls={
  123. 'Documentation': 'https://github.com/yt-dlp/yt-dlp#readme',
  124. 'Source': 'https://github.com/yt-dlp/yt-dlp',
  125. 'Tracker': 'https://github.com/yt-dlp/yt-dlp/issues',
  126. 'Funding': 'https://github.com/yt-dlp/yt-dlp/blob/master/Collaborators.md#collaborators',
  127. },
  128. classifiers=[
  129. 'Topic :: Multimedia :: Video',
  130. 'Development Status :: 5 - Production/Stable',
  131. 'Environment :: Console',
  132. 'Programming Language :: Python',
  133. 'Programming Language :: Python :: 3.7',
  134. 'Programming Language :: Python :: 3.8',
  135. 'Programming Language :: Python :: 3.9',
  136. 'Programming Language :: Python :: 3.10',
  137. 'Programming Language :: Python :: 3.11',
  138. 'Programming Language :: Python :: Implementation',
  139. 'Programming Language :: Python :: Implementation :: CPython',
  140. 'Programming Language :: Python :: Implementation :: PyPy',
  141. 'License :: Public Domain',
  142. 'Operating System :: OS Independent',
  143. ],
  144. cmdclass={'build_lazy_extractors': build_lazy_extractors},
  145. **params
  146. )
  147. main()