fix(iP): Fix missing version data
Some episodes return nothing from the API. In those cases, the episode id will be fetched from the page source code.
This commit is contained in:
		
							parent
							
								
									ffbcf011e0
								
							
						
					
					
						commit
						7bffda758f
					
				@ -126,13 +126,24 @@ class iP(Service):
 | 
			
		||||
        
 | 
			
		||||
    def get_tracks(self, title: Union[Movie, Episode]) -> Tracks:
 | 
			
		||||
        r = self.session.get(url=self.config["endpoints"]["playlist"].format(pid=title.id))
 | 
			
		||||
        r.raise_for_status()
 | 
			
		||||
        if not r.ok:
 | 
			
		||||
            self.log.error(r.text)
 | 
			
		||||
            sys.exit(1)
 | 
			
		||||
 | 
			
		||||
        versions = r.json().get("allAvailableVersions")
 | 
			
		||||
        if not versions:
 | 
			
		||||
            r = self.session.get(self.config["base_url"].format(type="episode", pid=title.id))
 | 
			
		||||
            redux = re.search("window.__IPLAYER_REDUX_STATE__ = (.*?);</script>", r.text).group(1)
 | 
			
		||||
            data = json.loads(redux)
 | 
			
		||||
            versions = [
 | 
			
		||||
                {"pid": x.get("id") for x in data["versions"] if not x.get("kind") == "audio-described"} 
 | 
			
		||||
            ]
 | 
			
		||||
        
 | 
			
		||||
        quality = [
 | 
			
		||||
            connection.get("height")
 | 
			
		||||
            for i in (
 | 
			
		||||
                self.check_all_versions(version)
 | 
			
		||||
                for version in (x.get("pid") for x in r.json()["allAvailableVersions"])
 | 
			
		||||
                for version in (x.get("pid") for x in versions)
 | 
			
		||||
            )
 | 
			
		||||
            for connection in i
 | 
			
		||||
            if connection.get("height")
 | 
			
		||||
@ -140,7 +151,7 @@ class iP(Service):
 | 
			
		||||
        max_quality = max((h for h in quality if h < "1080"), default=None)
 | 
			
		||||
 | 
			
		||||
        media = next((i for i in (self.check_all_versions(version)
 | 
			
		||||
                    for version in (x.get("pid") for x in r.json()["allAvailableVersions"]))
 | 
			
		||||
                    for version in (x.get("pid") for x in versions))
 | 
			
		||||
                    if any(connection.get("height") == max_quality for connection in i)), None)
 | 
			
		||||
        
 | 
			
		||||
        connection = {}
 | 
			
		||||
@ -296,6 +307,7 @@ class iP(Service):
 | 
			
		||||
            number=ep_num,
 | 
			
		||||
            name=ep_name,
 | 
			
		||||
            language="en",
 | 
			
		||||
            data=episode,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def get_single_episode(self, url: str) -> Series:
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,4 @@
 | 
			
		||||
base_url: https://www.bbc.co.uk/iplayer/{type}/{pid}
 | 
			
		||||
user_agent: 'smarttv_AFTMM_Build_0003255372676_Chromium_41.0.2250.2'
 | 
			
		||||
api_key: 'D2FgtcTxGqqIgLsfBWTJdrQh2tVdeaAp'
 | 
			
		||||
 | 
			
		||||
@ -7,3 +8,4 @@ endpoints:
 | 
			
		||||
  manifest: "https://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/{mediaset}/vpid/{vpid}/"
 | 
			
		||||
  manifest_: 'https://securegate.iplayer.bbc.co.uk/mediaselector/6/select/version/2.0/vpid/{vpid}/format/json/mediaset/{mediaset}/proto/https'
 | 
			
		||||
  search: "https://search.api.bbci.co.uk/formula/iplayer-ibl-root"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user