Esempio n. 1
0
 def fill_table(self):
     self.itag_list = self.yt.get_itag_list()
     self.itag_list.sort()
     print(self.itag_list, "before")
     for x in self.itag_list:
         try:
             urllib.request.urlopen(self.yt.streams.get_by_itag(x).url)
             # pytube for sometimes gives streams that dont exist, this doesn't allow them through
         except:
             # self.itag_list.remove(x) - for some reason this doesnt work
             print(x, "FAILED!")
             continue
         else:
             if (not (self.yt.streams.get_by_itag(x).parse_codecs()[0] and
                      self.yt.streams.get_by_itag(x).parse_codecs()[0][0:4]
                      == "av01")):
                 # gets rid of av01 codec bc it sucks
                 print(x, "continuing")
                 if not (itags.get_format_profile(x)['file_type'] == "webm"
                         and self.webm == True):
                     #currently not able to change metadata of webm files, so this gets rid of them
                     self.items.append(
                         Item(
                             x,
                             itags.get_format_profile(x)['resolution'],
                             itags.get_format_profile(x)['abr'],
                             itags.get_format_profile(x)['file_type'],
                             str(
                                 self.yt.streams.get_by_itag(
                                     x).filesize_approx / 1000000) +
                             " MB"  # sizes are NOT accurate, only estimates
                         ))
     print(self.itag_list, "after")
Esempio n. 2
0
    def __init__(self, stream: Dict, player_config_args: Dict, monostate: Monostate):
        """Construct a :class:`Stream <Stream>`.

        :param dict stream:
            The unscrambled data extracted from YouTube.
        :param dict player_config_args:
            The data object containing video media data like title and
            keywords.
        :param dict monostate:
            Dictionary of data shared across all instances of
            :class:`Stream <Stream>`.
        """
        # A dictionary shared between all instances of :class:`Stream <Stream>`
        # (Borg pattern).
        self._monostate = monostate

        self.url = stream["url"]  # signed download url
        self.itag = int(stream["itag"])  # stream format id (youtube nomenclature)
        self.type = stream[
            "type"
        ]  # the part of the mime before the slash, overwritten later

        self.abr = None  # average bitrate (audio streams only)
        self.fps = None  # frames per second (video streams only)
        self.res = None  # resolution (e.g.: 480p, 720p, 1080p)

        self._filesize: Optional[int] = None  # filesize in bytes
        self.mime_type = None  # content identifier (e.g.: video/mp4)
        self.subtype = None  # the part of the mime after the slash

        self.codecs: List[str] = []  # audio/video encoders (e.g.: vp8, mp4a)
        self.audio_codec = None  # audio codec of the stream (e.g.: vorbis)
        self.video_codec = None  # video codec of the stream (e.g.: vp8)

        # Iterates over the key/values of stream and sets them as class
        # attributes. This is an anti-pattern and should be removed.
        self.set_attributes_from_dict(stream)

        # Additional information about the stream format, such as resolution,
        # frame rate, and whether the stream is live (HLS) or 3D.
        self.fmt_profile: Dict = get_format_profile(self.itag)

        # Same as above, except for the format profile attributes.
        self.set_attributes_from_dict(self.fmt_profile)

        # The player configuration which contains information like the video
        # title.
        # TODO(nficano): this should be moved to the monostate.
        self.player_config_args = player_config_args

        # 'video/webm; codecs="vp8, vorbis"' -> 'video/webm', ['vp8', 'vorbis']
        self.mime_type, self.codecs = extract.mime_type_codec(self.type)

        # 'video/webm' -> 'video', 'webm'
        self.type, self.subtype = self.mime_type.split("/")

        # ['vp8', 'vorbis'] -> video_codec: vp8, audio_codec: vorbis. DASH
        # streams return NoneType for audio/video depending.
        self.video_codec, self.audio_codec = self.parse_codecs()
Esempio n. 3
0
    def __init__(
        self, stream: Dict, player_config_args: Dict, monostate: Monostate
    ):
        """Construct a :class:`Stream <Stream>`.

        :param dict stream:
            The unscrambled data extracted from YouTube.
        :param dict player_config_args:
            The data object containing video media data like title and
            keywords.
        :param dict monostate:
            Dictionary of data shared across all instances of
            :class:`Stream <Stream>`.
        """
        # A dictionary shared between all instances of :class:`Stream <Stream>`
        # (Borg pattern).
        self._monostate = monostate

        self.url = stream["url"]  # signed download url
        self.itag = int(
            stream["itag"]
        )  # stream format id (youtube nomenclature)

        # set type and codec info

        # 'video/webm; codecs="vp8, vorbis"' -> 'video/webm', ['vp8', 'vorbis']
        self.mime_type, self.codecs = extract.mime_type_codec(stream["type"])

        # 'video/webm' -> 'video', 'webm'
        self.type, self.subtype = self.mime_type.split("/")

        # ['vp8', 'vorbis'] -> video_codec: vp8, audio_codec: vorbis. DASH
        # streams return NoneType for audio/video depending.
        self.video_codec, self.audio_codec = self.parse_codecs()

        self.is_otf: bool = stream["is_otf"]
        self.bitrate: Optional[int] = stream["bitrate"]

        self._filesize: Optional[int] = None  # filesize in bytes

        # Additional information about the stream format, such as resolution,
        # frame rate, and whether the stream is live (HLS) or 3D.
        itag_profile = get_format_profile(self.itag)
        self.is_dash = itag_profile["is_dash"]
        self.abr = itag_profile["abr"]  # average bitrate (audio streams only)
        self.fps = stream[
            "fps"
        ]  # frames per second (video streams only)
        self.resolution = itag_profile[
            "resolution"
        ]  # resolution (e.g.: "480p")
        self.is_3d = itag_profile["is_3d"]
        self.is_hdr = itag_profile["is_hdr"]
        self.is_live = itag_profile["is_live"]

        # The player configuration, contains info like the video title.
        self.player_config_args = player_config_args
Esempio n. 4
0
    def __init__(self, stream, player_config_args, monostate):
        """Construct a :class:`Stream <Stream>`.

        :param dict stream:
            The unscrambled data extracted from YouTube.
        :param dict player_config_args:
            The data object containing video media data like title and
            keywords.
        :param dict monostate:
            Dictionary of data shared across all instances of
            :class:`Stream <Stream>`.
        """
        # A dictionary shared between all instances of :class:`Stream <Stream>`
        # (Borg pattern).
        self._monostate = monostate

        self.abr = None   # average bitrate (audio streams only)
        self.fps = None   # frames per second (video streams only)
        self.itag = None  # stream format id (youtube nomenclature)
        self.res = None   # resolution (e.g.: 480p, 720p, 1080p)
        self.url = None   # signed download url

        self.mime_type = None  # content identifier (e.g.: video/mp4)
        self.type = None       # the part of the mime before the slash
        self.subtype = None    # the part of the mime after the slash

        self.codecs = []         # audio/video encoders (e.g.: vp8, mp4a)
        self.audio_codec = None  # audio codec of the stream (e.g.: vorbis)
        self.video_codec = None  # video codec of the stream (e.g.: vp8)

        # Iterates over the key/values of stream and sets them as class
        # attributes. This is an anti-pattern and should be removed.
        self.set_attributes_from_dict(stream)

        # Additional information about the stream format, such as resolution,
        # frame rate, and whether the stream is live (HLS) or 3D.
        self.fmt_profile = get_format_profile(self.itag)

        # Same as above, except for the format profile attributes.
        self.set_attributes_from_dict(self.fmt_profile)

        # The player configuration which contains information like the video
        # title.
        # TODO(nficano): this should be moved to the monostate.
        self.player_config_args = player_config_args

        # 'video/webm; codecs="vp8, vorbis"' -> 'video/webm', ['vp8', 'vorbis']
        self.mime_type, self.codecs = extract.mime_type_codec(self.type)

        # 'video/webm' -> 'video', 'webm'
        self.type, self.subtype = self.mime_type.split('/')

        # ['vp8', 'vorbis'] -> video_codec: vp8, audio_codec: vorbis. DASH
        # streams return NoneType for audio/video depending.
        self.video_codec, self.audio_codec = self.parse_codecs()
Esempio n. 5
0
 def fill_table(self):
     self.itag_list = self.yt.get_itag_list()
     self.itag_list.sort()
     print(self.itag_list, "before")
     for x in self.itag_list:
         print(x, "index")
         try:
             urllib.request.urlopen(self.yt.streams.get_by_itag(x).url)
             # pytube for sometimes gives streams that dont exist, this doesn't allow them through
         except:
             # self.itag_list.remove(x) - for some reason this doesnt work
             print(x, "FAILED!")
             continue
         else:
             print(x,"continuing")
             self.items.append(
                 Item(
                     x,
                     itags.get_format_profile(x)['resolution'],
                     itags.get_format_profile(x)['abr'],
                     str(self.yt.streams.get_by_itag(x).filesize_approx/1000000) + " MB" # sizes are NOT accurate, only estimates
                 )
             )
     print(self.itag_list, "after")
Esempio n. 6
0
def test_get_format_profile_non_existant():
    profile = itags.get_format_profile(2239)
    assert profile["resolution"] is None
Esempio n. 7
0
def test_get_format_profile():
    profile = itags.get_format_profile(22)
    assert profile["resolution"] == "720p"
Esempio n. 8
0
def test_get_format_profile_non_existant():
    profile = itags.get_format_profile(2239)
    assert profile['resolution'] is None
Esempio n. 9
0
def test_get_format_profile():
    profile = itags.get_format_profile(22)
    assert profile['resolution'] == '720p'