Repository: pymedusa/Medusa

Issue:
error reporting
### Before submitting your issue:

Enable debug logging in Medusa settings, reproduce the error (be sure to disable after the bug is fixed)

Branch/Commit: last dev
OS: windows 10

2016-10-26 10:24:03 ERROR    Thread-31 :: [9f9a897] Failed doing web ui callback: Traceback (most recent call last):
  File "C:\Medusa\medusa\server\web\core\base.py", line 271, in async_call
    result = function(**kwargs)
  File "C:\Medusa\medusa\server\web\home\post_process.py", line 49, in processEpisode
    is_priority=argToBool(is_priority), delete_on=argToBool(delete_on), failed=argToBool(failed), proc_type=type, ignore_subs=argToBool(ignore_subs)
  File "C:\Medusa\medusa\processTV.py", line 287, in processDir
    process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, ignore_subs, result)
  File "C:\Medusa\medusa\processTV.py", line 548, in process_media
    if has_matching_unknown_subtitles(cur_video_file_path):
  File "C:\Medusa\medusa\processTV.py", line 672, in has_matching_unknown_subtitles
    Language('und') in get_embedded_subtitles(video_path)
  File "C:\Medusa\medusa\processTV.py", line 683, in get_embedded_subtitles
    subliminal_video = scan_video(video_path)
  File "C:\Medusa\lib\subliminal\core.py", line 380, in scan_video
    video = Video.fromguess(path, guessit(path))
  File "C:\Medusa\lib\subliminal\video.py", line 93, in fromguess
    return Episode.fromguess(name, guess)
  File "C:\Medusa\lib\subliminal\video.py", line 166, in fromguess
    raise ValueError('Insufficient data to process the guess')
ValueError: Insufficient data to process the guess
Traceback (most recent call last):
  File "C:\Medusa\medusa\server\web\core\base.py", line 271, in async_call
    result = function(**kwargs)
  File "C:\Medusa\medusa\server\web\home\post_process.py", line 49, in processEpisode
    is_priority=argToBool(is_priority), delete_on=argToBool(delete_on), failed=argToBool(failed), proc_type=type, ignore_subs=argToBool(ignore_subs)
  File "C:\Medusa\medusa\processTV.py", line 287, in processDir
    process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, ignore_subs, result)
  File "C:\Medusa\medusa\processTV.py", line 548, in process_media
    if has_matching_unknown_subtitles(cur_video_file_path):
  File "C:\Medusa\medusa\processTV.py", line 672, in has_matching_unknown_subtitles
    Language('und') in get_embedded_subtitles(video_path)
  File "C:\Medusa\medusa\processTV.py", line 683, in get_embedded_subtitles
    subliminal_video = scan_video(video_path)
  File "C:\Medusa\lib\subliminal\core.py", line 380, in scan_video
    video = Video.fromguess(path, guessit(path))
  File "C:\Medusa\lib\subliminal\video.py", line 93, in fromguess
    return Episode.fromguess(name, guess)
  File "C:\Medusa\lib\subliminal\video.py", line 166, in fromguess
    raise ValueError('Insufficient data to process the guess')
ValueError: Insufficient data to process the guess

full logs:
https://gist.github.com/NicoLeOca/4ec37df98fcce01d3255ba122fc6e46d



Discussion:
What's the state here? Fixed? @fernandog @ratoaq2 

Just starting to check it:

This is the important part of the log:

```
2016-10-26 10:24:03 DEBUG    Thread-31 :: [9f9a897] Parsed 'Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7' into title: Black Mirror, season: 2, screen_size: 1080p, format: WEB-DL, audio_codec: AAC, audio_channels: 2.0, video_codec: h264, release_group: Coo7, type: episode, absolute_episode: [], quality: 1080p WEB-DL, episode: []
```

What should be done when video has no episode, only season?

@ratoaq2 that is the directory.. it's of a season pack, if i'm not mistaken it's failing on one of the files.
@NicoLeOca what is the file list of `Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7`

@ratoaq2
Black.Mirror.S02E01.Be.Right.Back.1080p.WEB-DL.AAC2.0.H.264-Coo7
Black.Mirror.S02E02.White.Bear.1080p.Web-Dl.Aac2.0.h264-COO7
Black.Mirror.S02E03.The.Waldo.Moment.1080p.Web-Dl.Aac2.0.h264-COO7
Black.Mirror.S02.Special.White.Chirstmas.1080p.WEB-DL.AAC2.0.H.264-Coo7

It's related to process_tv.py logic: has_matching_unknown_subtitles:

```
  File "C:\Medusa\medusa\server\web\home\post_process.py", line 49, in processEpisode
    is_priority=argToBool(is_priority), delete_on=argToBool(delete_on), failed=argToBool(failed), proc_type=type, ignore_subs=argToBool(ignore_subs)
  File "C:\Medusa\medusa\processTV.py", line 287, in processDir
    process_media(processPath, videoFiles, nzbName, process_method, force, is_priority, ignore_subs, result)
  File "C:\Medusa\medusa\processTV.py", line 548, in process_media
    if has_matching_unknown_subtitles(cur_video_file_path):
  File "C:\Medusa\medusa\processTV.py", line 672, in has_matching_unknown_subtitles
    Language('und') in get_embedded_subtitles(video_path)
  File "C:\Medusa\medusa\processTV.py", line 683, in get_embedded_subtitles
    subliminal_video = scan_video(video_path)
  File "C:\Medusa\lib\subliminal\core.py", line 380, in scan_video
    video = Video.fromguess(path, guessit(path))
  File "C:\Medusa\lib\subliminal\video.py", line 93, in fromguess
    return Episode.fromguess(name, guess)
  File "C:\Medusa\lib\subliminal\video.py", line 166, in fromguess
    raise ValueError('Insufficient data to process the guess')
ValueError: Insufficient data to process the guess
```

It seems that's trying to process the folder as a video. @fernandog 

the problem is the special episode.

there is no episode so this fails `return Episode.fromguess(name, guess)`

that's why i tried to ignore special episodes parsing with this PR:

### Raise InvalidNameException for special episodes

https://github.com/pymedusa/Medusa/pull/1317

i see no other solution

The issue is in subliminal tho

What report guessit say passing folder + special? On mobile now

no idea why it fails @ratoaq2 

is pass video_path: `subliminal_video = scan_video(video_path)` - full path

## report_guessit:

```
python report_guessit.py "/media/series/Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7\Black.Mirror.S02.Special.White.Chirstmas.1080p.WEB-DL.AAC2.0.H.264-Coo7.mkv"
# guessit: 2.1.1.dev0  rebulk: 0.7.6
? /media/series/Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7\Black.Mirror.S02.Special.White.Chirstmas.1080p.WEB-DL.AAC2.0.H.264-Coo7.mkv
: season: 2
  screen_size: 1080p
  format: WEB-DL
  audio_codec: AAC
  audio_channels: 2.0
  video_codec: h264
  release_group: Coo7
  title: Black Mirror
  episode_title: Special White Chirstmas
  episode_details: Special
  container: mkv
  mimetype: video/x-matroska
  type: episode

```

## guessit

```
guessit "/media/series/Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7\Black.Mirror.S02.Special.White.Chirstmas.1080p.WEB-DL.AAC2.0.H.264-Coo7.mkv"
For: /media/series/Black.Mirror.S02.1080p.WEB-DL.AAC2.0.H.264-Coo7\Black.Mirror.S02.Special.White.Chirstmas.1080p.WEB-DL.AAC2.0.H.264-Coo7.mkv
GuessIt found: {
    "season": 2,
    "screen_size": "1080p",
    "format": "WEB-DL",
    "audio_codec": "AAC",
    "audio_channels": "2.0",
    "video_codec": "h264",
    "release_group": "Coo7",
    "title": "Black Mirror",
    "episode_title": "Special White Chirstmas",
    "episode_details": "Special",
    "container": "mkv",
    "mimetype": "video/x-matroska",
    "type": "episode"
}

```


Resolving patch:
diff --git a/medusa/image_cache.py b/medusa/image_cache.py
--- a/medusa/image_cache.py
+++ b/medusa/image_cache.py
@@ -20,10 +20,10 @@
 import os.path
 
 import medusa as app
-from medusa.helpers import get_image_size
 from . import helpers, logger
 from .helper.common import try_int
 from .helper.exceptions import ShowDirectoryNotFoundException
+from .helpers import get_image_size
 from .metadata.generic import GenericMetadata
 
 
diff --git a/medusa/metadata/generic.py b/medusa/metadata/generic.py
--- a/medusa/metadata/generic.py
+++ b/medusa/metadata/generic.py
@@ -22,10 +22,9 @@
 import re
 
 import medusa as app
-from medusa import exception_handler
 from six import iterkeys
 from tmdb_api.tmdb_api import TMDB
-from .. import helpers, logger
+from .. import exception_handler, helpers, logger
 from ..helper.common import replace_extension
 from ..helper.exceptions import ex
 from ..metadata import helpers as metadata_helpers
diff --git a/medusa/process_tv.py b/medusa/process_tv.py
--- a/medusa/process_tv.py
+++ b/medusa/process_tv.py
@@ -21,9 +21,9 @@
 import stat
 
 from babelfish import Language
+import knowit
 import medusa as app
 import shutil_custom
-from subliminal import refine, scan_video
 from unrar2 import RarFile
 from unrar2.rar_exceptions import (ArchiveHeaderBroken, FileOpenError, IncorrectRARPassword, InvalidRARArchive,
                                    InvalidRARArchiveUsage)
@@ -683,6 +683,6 @@ def get_embedded_subtitles(video_path):
     :return:
     :rtype: set of Language
     """
-    subliminal_video = scan_video(video_path)
-    refine(subliminal_video, episode_refiners=('metadata',))
-    return subliminal_video.subtitle_languages
+    knowledge = knowit.know(video_path)
+    tracks = knowledge.get('subtitle', [])
+    return [s['language'] for s in tracks if 'language' in s]


Test patch: