Skip to content

Commit

Permalink
8.3-rc4 (#308 #309 #310)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanBindez committed Nov 3, 2024
1 parent 9c34ea2 commit 4774035
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
VERSION=8
MINOR=3
PATCH=
EXTRAVERSION="-rc3"
EXTRAVERSION="-rc4"

NOTES="(#308 #309 #310)"
BRANCH="dev"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pytubefix"
version = "8.3-rc3"
version = "8.3-rc4"
authors = [
{ name="Juan Bindez", email="[email protected]" },
]
Expand Down
102 changes: 57 additions & 45 deletions pytubefix/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,74 +266,86 @@ def display_streams(youtube: YouTube) -> None:


def _parse_args(parser: argparse.ArgumentParser, args: Optional[List] = None) -> argparse.Namespace:
parser.add_argument("url", help="URL do vídeo ou playlist do YouTube", nargs="?")
parser.add_argument("url", help="The YouTube /watch or /playlist url", nargs="?")
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}")
parser.add_argument("--itag", type=int, help="Itag do stream desejado")
parser.add_argument("-r", "--resolution", type=str, help="Resolução do stream desejado")
parser.add_argument("-l", "--list", action="store_true", help="Listar streams disponíveis para download")
parser.add_argument("--oauth", action="store_true", help="Usar token OAuth")
parser.add_argument("-v", "--verbose", action="store_true", help="Ativar logs detalhados")
parser.add_argument("--logfile", help="Arquivo para logs de debug e erro")
parser.add_argument("--build-playback-report", action="store_true", help="Salvar HTML e JS no disco")
parser.add_argument("-c", "--caption-code", type=str, help="Baixar legendas no código de idioma especificado")
parser.add_argument("-lc", "--list-captions", action="store_true", help="Listar códigos de legendas disponíveis")
parser.add_argument("-t", "--target", help="Diretório de saída para o stream baixado")
parser.add_argument("-a", "--audio", const="mp4", nargs="?", help="Baixar áudio na maior qualidade disponível (padrão: mp4)")
parser.add_argument("-f", "--ffmpeg", const="best", nargs="?", help="Baixar áudio e vídeo e combiná-los")
parser.add_argument("--itag", type=int, help="The itag for the desired stream")
parser.add_argument("-r", "--resolution", type=str, help="The resolution for the desired stream")
parser.add_argument("-l", "--list", action="store_true", help="The list option causes pytubefix cli to return a list of streams available to download")
parser.add_argument("--oauth", action="store_true", help="use oauth token")
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", help="Set logger output to verbose output.")
parser.add_argument("--logfile", action="store", help="logging debug and error messages into a log file")
parser.add_argument("--build-playback-report", action="store_true", help="Save the html and js to disk")
parser.add_argument("-c", "--caption-code", type=str, help="Download srt captions for given language code. Prints available language codes if no argument given")
parser.add_argument('-lc', '--list-captions', action='store_true', help="List available caption codes for a video")
parser.add_argument("-t", "--target", help="The output directory for the downloaded stream. Default is current working directory")
parser.add_argument("-a", "--audio", const="mp4", nargs="?", help="Download the audio for a given URL at the highest bitrate available. Defaults to mp4 format if none is specified")
parser.add_argument("-f", "--ffmpeg", const="best", nargs="?", help="Downloads the audio and video stream for resolution provided. If no resolution is provided, downloads the best resolution. Runs the command line program ffmpeg to combine the audio and video")

return parser.parse_args(args)

def _perform_args_on_youtube(youtube: YouTube, args: argparse.Namespace) -> None:
if len(sys.argv) == 2:
download_highest_resolution_progressive(youtube=youtube, resolution="highest", target=args.target)
return # Exit early as no further actions are needed

if args.list_captions:
_print_available_captions(youtube.captions)
if args.list:
display_streams(youtube)

if args.itag:
download_by_itag(youtube, itag=args.itag, target=args.target)
download_by_itag(youtube=youtube, itag=args.itag, target=args.target)
elif args.caption_code:
download_caption(youtube, lang_code=args.caption_code, target=args.target)
download_caption(youtube=youtube, lang_code=args.caption_code, target=args.target)
elif args.resolution:
download_by_resolution(youtube, resolution=args.resolution, target=args.target)
download_by_resolution(youtube=youtube, resolution=args.resolution, target=args.target)
elif args.audio:
download_audio(youtube, filetype=args.audio, target=args.target)
download_audio(youtube=youtube, filetype=args.audio, target=args.target)

if args.ffmpeg:
ffmpeg_process(youtube, resolution=args.resolution, target=args.target)
ffmpeg_process(youtube=youtube, resolution=args.resolution, target=args.target)

if args.build_playback_report:
build_playback_report(youtube)

global oauth, cache

oauth = False
cache = False

if args.oauth:
oauth = True
cache = True

def main():
parser = argparse.ArgumentParser(description="Baixador de vídeos e playlists do YouTube")
parser = argparse.ArgumentParser(description=main.__doc__)
args = _parse_args(parser)

setup_logger(logging.DEBUG if args.verbose else logging.INFO, log_filename=args.logfile)
log_filename = args.logfile if args.verbose else None
setup_logger(logging.DEBUG if args.verbose else logging.INFO, log_filename=log_filename)

if args.verbose:
logging.debug(f"Versão do Pytubefix: {__version__}")
logger.debug(f'Pytubefix version: {__version__}')

if not args.url or "youtu" not in args.url:
parser.print_help()
sys.exit("Erro: URL do YouTube inválida ou ausente")

oauth, cache = args.oauth, args.oauth

try:
if "/playlist" in args.url:
print("Carregando playlist...")
playlist = Playlist(args.url, use_oauth=oauth, allow_oauth_cache=cache)
args.target = args.target or safe_filename(playlist.title)

for video in playlist.videos:
try:
_perform_args_on_youtube(video, args)
except exceptions.PytubeFixError as e:
print(f"Erro com o vídeo {video}: {e}")

else:
print("Carregando vídeo...")
youtube = YouTube(args.url, use_oauth=oauth, allow_oauth_cache=cache)
_perform_args_on_youtube(youtube, args)

except exceptions.PytubeFixError as e:
sys.exit(f"Ocorreu um erro: {e}")
sys.exit(0)

if "/playlist" in args.url:
print("Loading playlist...")
playlist = Playlist(args.url, use_oauth=oauth, allow_oauth_cache=cache)
args.target = args.target or safe_filename(playlist.title)

for youtube_video in playlist.videos:
try:
_perform_args_on_youtube(youtube_video, args)
except exceptions.PytubeFixError as e:
print(f"There was an error with video: {youtube_video}")
print(e)
else:
print("Loading video...")
youtube = YouTube(args.url, use_oauth=oauth, allow_oauth_cache=cache)
_perform_args_on_youtube(youtube, args)

if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion pytubefix/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "8.3-rc3"
__version__ = "8.3-rc4"

if __name__ == "__main__":
print(__version__)

0 comments on commit 4774035

Please sign in to comment.