stigger / trakt-for-appletv

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

Docker build process and usage #12

Closed tanc closed 3 years ago

tanc commented 4 years ago

Hi, I'm interesting in trying this as a Docker container. I've cloned the latest and build the container using the following steps:

git clone https://github.com/stigger/trakt-for-appletv.git
cd trakt-for-appletv
docker build --tag traktforappletv:1.0 .
docker run --name traktforappletv traktforappletv:1.0

Unfortunately the container quits immediately with the following output:

tvscrobbler.py:21: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  config = yaml.load(open('data/config.yml', 'r'))
Navigate to https://trakt.tv/oauth/authorize?client_id=dc705f550f50706bdd7bd55db120235cc68899dbbfb4fbc171384c1c1d30d7d4&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code
Authorization code: Traceback (most recent call last):
  File "tvscrobbler.py", line 53, in <module>
    launch(ScrobblingRemoteProtocol(load_config()))
  File "/opt/TVRemote/scrobbling.py", line 39, in __init__
    self.authenticate_trakt()
  File "/opt/TVRemote/scrobbling.py", line 46, in authenticate_trakt
    pin = input('Authorization code: ')
EOFError: EOF when reading a line

Is this the correct way to use it? Are there any docs on usage?

stigger commented 4 years ago

Try running with -it, so the container has access to the terminal.

tanc commented 4 years ago

Thank you, that worked:

docker run -it --name traktforappletv traktforappletv:1.0

I've followed the steps and entered the authorisation code. How does it work from here?

stigger commented 4 years ago

If it said "done!", then you're done, now it should just work.

tanc commented 4 years ago

The last thing printed to the terminal was the input for the Trakt authorisation code. But nothing after pressing return. I've tried it twice but it does not continue after entering the code.

stigger commented 4 years ago

It should also ask you to enter code from Apple TV. Does file data/trakt.auth gets created? If not, then something's off.

tanc commented 4 years ago

In the host machine I see data/config.yml but not data/trakt.auth. The same when I get a shell in the docker container:

~ $ ls -la data
total 12
drwxr-xr-x    2 tvremote root          4096 Mar 31 16:05 .
drwxr-sr-x    1 tvremote nogroup       4096 Mar 31 16:05 ..
-rw-r--r--    1 tvremote root            37 Mar 31 15:18 config.yml
stigger commented 4 years ago

Perhaps, the script does not get the entered code from stdin, not sure why.

tanc commented 4 years ago

I also tried from within the container but the same problem. I was successful creating a virtualenv on the host machine and running the commands as per the README.md. This created the following two files:

data/pairing.state
data/trakt.auth

Can I copy them into the docker container and use it from there?

I'm also not entirely clear how this is supposed to work. Does the container need to be constantly running? How does the container interact with the Apple TV?

stigger commented 4 years ago

Can I copy them into the docker container and use it from there?

Yes, or you can put them in data/ on your host and rebuild the container: they will be included into the container.

I'm also not entirely clear how this is supposed to work. Does the container need to be constantly running? How does the container interact with the Apple TV?

Yes, it needs to be constantly running. The script acts as a remote app (like Apple's Remote iOS app) and receives information about what's currently playing on Apple TV. Then it just uses this information to scrobble to trakt.

tanc commented 4 years ago

Yes, or you can put them in data/ on your host and rebuild the container: they will be included into the container. Good thinking. Rebuilding with the following worked:

docker build --tag traktforappletv:1.1 .

Then:

docker run -dit --name traktforappletv --restart always traktforappletv:1.1

The container stays up and the two files have been included:

~$ docker exec -ti traktforappletv ls -la data
total 20
drwxr-xr-x    2 tvremote root          4096 Apr  1 11:55 .
drwxr-sr-x    1 tvremote nogroup       4096 Apr  1 11:47 ..
-rw-r--r--    1 tvremote root           126 Mar 31 16:38 config.yml
-rw-r--r--    1 tvremote root           167 Mar 31 16:38 pairing.state
-rw-r--r--    1 tvremote root           288 Mar 31 16:38 trakt.auth

Will test scrobbling next.

Question: how does the docker container communicate with the Apple TV? Does it need any ports exposed with the host?

stigger commented 4 years ago

No, it doesn't need any ports, only access to the local network. It initiates connection to Apple TV, not the other way around.

tanc commented 4 years ago

Last night I had the container running and watched an episode of a series but unfortunately it didn't scrobble to Trakt. There is nothing in docker logs that shows any output for that container (other than the YAMLLoadWarning on startup). Is there any logging built in? It would be useful to see whether the container had successfully connected to the Apple TV for instance. Also whether it had recognised a show and tried or failed to scrobble it.

stigger commented 4 years ago

Which app on Apple TV did you use?

You can go on Apple TV to the settings -> remote apps/devices and see if "Trakt Scrobbler" is connected.

You can also add the following snippet to the scrobbler.py. This will log communication with trakt.

import logging
logging.basicConfig(level=logging.DEBUG)
wolverine30008 commented 4 years ago

Hi Stigger, I am not using a docker just did the script as instructed on your repo from a Mac. Under Remote App and devices mine says Remote app: Trakt Scrobbler not connected.  How do I connect? Thanks

Sent from Yahoo Mail for iPad

On Thursday, April 2, 2020, 2:57 PM, Vyacheslav Karpukhin notifications@github.com wrote:

Which app on Apple TV did you use?

You can go on Apple TV to the settings -> remote apps/devices and see if "Trakt Scrobbler" is connected.

You can also add the following snippet to the scrobbler.py. This will log communication with trakt. import logging logging.basicConfig(level=logging.DEBUG)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

What happens when you launch the script?

wolverine30008 commented 4 years ago

odds-Mac-mini:trakt-for-appletv-master wolverine30008$ python3 tvscrobbler.py

tvscrobbler.py:21: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.

  config = yaml.load(open('data/config.yml', 'r'))

Navigate to https://trakt.tv/oauth/authorize?client_id=dc705f550f50706bdd7bd55db120235cc68899dbbfb4fbc171384c1c1d30d7d4&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code

Authorization code: 22F9E386

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/x25519.py:35: CryptographyDeprecationWarning: public_bytes now requires encoding and format arguments. Support for calling without arguments will be removed in cryptography 2.7

  utils.DeprecatedIn25,

ready!

On Thursday, April 2, 2020, 6:57:11 PM EDT, Vyacheslav Karpukhin <notifications@github.com> wrote:  

What happens when you launch the script?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

Well, it prints ready! after successful connection to Apple TV. After that Apple TV should show it as connected, and scrobbling should work.

wolverine30008 commented 4 years ago

Maybe because I had to authorize trakt again, I may have to pair the apple tv again as well with the activation code.  How do i refresh the activation code or do I need to delete the original code in a folder first? Is step 1 authorize trakt and step 2 pair or activate the apple tv or visa versa in the script process?  

On Thursday, April 2, 2020, 7:13:40 PM EDT, Vyacheslav Karpukhin <notifications@github.com> wrote:  

Well, it prints ready! after successful connection to Apple TV. After that Apple TV should show it as connected, and scrobbling should work.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

You don't need to reauthorize with Apple TV. It won't print "done!", unless it was able to connect to Apple TV. But if you want:

  1. Kill the script
  2. Delete Trakt Scrobbler from Apple TV's settings -> remote app & devices
  3. Delete data/pairing.state
  4. Run the script

Note that the script has to keep running in order for scrobbling to work.

wolverine30008 commented 4 years ago

Ok followed the steps and now it says connected. Which apps specifically would I have to use to get the trakt scrobbling started. For iTunes TV and Movies should I use the pink and blue apps or can I just use the Apple TV app in order for it to register on trakt. Also what other apps does this support? Thanks for the support

Sent from Yahoo Mail for iPad

On Thursday, April 2, 2020, 7:27 PM, Vyacheslav Karpukhin notifications@github.com wrote:

You don't need to reauthorize with Apple TV. It won't print "done!", unless it was able to connect to Apple TV. But if you want:

Note that the script has to keep running in order for scrobbling to work.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

All three of Apple's apps should work. Netflix should work out of the box as well. Amazon supported too, but requires additional configuration, which is currently non-trivial, so I suggest to try this on something else first.

wolverine30008 commented 4 years ago

Hi Vyacheslav, I factory reset my Mac and ran the script as I did before and now I receive this when running python3 ./tvscrobbler.py

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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/events.py", line 88, in _run

    self._context.run(self._callback, *self._args)

  File "/Users/toddrock/Downloads/trakt-for-appletv-master/scrobbling.py", line 52, in connection_made

    super().connection_made(transport)

  File "/Users/toddrock/Downloads/trakt-for-appletv-master/media_remote.py", line 50, in connection_made

    self.output_key, self.input_key = setup_keys(verify(socket, self.config['device_info']))

  File "/Users/toddrock/Downloads/trakt-for-appletv-master/pairing.py", line 198, in verify

    {kTLVType_PublicKey: randpk.public_key().public_bytes(), kTLVType_State: b'\x01'}) TypeError: public_bytes() missing 2 required positional arguments: 'encoding' and 'format' Your support is appreciated. Thanks On Thursday, April 2, 2020, 07:48:14 PM EDT, Vyacheslav Karpukhin notifications@github.com wrote:

All three of Apple's apps should work. Netflix should work out of the box as well. Amazon supported too, but requires additional configuration, which is currently non-trivial, so I suggest to try this on something else first.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

Looks like something has changed and the serialization format used for storing the authentication info became incompatible. You need to re-pair: delete the app from Apple TV, delete data/pairing.state, run again.

wolverine30008 commented 4 years ago

did as you instructed. Now I get this

Enter code displayed by Apple TV: 0141

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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/events.py", line 88, in _run

    self._context.run(self._callback, *self._args)

  File "/Users/toddrock/Desktop/trakt-for-appletv-master/scrobbling.py", line 52, in connection_made

    super().connection_made(transport)

  File "/Users/toddrock/Desktop/trakt-for-appletv-master/media_remote.py", line 50, in connection_made

    self.output_key, self.input_key = setup_keys(verify(socket, self.config['device_info']))

  File "/Users/toddrock/Desktop/trakt-for-appletv-master/pairing.py", line 198, in verify

    {kTLVType_PublicKey: randpk.public_key().public_bytes(), kTLVType_State: b'\x01'})

TypeError: public_bytes() missing 2 required positional arguments: 'encoding' and 'format'

On Saturday, April 4, 2020, 06:53:25 PM EDT, Vyacheslav Karpukhin <notifications@github.com> wrote:  

Looks like something has changed and the serialization format used for storing the authentication info became incompatible. You need to re-pair: delete the app from Apple TV, delete data/pairing.state, run again.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

Apparently, I was wrong. I believe the problem is in the cryptography dependency. What does pip3 show cryptography show?

wolverine30008 commented 4 years ago

here is the read out from the pip3 install -r requirements.txt

pip3 install -r requirements.txt

Requirement already satisfied: zeroconf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.25.0)

Requirement already satisfied: PyYAML in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (5.3.1)

Requirement already satisfied: protobuf in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (3.11.3)

Requirement already satisfied: trakt.py in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (3.2.0)

Requirement already satisfied: varint in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (1.0.2)

Requirement already satisfied: srptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (1.0.0)

Requirement already satisfied: ed25519 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (1.5)

Requirement already satisfied: cryptography in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (2.9)

Requirement already satisfied: lxml in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (4.5.0)

Requirement already satisfied: ifaddr in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from zeroconf->-r requirements.txt (line 1)) (0.1.6)

Requirement already satisfied: six>=1.9 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->-r requirements.txt (line 3)) (1.14.0)

Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from protobuf->-r requirements.txt (line 3)) (39.0.1)

Requirement already satisfied: arrow<1.0.0,>=0.10.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from trakt.py->-r requirements.txt (line 4)) (0.15.5)

Requirement already satisfied: requests<3.0.0,>=2.4.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from trakt.py->-r requirements.txt (line 4)) (2.23.0)

Requirement already satisfied: cffi!=1.11.3,>=1.8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cryptography->-r requirements.txt (line 8)) (1.14.0)

Requirement already satisfied: python-dateutil in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from arrow<1.0.0,>=0.10.0->trakt.py->-r requirements.txt (line 4)) (2.8.1)

Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests<3.0.0,>=2.4.0->trakt.py->-r requirements.txt (line 4)) (2019.11.28)

Requirement already satisfied: chardet<4,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests<3.0.0,>=2.4.0->trakt.py->-r requirements.txt (line 4)) (3.0.4)

Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests<3.0.0,>=2.4.0->trakt.py->-r requirements.txt (line 4)) (1.25.8)

Requirement already satisfied: idna<3,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests<3.0.0,>=2.4.0->trakt.py->-r requirements.txt (line 4)) (2.9)

Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography->-r requirements.txt (line 8)) (2.20)

You are using pip version 10.0.1, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. On Saturday, April 4, 2020, 08:03:27 PM EDT, Vyacheslav Karpukhin notifications@github.com wrote:

Apparently, I was wrong. I believe the problem is in the cryptography dependency. What does pip3 show cryptography show?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub, or unsubscribe.

stigger commented 4 years ago

Pushed the fix.