stigger / trakt-for-appletv

Trakt.tv scrobbler for Apple TV
49 stars 7 forks source link

Docker file fails to build functional dockerfile #8

Closed CelticWebSolutions closed 4 years ago

CelticWebSolutions commented 4 years ago

I've built from your docker file but this results in a docker image that fails to run, looking at the log, it says can't find tvremote.py. So I changed this to tvscrobbler.py, this unfortunately still causes a restart loop as out keeps getting errors once run. Is anybody else able to build a working image from the docker file please?

I'm running on a Synology NAS.

Any help greatly appreciated.

stigger commented 4 years ago

still causes a restart loop as out keeps getting errors once run

Please post the errors here.

CelticWebSolutions commented 4 years ago

I build the image with the command sudo docker build -t stigger/trakt-for-appletv .

Output of build can be seen here [https://pastebin.com/kRHdnJ76] This creates an image that is called stigger/trakt-for-appletv

The I run the image which gives errors, the initial error was

python3: can't open file 'tvremote.py': [Errno 2] No such file or directory

So I changed the docker file to run tvscrobbler.py as per the GitHub instructions in the readme.

rebuild the image from the new docker file and I then get the error (screenshot) Screenshot 2020-03-09 at 11 01 35

PermissionError: [Errno 13] Permission denied: 'data/config.yml'` Looks like there may be a permissions error but I can't work out how to fix it.

CelticWebSolutions commented 4 years ago

I'm also not sure where it would be asking for me to login when it's running in a docker container on my Synology. When I couldn't get it to run on docker on my Synology, I tried to run it on my Mac but just running the scripts there failed too. different error I'll pop that in another issue report for you.

CelticWebSolutions commented 4 years ago

Were you able to replicate this error? I just can’t get the docket container to run :( myself and so many other have been hunting for exactly this for some time so I’m keen to find what’s causing it to fail.

stigger commented 4 years ago

I pushed some updates and now the permission error should be resolved.

I'm also not sure where it would be asking for me to login when it's running in a docker container on my Synology

I'm not sure, to be honest, never had any experience with Synology. If there is a way to get a proper shell access, then you can just run the container interactively the first time (add -i, omit -d).

Alternatively, do the initial setup on some other machine, then copy the contents of data directory into /opt/TVRemote/data inside the container and restart it. Or put it into data of this project and rebuild the image. If you do that, then don't share the image with anybody, because it will contain your credentials.

CelticWebSolutions commented 4 years ago

Thank for the update, I think we're close enow, the container asked for the auth ket for trat then once I gave it the key, it threw the following error Exception in callback ScrobblingRemoteProtocol.connection_made(<_SelectorSoc...e, bufsize=0>>) handle: <Handle ScrobblingRemoteProtocol.connection_made(<_SelectorSoc...e, bufsize=0>>)> Traceback (most recent call last): File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/opt/TVRemote/scrobbling.py", line 52, in connection_made super().connection_made(transport) File "/opt/TVRemote/media_remote.py", line 48, in connection_made pairing(socket, self.config['device_info']) File "/opt/TVRemote/pairing.py", line 117, in pairing appletv_public = parsed[kTLVType_PublicKey] KeyError: b'\x03'

stigger commented 4 years ago

I was able to reproduce this problem and will try to look into it later this week.

stigger commented 4 years ago

@CelticWebSolutions Pushed a fix, please try again.

CelticWebSolutions commented 4 years ago

Thanks, updated container and now I can't get Trakt to generate a code, keep getting error on tract website "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."

CelticWebSolutions commented 4 years ago

I've managed to get past the tract authorisation part by adding an existing config and tarot.auth file, now it just sat and did nothing....

I deleted the container and set it up with higher privileges and then set the network to be same as host. It's now saying ready! I think we're near perfect now. Only issue in the container is the OAUTH failing. doesn't effect it running directly on my Mac though, only while it's in the container. I'll experiment some more and see if I can fix that if you can't replicate it. I'll update when I get it all working 100%

Thank you for all your time and effort!

CelticWebSolutions commented 4 years ago

Quick update, Netflix works great, Amazon on the other hand fails with an error as follows

Exception in thread Thread-5: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 214, in get_amazon_details url = self.config['amazon']['get_playback_resources_url'] % contentIdentifier KeyError: 'get_playback_resources_url'

Definitely some serious progress here, I'm really impressed how well the Netflix one worked!

stigger commented 4 years ago

Glad that it works!

The Amazon support is a bit tricky and requires some additional configuration. Besides, I haven't used Amazon Prime for some time, so it might be non-functional at the moment. Nevertheless, please give it a try, and if this works for you, I'll put something into readme.

  1. Go to the prime video service in the browser
  2. In your browser open Web Inspector, find a way to see cookies and get the values for the following cookies: ubid-acbde, x-acbde, at-acbde
  3. Start watching some video. In the web inspector try to find requests to a URL containing "cdp/catalog/GetPlaybackResources". Copy that URL and replace the value for asin parameter with %s.
  4. Put everything together and add to config.yml using the following structure:
    amazon:
    cookie: ubid-acbde=<value>; x-acbde=<value>; at-acbde=<value>
    get_playback_resources_url: https://atv-ps-eu.amazon.de/cdp/catalog/GetPlaybackResources?asin=%s&consumptionType=Streaming&<...>
CelticWebSolutions commented 4 years ago

OK I've found the details above, my cookies are UK not de, for example, instead of ubid-acbde I have ubidacbuk I've changed them to show as such in the entry in the config. exmaple being

amazon: cookie: ubid-acbuk=262-3051744-8224249; x-acbuk=

I assume thats correct?

As for the url, I've found that in the network inspector, it's extremely long, which part do I need?

Here it is (modified some numbers within so as not to give any access to my account)

https://atv-ps-eu.amazon.co.uk/cdp/catalog/GetPlaybackResources?asin=B085F2BPQJ&consumptionType=Streaming&desiredResources=Widevine2License&deviceID=a635aec3812f4c74d7e3e0c96ecaa562179c421951ef98d170cf56e3&deviceTypeID=AOAGZA014O5RE&firmware=1&gascEnabled=false&marketplaceID=A1F83G8C1ARO7P&resourceUsage=ImmediateConsumption&userWatchSessionId=89eb3a09-1abe-4d8d-bd29-a43aa72f5064&videoMaterialType=Feature&playerType=html5&clientId=f22dbddb-ef2c-48c5-8876-bed0d47594fd&operatingSystemName=Mac%20OS%20X&operatingSystemVersion=10.15.4&deviceDrmOverride=CENC&deviceStreamingTechnologyOverride=DASH

Thanks again for all your help, I'll be assembling thsi in a simple package for Synology users once we get this sorted.

stigger commented 4 years ago

OK I've found the details above, my cookies are UK not de, for example, instead of ubid-acbde I have ubidacbuk I've changed them to show as such in the entry in the config

Yes, in that case you should have ubid-acbuk, x-acbuk and at-acbuk.

As for the url, I've found that in the network inspector, it's extremely long, which part do I need?

  1. Replace asin=B085F2BPQJ with asin=%s
  2. Replace Widevine2License with CatalogMetadata
  3. The rest can be left as is, I think
CelticWebSolutions commented 4 years ago

OK so my url would be something like

get_playback_resources_url: https://atv-ps-eu.amazon.co.uk/cdp/catalog/GetPlaybackResources?asin=%s&consumptionType=Streaming&desiredResources=CatalogMetadata&deviceID=a635aec3812f4c94d7e2e0c96ecaa562179c421951ef98d170cf56e2&deviceTypeID=AOAGZA014O5RE&firmware=1&gascEnabled=false&marketplaceID=A1F83G7C2ARO7P&resourceUsage=ImmediateConsumption&userWatchSessionId=88eb2a09-1abe-4d8d-bd29-a43aa72f5064&videoMaterialType=Feature&playerType=html5&clientId=f22dbddb-ef2c-48c5-8876-bed0d47594fd&operatingSystemName=Mac%20OS%20X&operatingSystemVersion=10.15.4&deviceDrmOverride=CENC&deviceStreamingTechnologyOverride=DASH

Does that look right?

CelticWebSolutions commented 4 years ago

First time I tried, before you gave me the details to change in the url, it stopped the system from talking to trakt all together, with the modified url, it talks to trakt about Netflix but still throws an error while using amazon with the following log

Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 211, in get_amazon_details known = self.config['amazon']['titles'].get(contentIdentifier) KeyError: 'titles'

We must be close now! Could you possibly send me your own config so I can break it down to work with my details?

stigger commented 4 years ago

Yes, the URL looks fine.

Regarding the exception, please add titles: {} to the amazon section, so it looks like this:

amazon:
  titles: {}
  cookie: ubid-acbuk=<value>; x-acbuk=<value>; at-acbuk=<value>
  get_playback_resources_url: https://atv-ps-eu.amazon.co.uk/cdp/catalog/GetPlaybackResources?asin=%s&consumptionType=Streaming&desiredResources=CatalogMetadata&deviceID=a635aec3812f4c94d7e2e0c96ecaa562179c421951ef98d170cf56e2&deviceTypeID=AOAGZA014O5RE&firmware=1&gascEnabled=false&marketplaceID=A1F83G7C2ARO7P&resourceUsage=ImmediateConsumption&userWatchSessionId=88eb2a09-1abe-4d8d-bd29-a43aa72f5064&videoMaterialType=Feature&playerType=html5&clientId=f22dbddb-ef2c-48c5-8876-bed0d47594fd&operatingSystemName=Mac%20OS%20X&operatingSystemVersion=10.15.4&deviceDrmOverride=CENC&deviceStreamingTechnologyOverride=DASH
CelticWebSolutions commented 4 years ago

Unfortunately that still didn't work.

On playing something in Amazon I get Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 214, in get_amazon_details url = self.config['amazon']['get_playback_resources_url'] % contentIdentifier TypeError: not enough arguments for format string

On Stopping I get Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 214, in get_amazon_details url = self.config['amazon']['get_playback_resources_url'] % contentIdentifier TypeError: not enough arguments for format string

Any more suggestions?

stigger commented 4 years ago

Looks like the get_playback_resources_url value is invalid. Make sure that every value is in a single line without returns, and that %s is present in the right place.

CelticWebSolutions commented 4 years ago

I'll give it another go now and see what happens

CelticWebSolutions commented 4 years ago

Tried again and still didn't work. I previously got the url from Chrome, so this time I've got it from Safari and it is different, here it is

https://atv-ps-eu.amazon.co.uk/cdp/catalog/GetPlaybackResources?asin=B085F2BPQJ&consumptionType=Streaming&desiredResources=PlaybackUrls&deviceID=7f0629695bfc468a8c34e642227fa51559248c3d5563b1e08b3d2d83&deviceTypeID=AOAGZA014O5RE&firmware=1&gascEnabled=false&marketplaceID=A1F83G8C2ARO7P&resourceUsage=ImmediateConsumption&userWatchSessionId=78fa2f63-52d9-4e09-b839-d93ca7644ddd&videoMaterialType=Feature&playerType=html5&clientId=f22dbddb-ef2c-48c5-8876-bed0d47594fd&operatingSystemName=Mac%20OS%20X&operatingSystemVersion=10.15.4&deviceDrmOverride=FairPlay&deviceStreamingTechnologyOverride=HLS&deviceProtocolOverride=Https&supportedDRMKeyScheme=SINGLE_KEY&videoMinBitrate=50000&liveManifestType=live&deviceBitrateAdaptationsOverride=CBR&languageFeature=MLFv2

I have replaced the sin with %s as stated but this time I can't find wide vine to replace with CatalogMetadata. So it would appear that this url is different. I'm assuming some details in that url will be different on the Apple TV too? Or is that not an issue?

stigger commented 4 years ago

No, it's not an issue.

OK, I think I know what's wrong: please try again the first version of the URL, but drop the &operatingSystemName=Mac%20OS%20X part.

CelticWebSolutions commented 4 years ago

OK, building now with that one part of the url removed. I'll update you shortly.

CelticWebSolutions commented 4 years ago

still an exception

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 219, in get_amazon_details episode = data['catalogMetadata']['catalog']['episodeNumber'] KeyError: 'catalogMetadata'

stigger commented 4 years ago

Well, at least we're 5 lines of code further this time :)

CelticWebSolutions commented 4 years ago

oh yes lol! 219 now instead of 214, I hadn't noticed!

stigger commented 4 years ago

Try to use this URL, but replace values for deviceID and deviceTypeID with yours: https://atv-ps-eu.amazon.co.uk/cdp/catalog/GetPlaybackResources?asin=%s&consumptionType=Streaming&desiredResources=CatalogMetadata&firmware=1&resourceUsage=ImmediateConsumption&videoMaterialType=Feature&titleDecorationScheme=primary-content&deviceID=your_value&deviceTypeID=your_value

CelticWebSolutions commented 4 years ago

Used your url and got the following error

Exception in thread Thread-3: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/TVRemote/scrobbling.py", line 94, in <lambda> Thread(target=lambda: inner()).start() File "/opt/TVRemote/scrobbling.py", line 91, in inner handler(operation, progress) File "/opt/TVRemote/scrobbling.py", line 204, in handle_amazon title, season, episode = self.get_amazon_details(self.now_playing_metadata.contentIdentifier) File "/opt/TVRemote/scrobbling.py", line 219, in get_amazon_details episode = data['catalogMetadata']['catalog']['episodeNumber'] KeyError: 'catalogMetadata'

stigger commented 4 years ago

OK, let's slightly change our approach. Our goal is to derive a working URL that has desiredResources set to CatalogMetadata. The algorithm is to take an existing URL and iteratively modify it until we get what we want. For tests, to make sure that the URL is correct, you can just open it in the browser and see, whether you get an error or a sensible response.

So, the steps, approximately, are:

  1. Take a valid URL, make sure it works (and make sure it keeps working on every change you make)
  2. Set desiredResources=CatalogMetadata
  3. Remove &operatingSystemName=Mac%20OS%20X
  4. If you want, you can try to minimize it further by removing parameters one by one, and returning them if they turn out to be required. But this is optional
  5. At the very end replace asin value with %s and put the result into config.

If you want, we can try to chat via IM to make it more interactive, might be quicker that way.

CelticWebSolutions commented 4 years ago

Managed to shorten the URL a little while keeping it as a working URL, unfortunately I'm not getting anywhere with the software side of things though, all up for IM if you are available. What IM did you have in mind?