Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: ParseError: not well-formed (invalid token): line 1, column 19

### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe
**Link to Log**: https://gist.github.com/b93f708a0f5b80e1ab608f3c9b1259c2
### ERROR
<pre>
2018-04-02 05:11:25 ERROR    SEARCHQUEUE-BACKLOG-290853 :: [filelist] :: [d6eb72d] Unable to parse the XML of Fear.The.Walking.Dead.S02.HDTV.AAC2.0.x264-Scene, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 60, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

[APP SUBMITTED]: ParseError: not well-formed (invalid token): line 1, column 19

### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe
**Link to Log**: https://gist.github.com/b93f708a0f5b80e1ab608f3c9b1259c2
### ERROR
<pre>
2018-04-02 05:11:25 ERROR    SEARCHQUEUE-BACKLOG-290853 :: [filelist] :: [d6eb72d] Unable to parse the XML of Fear.The.Walking.Dead.S02.HDTV.AAC2.0.x264-Scene, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 60, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/8bec4adb14fec09c362cc7c433aefa2c
### ERROR
<pre>
2018-04-04 19:11:40 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [bitmetv] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S06.BDRip.SUBS-HAGGiS, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 20
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/7b3f339a9ad9f7964032138d1e723637
### ERROR
<pre>
2018-04-04 19:00:39 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [bitmetv] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S02.DVDRip.XviD-HAGGiS, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 20
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/e4e5ae27fb68f31e5d68f88c8a3c39e3
### ERROR
<pre>
2018-04-04 18:53:48 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [filelist] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S01.RoSubbed.HDTV.XviD-FL, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@77b20916ab577b82112ebc624f816054788c63f2
**Link to Log**: https://gist.github.com/c58b70f551e37d47db739520991eec4d
### ERROR
<pre>
2018-04-22 22:28:26 ERROR    SEARCHQUEUE-BACKLOG-295760 :: [Jackett FileList.ro] :: [77b2091] Unable to parse the XML of DCs.Legends.Of.Tomorrow.S03.1080p.AMZN.WEB-DL.DD+5.1.H.264-QOQ, not splitting it
Traceback (most recent call last):
  File "C:\Data\Medusa\Medusa\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/8bec4adb14fec09c362cc7c433aefa2c
### ERROR
<pre>
2018-04-04 19:11:40 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [bitmetv] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S06.BDRip.SUBS-HAGGiS, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 20
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/7b3f339a9ad9f7964032138d1e723637
### ERROR
<pre>
2018-04-04 19:00:39 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [bitmetv] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S02.DVDRip.XviD-HAGGiS, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 20
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@0da7d0a5b457a7acf6686949361aa1a1c2fcf93d
**Link to Log**: https://gist.github.com/e4e5ae27fb68f31e5d68f88c8a3c39e3
### ERROR
<pre>
2018-04-04 18:53:48 ERROR    SEARCHQUEUE-BACKLOG-193131 :: [filelist] :: [0da7d0a] Unable to parse the XML of Downton.Abbey.S01.RoSubbed.HDTV.XviD-FL, not splitting it
Traceback (most recent call last):
  File "C:\Users\Mat\Documents\Medusa-0.2.1\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.16299`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@77b20916ab577b82112ebc624f816054788c63f2
**Link to Log**: https://gist.github.com/c58b70f551e37d47db739520991eec4d
### ERROR
<pre>
2018-04-22 22:28:26 ERROR    SEARCHQUEUE-BACKLOG-295760 :: [Jackett FileList.ro] :: [77b2091] Unable to parse the XML of DCs.Legends.Of.Tomorrow.S03.1080p.AMZN.WEB-DL.DD+5.1.H.264-QOQ, not splitting it
Traceback (most recent call last):
  File "C:\Data\Medusa\Medusa\medusa\nzb_splitter.py", line 61, in get_season_nzbs
    show_xml = ETree.ElementTree(ETree.XML(url_data))
  File "<string>", line 124, in XML
ParseError: not well-formed (invalid token): line 1, column 19
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Resolving patch:
diff --git a/medusa/nzb_splitter.py b/medusa/nzb_splitter.py
--- a/medusa/nzb_splitter.py
+++ b/medusa/nzb_splitter.py
@@ -20,11 +20,13 @@
 # pylint: disable=line-too-long
 
 from __future__ import unicode_literals
+import logging
 import re
 
-from medusa import classes, logger
+from medusa import classes
 from medusa.helper.encoding import ss
 from medusa.helper.exceptions import ex
+from medusa.logger.adapters.style import BraceAdapter
 from medusa.name_parser.parser import InvalidNameException, InvalidShowException, NameParser
 from medusa.session.core import MedusaSession
 
@@ -34,6 +36,9 @@
     import xml.etree.ElementTree as ETree
 
 
+log = BraceAdapter(logging.getLogger(__name__))
+log.logger.addHandler(logging.NullHandler())
+
 session = MedusaSession()
 
 
@@ -60,7 +65,7 @@ def get_season_nzbs(name, url_data, season):
     try:
         show_xml = ETree.ElementTree(ETree.XML(url_data))
     except SyntaxError:
-        logger.log(u"Unable to parse the XML of " + name + ", not splitting it", logger.ERROR)  # pylint: disable=no-member
+        log.error(u'Unable to parse the XML of {0}, not splitting it', name)
         return {}, ''
 
     nzb_element = show_xml.getroot()
@@ -70,7 +75,7 @@ def get_season_nzbs(name, url_data, season):
         show_name = scene_name_match.groups()[0]
     else:  # Make sure we aren't missing valid results after changing name_parser and the quality detection
         # Most of these will likely be invalid shows
-        logger.log(u"Unable to parse " + name + " into a scene name.", logger.DEBUG)   # pylint: disable=no-member
+        log.debug(u'Unable to parse {0} into a scene name.', name)
         return {}, ''
 
     regex = '(' + re.escape(show_name) + regex_string['episode'] % season + ')'
@@ -128,7 +133,7 @@ def save_nzb(nzb_name, nzb_string):
             nzb_fh.write(nzb_string)
 
     except EnvironmentError as error:
-        logger.log(u"Unable to save NZB: " + ex(error), logger.ERROR)  # pylint: disable=no-member
+        log.error(u'Unable to save NZB: {0}', ex(error))
 
 
 def strip_xmlns(element, xmlns):
@@ -156,14 +161,14 @@ def split_result(obj):
     # TODO: Check if this needs exception handling.
     url_data = session.get(obj.url).content
     if url_data is None:
-        logger.log(u"Unable to load url " + obj.url + ", can't download season NZB", logger.ERROR)
+        log.error(u'Unable to load url {0}, can\'t download season NZB', obj.url)
         return []
 
     # parse the season ep name
     try:
         parsed_obj = NameParser(series=obj.series).parse(obj.name)
     except (InvalidNameException, InvalidShowException) as error:
-        logger.log(u"{}".format(error), logger.DEBUG)
+        log.debug(u'{}', error)
         return []
 
     # bust it up
@@ -178,31 +183,31 @@ def split_result(obj):
     #   Maybe we should return the results found or possibly continue with the next iteration of the loop
     #   Also maybe turn this into a function and generate the results_list with a list comprehension instead
     for new_nzb in separate_nzbs:
-        logger.log(u"Split out " + new_nzb + " from " + obj.name, logger.DEBUG)  # pylint: disable=no-member
+        log.debug(u'Split out {new_nzb} from {name}', {'new_nzb': new_nzb, 'name': obj.name})
 
         # parse the name
         try:
             parsed_obj = NameParser(series=obj.series).parse(new_nzb)
         except (InvalidNameException, InvalidShowException) as error:
-            logger.log(u"{}".format(error), logger.DEBUG)
+            log.debug(u'{}', error)
             return []
 
         # make sure the result is sane
         if (parsed_obj.season_number != season) or (parsed_obj.season_number is None and season != 1):
             # pylint: disable=no-member
-            logger.log(u"Found " + new_nzb + " inside " + obj.name + " but it doesn't seem to belong to the same season, ignoring it",
-                       logger.WARNING)
+            log.warning(u'Found {new_nzb} inside {name} but it doesn\'t seem to belong to the same season, ignoring it',
+                        {'new_nzb': new_nzb, 'name': obj.name})
             continue
         elif not parsed_obj.episode_numbers:
             # pylint: disable=no-member
-            logger.log(u"Found " + new_nzb + " inside " + obj.name + " but it doesn't seem to be a valid episode NZB, ignoring it",
-                       logger.WARNING)
+            log.warning(u'Found {new_nzb} inside {name} but it doesn\'t seem to be a valid episode NZB, ignoring it',
+                        {'new_nzb': new_nzb, 'name': obj.name})
             continue
 
         want_ep = True
         for ep_num in parsed_obj.episode_numbers:
             if not obj.extraInfo[0].want_episode(season, ep_num, obj.quality):
-                logger.log(u"Ignoring result: " + new_nzb, logger.DEBUG)
+                log.debug(u'Ignoring result: {0}', new_nzb)
                 want_ep = False
                 break
         if not want_ep:
diff --git a/medusa/providers/generic_provider.py b/medusa/providers/generic_provider.py
--- a/medusa/providers/generic_provider.py
+++ b/medusa/providers/generic_provider.py
@@ -171,6 +171,7 @@ def _make_url(self, result):
 
         # TODO: Remove this in future versions, kept for the warning
         # Some NZB providers (e.g. Jackett) can also download torrents
+        # A similar check is performed for NZB splitting in medusa/search/core.py @ search_providers()
         if (result.url.endswith(GenericProvider.TORRENT) or
                 result.url.startswith('magnet:')) and self.provider_type == GenericProvider.NZB:
             filename = join(app.TORRENT_DIR, result_name + '.torrent')
diff --git a/medusa/search/core.py b/medusa/search/core.py
--- a/medusa/search/core.py
+++ b/medusa/search/core.py
@@ -729,7 +729,9 @@ def search_providers(series_obj, episodes, forced_search=False, down_cur_quality
                           best_season_result.provider.provider_type,
                           best_season_result.name)
             else:
-                if best_season_result.provider.provider_type == GenericProvider.NZB:
+                # Some NZB providers (e.g. Jackett) can also download torrents, but torrents cannot be split like NZB
+                if (best_season_result.provider.provider_type == GenericProvider.NZB and
+                        not best_season_result.url.endswith(GenericProvider.TORRENT)):
                     log.debug(u'Breaking apart the NZB and adding the individual ones to our results')
 
                     # if not, break it apart and add them as the lowest priority results


Test patch: