ukdtom / ExportTools.bundle

Export tools for Plex
https://forums.plex.tv/t/rel-exporttools/175915
The Unlicense
328 stars 29 forks source link

Missing hash causes exception #99

Closed seizedengine closed 5 years ago

seizedengine commented 5 years ago

Bringing this up as an issue even though I acknowledge that the cause is outside of ExportTools itself. This also only happens on level 666 (in this case for my movies library only). ExportTools v2.0.0.4.

Running ExportTools on my Movies library results in an exception:

2019-07-25 19:35:17,920 (-ef004c0) :  DEBUG (networking:166) - Requesting 'http://127.0.0.1:32400/library/metadata/103179?includeBandwidths=1&includeExtras=1&includeChapters=1'
2019-07-25 19:35:17,995 (-ef004c0) :  DEBUG (networking:166) - Requesting 'http://127.0.0.1:32400/library/metadata/103179/tree'
2019-07-25 19:35:18,002 (-ef004c0) :  CRITICAL (__init__:714) - Exception happened in backgroundScanThread was string index out of range (most recent call last):
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/__init__.py", line 702, in backgroundScanThread
    scanPhotoDB(myMediaURL, outFile, level=myLevel)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/__init__.py", line 777, in scanMovieDB
    myRow = movies.getMovieInfo(media, myRow, prefsLevel=level)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/movies.py", line 183, in getMovieInfo
    myRow = misc.getMediaPath(myMedia, myRow)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/misc.py", line 349, in getMediaPath
    MediaHash[0], MediaHash[1:] + '.bundle',
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-4b7ace214/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 108, in <lambda>
    _getitem_           = lambda x, y: x.__getitem__(y),
IndexError: string index out of range

2019-07-25 19:35:18,003 (-ef004c0) :  CRITICAL (runtime:1128) - Exception in thread named 'backgroundScanThread' (most recent call last):
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-4b7ace214/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/components/runtime.py", line 1126, in _start_thread
    f(*args, **kwargs)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/__init__.py", line 702, in backgroundScanThread
    scanPhotoDB(myMediaURL, outFile, level=myLevel)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/__init__.py", line 777, in scanMovieDB
    myRow = movies.getMovieInfo(media, myRow, prefsLevel=level)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/movies.py", line 183, in getMovieInfo
    myRow = misc.getMediaPath(myMedia, myRow)
  File "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/ExportTools V2.0.0.4.bundle/Contents/Code/misc.py", line 349, in getMediaPath
    MediaHash[0], MediaHash[1:] + '.bundle',
  File "/usr/lib/plexmediaserver/Resources/Plug-ins-4b7ace214/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 108, in <lambda>
    _getitem_           = lambda x, y: x.__getitem__(y),
IndexError: string index out of range

Checking the movies that cause this error using a direct URL (https://server:32400/library/metadata/103540/tree?checkFiles=1&includeExtras=1&includeBandwidths=1&X-Plex-Token=redacted) returns the XML of the movie which has a blank hash value (hash="").

<MediaContainer size="1" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1562056514">
<MetadataItem id="103179" title="The Dark Tower" guid="com.plexapp.agents.imdb://tt1648190?lang=en" parentTitle="" index="1" originallyAvailableAt="2017-08-04">
<MediaItem id="172420">
<MediaPart id="174022" file="/mnt/media-tank/movies/The Dark Tower (2017)/The Dark Tower (2017).mkv" size="6659220566" openSubtitleHash="" hash="" duration="5684682">
<MediaStream id="350096" index="0" type="1" codec="h264" bitDepth="8" chromaLocation="left" chromaSubsampling="4:2:0" colorPrimaries="bt709" colorRange="tv" colorSpace="bt709" colorTrc="bt709" frameRate="23.976" hasScalingMatrix="0" height="800" level="41" profile="high" refFrames="5" requiredBandwidths="22752,16489,14172,12200,11402,11017,9195,8369" scanType="progressive" width="1920"/>
<MediaStream id="350097" index="1" type="2" channels="6" codec="dca" language="eng" audioChannelLayout="5.1(side)" bitDepth="16" profile="dts" requiredBandwidths="1509,1509,1509,1509,1509,1509,1509,1509" samplingRate="48000" title="Surround"/>
<MediaStream id="350098" index="2" type="3" codec="pgs" language="eng"/>
</MediaPart>
</MediaItem>
</MetadataItem>
</MediaContainer>

I have found at least two movies without a hash in my library. Optimizing the library or trying other actions like refreshing that movies medadata or analyzing the media does not create the hash value. These movies play fine without it. Deleting then readding the movie creates the missing hash and fixes things.

Since this only happens on level 666 and I dont specifically need that value I can work around it but thought it worthy of bringing up. Maybe a specific version of Plex didnt create these hash values or there is some other factor. There isnt anything odd/different about these movies vs others though, at least not obviously.

Probably the best fix is for ExportTools to fail gracefully wthout the hash and just write some error in the output file field.

ukdtom commented 5 years ago

Thanks, and first time I've heard about this problem

seizedengine commented 5 years ago

Updated my misc.py with the new one and reran the export on level 666. Confirmed that it worked with my hashless movies. Four movies total, not counting one I deleted and readded as a test. Very weird.

Thank you for the quick fix!

ukdtom commented 5 years ago

Thanks for the detailed report, as well as confirming it, since all my medias worked, so no way of testing ;)