Repository: Flexget/Flexget

Issue:
TorrentDay search result empty or malformed
### Expected behaviour:

Search result
![image](https://user-images.githubusercontent.com/3293865/94644622-67c71500-031c-11eb-86d9-a9cd983dee1f.png)

### Actual behaviour:

Search result empty or malformed.

### Steps to reproduce:
- Step 1: run task

#### Config:
```yaml
  download-childrenshow-discover:
    template:
      - cartoon-metainfo
      - reject
      - children_show
      - notifyViaEmail
    discover:
      what:
        - next_series_seasons:
            from_start: yes
        - next_series_episodes:
            backfill: true
            from_start: yes
      from:
        - torrentday:
            uid: "'{? torrentday.uid ?}'"
            passkey: "{? torrentday.passkey ?}"
            cfduid: "{? torrentday.cfduid ?}"
            rss_key: "{? torrentday.rss_key ?}"
```
  
#### Log:
<details>
 <summary>(click to expand)</summary>

2020-09-30 12:39:49 VERBOSE  discover      download-childrenshow-discover Searching for `Vampirina S02` with plugin `torrentday` (1 of 7)
2020-09-30 12:39:49 DEBUG    utils.requests download-childrenshow-discover GETing URL https://www.torrentday.com/t with args () and kwargs {'params': {'cata': 'yes', 'c7': 1, 'clear-new': 1, 'q': 'Vampirina S02'}, 'cookies': {'uid': '...', 'pass': '...', '__cfduid': '...'}, 'allow_redirects': True, 'timeout': 30}
2020-09-30 12:39:50 ERROR    discover      download-childrenshow-discover Error searching with torrentday: Search returned by torrentday appears to be empty or malformed.
2020-09-30 12:39:50 VERBOSE  discover      download-childrenshow-discover No search results for `Vampirina S02`

</details>

### Additional information:

- FlexGet version: 3.1.71
- Python version: 3.5.1
- Installation method: pip install
- Using daemon (yes/no): yes
- OS and version: Synology DSM 6


Discussion:
This plugin was quite important for me, so I found the error that fixed this problem for me. Not sure how to submit a pull request properly, so I can either point you guys to the error, or submit a pull request if someone can help me :)
> This plugin was quite important for me, so I found the error that fixed this problem for me. Not sure how to submit a pull request properly, so I can either point you guys to the error, or submit a pull request if someone can help me :)

It is possible for you to share a solution in the comments you know... 

Seems they have made a minor change on page. Parsing of page should be rewritten to be more robust. This is how I solved it with current solution.
```
--- torrentday.py.org   2020-12-06 10:44:06.330641435 +0100
+++ torrentday.py       2020-12-06 10:44:45.283036912 +0100
@@ -137,7 +137,7 @@

             # the following should avoid table being None due to a malformed
             # html in td search results
-            soup = get_soup(page).contents[1].contents[1].next.next.nextSibling
+            soup = get_soup(page).contents[1].contents[1].contents[1].next.nextSibling
             table = soup.find('table', {'id': 'torrentTable'})
             if table is None:
                 raise PluginError(
```


If not familiar with git, forking, and such, editing the file directly on GitHub to quick and easily open a Pull Request is also a valid option.

1. Just [navigate to the file](https://github.com/Flexget/Flexget/blob/develop/flexget/components/sites/sites/torrentday.py)
2. Click the pencil icon above the text area
2. Change what's needed
3. Hop down to the "Propose changes" button
4. Double-check the changes to make sure only the intended lines got changed
5. Click the "Open Pulll Request" button on top
6. Fill in the template to help the team evaluate the proposed changes
7. Done :)

Resolving patch:
diff --git a/flexget/components/sites/sites/torrentday.py b/flexget/components/sites/sites/torrentday.py
--- a/flexget/components/sites/sites/torrentday.py
+++ b/flexget/components/sites/sites/torrentday.py
@@ -18,6 +18,7 @@
 CATEGORIES = {
     'all': 0,
     # Movies
+    'mov4k': 96,
     'mov480p': 25,
     'movHD': 11,
     'movBD': 5,
@@ -34,6 +35,7 @@
     'tvDVD': 31,
     'tvDVDrip': 33,
     'tvMOBILE': 46,
+    'tvNonEnglish': 82,
     'tvPACKS': 14,
     'tvSDx264': 26,
     'tvHDx264': 7,
@@ -53,16 +55,16 @@ class UrlRewriteTorrentday:
           rss_key: xxxxxxxxx  (required)    get this from your profile page
           category: xxxxxxxx
 
-          Category can be one of 
+          Category can be one of
             ID from browsing site OR 'name'
             movies:
-              mov480p, movHD, movBD, movDVD,
+              mov4k, mov480p, movHD, movBD, movDVD,
               movMP4, movNonEnglish, movPACKS,
               movSDx264, movX265, movXVID
             tv:
               tv480p, tvBRD, tvDVD, tvDVDrip,
-              tvMOBILE, tvPACKS, tvSDx264, 
-              tvHDx264, tvX265, tvXVID
+              tvMOBILE, tvNonEnglish, tvPACKS,
+              tvSDx264, tvHDx264, tvX265, tvXVID
     """
 
     schema = {
@@ -114,11 +116,9 @@ def search(self, task, entry, config=None):
             categories = [categories]
         # If there are any text categories, turn them into their id number
         categories = [c if isinstance(c, int) else CATEGORIES[c] for c in categories]
-        params = {
-            'cata': 'yes',
-            'c{}'.format(','.join(str(c) for c in categories)): 1,
-            'clear-new': 1,
-        }
+        params = {'cata': 'yes', 'clear-new': 1}
+        params.update({str(c): 1 for c in categories})
+
         entries = set()
         for search_string in entry.get('search_strings', [entry['title']]):
 
@@ -137,7 +137,7 @@ def search(self, task, entry, config=None):
 
             # the following should avoid table being None due to a malformed
             # html in td search results
-            soup = get_soup(page).contents[1].contents[1].next.next.nextSibling
+            soup = get_soup(page).contents[1].contents[1].contents[1].next.nextSibling
             table = soup.find('table', {'id': 'torrentTable'})
             if table is None:
                 raise PluginError(


Test patch: