Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'player' #179

Open
kafuku1 opened this issue Dec 13, 2018 · 4 comments
Open

KeyError: 'player' #179

kafuku1 opened this issue Dec 13, 2018 · 4 comments
Labels

Comments

@kafuku1
Copy link

kafuku1 commented Dec 13, 2018

I'm having issues with the latest release of the tool. Everytime I run it this error appears. I've looked for the same error but I didn't find any solution.

Exception in thread Thread-14:to 49 of 1679
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Users\user\Downloads\c\tumblr_backup.py", line 1043, in handler

work()

File "C:\Users\user\Downloads\c\tumblr_backup.py", line 735, in save_con
tent
append(post['player'][-1]['embed_code'])
KeyError: 'player'
Exception in thread Thread-9:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Users\user\Downloads\c\tumblr_backup.py", line 1043, in handler

work()

File "C:\Users\user\Downloads\c\tumblr_backup.py", line 735, in save_con
tent
append(post['player'][-1]['embed_code'])
KeyError: 'player'

Exception in thread Thread-17:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Users\user\Downloads\c\tumblr_backup.py", line 1043, in handler

work()

File "C:\Users\user\Downloads\c\tumblr_backup.py", line 735, in save_con
tent
append(post['player'][-1]['embed_code'])
KeyError: 'player'

@themcny
Copy link

themcny commented Dec 13, 2018

I'm running into the same issue.

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/bin/tumblr_backup.py", line 1043, in handler
    work()
  File "/usr/local/bin/tumblr_backup.py", line 735, in save_content
    append(post['player'][-1]['embed_code'])
KeyError: 'player'

I installed by cloning the repo and copying the python script to my /usr/local/bin and then ran tumblr_backup.py blogname. I didn't run with any special flags and I brew installed both youtube-dland pyexiv2 locally.

@cebtenzzre
Copy link
Collaborator

cebtenzzre commented Dec 13, 2018

Here's an untested patch that attempts to make the video/audio save/embed code more robust.
I don't know Python as well as I know C++, so standard disclaimer if it doesn't work.

These instructions seem to be necessary here:
Here is where I've explained how to apply a patch.
See also diff on Wikipedia and the man page for GNU patch.

diff --git a/tumblr_backup.py b/tumblr_backup.py
index 338c7d3..c2eb2fe 100755
--- a/tumblr_backup.py
+++ b/tumblr_backup.py
@@ -731,13 +731,17 @@ class TumblrPost:
                     src, "Your browser does not support the video element.", src, "Video file"
                 ))
             else:
-                append(post['player'][-1]['embed_code'])
+                player = get_try('player')
+                if player:
+                    append(player[-1]['embed_code'])
+                else:
+                    append_try('video_url')
             append_try('caption')
 
         elif self.typ == 'audio':
             src = ''
+            audio_url = get_try('audio_url') or get_try('audio_source_url')
             if options.save_audio:
-                audio_url = get_try('audio_url') or get_try('audio_source_url')
                 if post['audio_type'] == 'tumblr':
                     if audio_url.startswith('https://a.tumblr.com/'):
                         src = self.get_media_url(audio_url, '.mp3')
@@ -746,12 +750,13 @@ class TumblrPost:
                         src = self.get_media_url(audio_url, '.mp3')
                 elif post['audio_type'] == 'soundcloud':
                     src = self.get_media_url(audio_url, '.mp3')
-            if src:
+            player = get_try('player')
+            if src or ((not player) and audio_url):
                 append(u'<p><audio controls><source src="%s" type=audio/mpeg>%s<br>\n<a href="%s">%s</a></audio></p>' % (
-                    src, "Your browser does not support the audio element.", src, "Audio file"
+                    src, "Your browser does not support the audio element.", src or audio_url, "Audio file"
                 ))
-            else:
-                append(post['player'])
+            elif player:
+                append(player)
             append_try('caption')
 
         elif self.typ == 'answer':

@aspensmonster
Copy link

@kafuku1 @themcny Is it possible to get the full command that was run (including blog name)? I'd like to try to test @cebtenzzre's patch, but don't know what specific payloads are causing the problem.

@cebtenzzre cebtenzzre changed the title Exception in thread error KeyError: 'player' Dec 16, 2018
@agcarter
Copy link

agcarter commented Jan 2, 2019

I'm having what looks like the same issue. I used my blog (tumblr_backup.py frogeyedape) if you want to test it.
running errors with cmd
I'm a total newbie to both python and github, so please let me know if there's any other information I need to add.

@cebtenzzre cebtenzzre added the bug label Aug 31, 2020
cebtenzzre added a commit to cebtenzzre/tumblr-utils that referenced this issue Sep 24, 2020
cebtenzzre added a commit to cebtenzzre/tumblr-utils that referenced this issue Nov 25, 2020
cebtenzzre added a commit to cebtenzzre/tumblr-utils that referenced this issue Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants