Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CODE REFACTO] Create a status enum for code clarity #1859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pytube/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def check_availability(self):
status, messages = extract.playability_status(self.watch_html)

for reason in messages:
if status == 'UNPLAYABLE':
if status == extract.Status.UNPLAYABLE:
if reason == (
'Join this channel to get access to members-only content '
'like this video, and other exclusive perks.'
Expand All @@ -220,16 +220,16 @@ def check_availability(self):
raise exceptions.RecordingUnavailable(video_id=self.video_id)
else:
raise exceptions.VideoUnavailable(video_id=self.video_id)
elif status == 'LOGIN_REQUIRED':
elif status == extract.Status.LOGIN_REQUIRED:
if reason == (
'This is a private video. '
'Please sign in to verify that you may see it.'
):
raise exceptions.VideoPrivate(video_id=self.video_id)
elif status == 'ERROR':
elif status == extract.Status.ERROR:
if reason == 'Video unavailable':
raise exceptions.VideoUnavailable(video_id=self.video_id)
elif status == 'LIVE_STREAM':
elif status == extract.Status.LIVE_STREAM:
raise exceptions.LiveStreamError(video_id=self.video_id)

@property
Expand Down
7 changes: 7 additions & 0 deletions pytube/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple
from urllib.parse import parse_qs, quote, urlencode, urlparse
from enum import Enum

from pytube.cipher import Cipher
from pytube.exceptions import HTMLParseError, LiveStreamError, RegexMatchError
Expand All @@ -16,6 +17,12 @@

logger = logging.getLogger(__name__)

class Status(Enum):
"""Status enum class"""
UNPLAYABLE = 'UNPLAYABLE'
LOGIN_REQUIRED = 'LOGIN_REQUIRED'
ERROR = 'ERROR'
LIVE_STREAM = 'LIVE_STREAM'

def publish_date(watch_html: str):
"""Extract publish date
Expand Down