mirror of
				https://github.com/devine-dl/devine.git
				synced 2025-11-04 03:44:49 +00:00 
			
		
		
		
	refactor(Track): Rename extra to data, enforce type as dict
Setting data as a dictionary allows more places of code (including DASH, HLS, Services, etc) to get/set what they want by key instead of typically by index (list/tuple). Tuples or lists were typically in services because DASH and HLS stored needed data as a tuple and services did not want to interrupt or remove that data, even though it would be fine.
This commit is contained in:
		
							parent
							
								
									a6a5699577
								
							
						
					
					
						commit
						90c544966a
					
				@ -207,7 +207,12 @@ class DASH:
 | 
			
		||||
                        language=track_lang,
 | 
			
		||||
                        is_original_lang=language and is_close_match(track_lang, [language]),
 | 
			
		||||
                        descriptor=Video.Descriptor.DASH,
 | 
			
		||||
                        extra=(rep, adaptation_set),
 | 
			
		||||
                        data={
 | 
			
		||||
                            "dash": {
 | 
			
		||||
                                "representation": rep,
 | 
			
		||||
                                "adaptation_set": adaptation_set
 | 
			
		||||
                            }
 | 
			
		||||
                        },
 | 
			
		||||
                        **track_args
 | 
			
		||||
                    ))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -116,7 +116,11 @@ class HLS:
 | 
			
		||||
                bitrate=playlist.stream_info.average_bandwidth or playlist.stream_info.bandwidth,
 | 
			
		||||
                descriptor=Video.Descriptor.HLS,
 | 
			
		||||
                drm=session_drm,
 | 
			
		||||
                extra=playlist,
 | 
			
		||||
                data={
 | 
			
		||||
                    "hls": {
 | 
			
		||||
                        "playlist": playlist
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                # video track args
 | 
			
		||||
                **(dict(
 | 
			
		||||
                    range_=Video.Range.DV if any(
 | 
			
		||||
@ -166,7 +170,11 @@ class HLS:
 | 
			
		||||
                is_original_lang=language and is_close_match(track_lang, [language]),
 | 
			
		||||
                descriptor=Audio.Descriptor.HLS,
 | 
			
		||||
                drm=session_drm if media.type == "AUDIO" else None,
 | 
			
		||||
                extra=media,
 | 
			
		||||
                data={
 | 
			
		||||
                    "hls": {
 | 
			
		||||
                        "media": media
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                # audio track args
 | 
			
		||||
                **(dict(
 | 
			
		||||
                    bitrate=0,  # TODO: M3U doesn't seem to state bitrate?
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ class Track:
 | 
			
		||||
        name: Optional[str] = None,
 | 
			
		||||
        drm: Optional[Iterable[DRM_T]] = None,
 | 
			
		||||
        edition: Optional[str] = None,
 | 
			
		||||
        extra: Optional[Any] = None,
 | 
			
		||||
        data: Optional[dict] = None,
 | 
			
		||||
        id_: Optional[str] = None,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        if not isinstance(url, (str, list)):
 | 
			
		||||
@ -54,6 +54,8 @@ class Track:
 | 
			
		||||
            raise TypeError(f"Expected id_ to be a {str}, not {type(id_)}")
 | 
			
		||||
        if not isinstance(edition, (str, type(None))):
 | 
			
		||||
            raise TypeError(f"Expected edition to be a {str}, not {type(edition)}")
 | 
			
		||||
        if not isinstance(data, (dict, type(None))):
 | 
			
		||||
            raise TypeError(f"Expected data to be a {dict}, not {type(data)}")
 | 
			
		||||
 | 
			
		||||
        invalid_urls = ", ".join(set(type(x) for x in url if not isinstance(x, str)))
 | 
			
		||||
        if invalid_urls:
 | 
			
		||||
@ -74,7 +76,7 @@ class Track:
 | 
			
		||||
        self.name = name
 | 
			
		||||
        self.drm = drm
 | 
			
		||||
        self.edition: str = edition
 | 
			
		||||
        self.extra: Any = extra or {}  # allow anything for extra, but default to a dict
 | 
			
		||||
        self.data = data or {}
 | 
			
		||||
 | 
			
		||||
        if not id_:
 | 
			
		||||
            this = copy(self)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user