setup.py 5.2 KB

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