Repository: Flexget/Flexget

Issue:
time.clock DeprecationWarning under python3.7
### Expected behaviour:
This isnt a breaking issue as such, but it potentially will be in python 3.8 when time.clock is deprecated
for now it just fills your logs with 
```
Dec 08 00:27:55 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
Dec 08 00:27:55 citadel flexget[1765]:   start = time.clock()
```

### Actual behaviour:

### Steps to reproduce:
- Step 1: install flexget under python 3.7
- Ster 2: invoke either method from ParserInternal in `flexget/plugins/parsers/parser_internal.py`

#### Config:
<details>
 <summary>(click to expand)</summary>

```
tasks:
  Movies:
    exists_movie: 
      path: /mnt/raid/Movies
      lookup: imdb
      allow_different_qualities: better
    imdb_lookup: yes
    html:
      url: https://thepiratebay.org/top/207
      title_from: url
      links_re: [ magnet ]
    proper_movies: yes
    quality:
      - 1080p+
      - h264+
      - dvdrip+
    seen_movies:
      scope: local
    regexp:
      accept:
        - '2018'
        - '2017'
        - '2016'
        - '2015'
        - '2014'
        - 1080p
        - BRRip
        - DvdRip
        - BluRay
      reject:
        - Hindi
    template: 
      - deluge_settings
      - piratebay_manipulate

  TvShows:
    exists_series: 
      - /mnt/raid/TvShows/
      - /mnt/raid/Movies/
    template: deluge_settings
    series:
      shows:
        - 13 Reasons Why
        - Shooter
        - Silicon Valley
        - Mr Robot
        - Game of Thrones
        - Vikings
        - Wanted
        - This is us
        - Breaking Bad
        - Archer
        - Orphan Black
        - Continuum
        - Narcos
        - House of Cards
        - Stranger Things
        - Wire
        - The Big Bang Theory
    discover:
      interval: 1 hour
      release_estimations: loose
      what:
        - next_series_episodes: yes
      from:
        - piratebay:
            category: tv
            sort_by: seeds  
    set:
      movedone: "/mnt/raid/TvShows/{{series_name}}/Season {{series_season}}/"
      path: "/mnt/raid/TvShows/{{series_name}}/Season {{series_season}}/"

templates:
  deluge_settings:
    deluge:
      username: localclient
      password: <some_hash>

  piratebay_manipulate:
    manipulate:
      - title:
          from: url
          extract: '&dn=(.*?)&tr=udp'
      - title:
          replace:
            regexp: '\+'
            format: ' '

schedules:
  - tasks: '*'
    interval:
      hours: 1
```

</details>
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:37: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   end = time.clock()
Dec 08 00:33:19 citadel flexget[1765]: /usr/lib/python3.7/site-packages/flexget/plugins/parsers/parser_internal.py:23: DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be r>
Dec 08 00:33:19 citadel flexget[1765]:   start = time.clock()
```

</details>

### Additional information:

- FlexGet version: 2.17.18.dev
- Python version: Python 3.7.1 (default, Oct 22 2018, 10:41:28) 
- Installation method: AUR package[flexget-git] (Arch Linux) built from the latest git commit
- Using daemon (yes/no): yes
- OS and version: Arch Linux... latest? lol


Discussion:

Resolving patch:
diff --git a/flexget/plugins/filter/series.py b/flexget/plugins/filter/series.py
--- a/flexget/plugins/filter/series.py
+++ b/flexget/plugins/filter/series.py
@@ -41,6 +41,12 @@
 Base = db_schema.versioned_base('series', SCHEMA_VER)
 
 
+try:
+    preferred_clock = time.process_time
+except AttributeError:
+    preferred_clock = time.clock
+
+
 @db_schema.upgrade('series')
 def upgrade(ver, session):
     if ver is None:
@@ -1606,7 +1612,7 @@ def on_task_metainfo(self, task, config):
 
         parser = get_plugin_by_name('parsing').instance
 
-        start_time = time.clock()
+        start_time = preferred_clock()
 
         # Sort Entries into data model similar to https://en.wikipedia.org/wiki/Trie
         # Only process series if both the entry title and series title first letter match
@@ -1648,7 +1654,7 @@ def on_task_metainfo(self, task, config):
                 if entries:
                     self.parse_series(entries, series_name, series_config, db_identified_by)
 
-        log.debug('series on_task_metainfo took %s to parse', time.clock() - start_time)
+        log.debug('series on_task_metainfo took %s to parse', preferred_clock() - start_time)
 
     def on_task_filter(self, task, config):
         """Filter series"""
@@ -1673,7 +1679,7 @@ def on_task_filter(self, task, config):
             # Expunge so we can work on de-attached while processing the series to minimize db locks
             session.expunge_all()
 
-        start_time = time.clock()
+        start_time = preferred_clock()
         for series_item in config:
             with Session() as session:
                 series_name, series_config = list(series_item.items())[0]
@@ -1734,7 +1740,7 @@ def on_task_filter(self, task, config):
 
                 self.process_series(task, series_entries, series_config)
 
-        log.debug('processing series took %s', time.clock() - start_time)
+        log.debug('processing series took %s', preferred_clock() - start_time)
 
     def parse_series(self, entries, series_name, config, db_identified_by=None):
         """
diff --git a/flexget/plugins/parsers/parser_guessit.py b/flexget/plugins/parsers/parser_guessit.py
--- a/flexget/plugins/parsers/parser_guessit.py
+++ b/flexget/plugins/parsers/parser_guessit.py
@@ -57,6 +57,12 @@ def normalize_component(data):
     return [data.lower().replace('-', '')]
 
 
+try:
+    preferred_clock = time.process_time
+except AttributeError:
+    preferred_clock = time.clock
+
+
 class ParserGuessit(object):
     SOURCE_MAP = {
         'Camera': 'cam',
@@ -168,7 +174,7 @@ def _quality(self, guessit_result):
     # movie_parser API
     def parse_movie(self, data, **kwargs):
         log.debug('Parsing movie: `%s` [options: %s]', data, kwargs)
-        start = time.clock()
+        start = preferred_clock()
         guessit_options = self._guessit_options(kwargs)
         guessit_options['type'] = 'movie'
         guess_result = guessit_api.guessit(data, options=guessit_options)
@@ -182,8 +188,7 @@ def parse_movie(self, data, **kwargs):
             release_group=guess_result.get('release_group'),
             valid=bool(guess_result.get('title'))  # It's not valid if it didn't find a name, which sometimes happens
         )
-        end = time.clock()
-        log.debug('Parsing result: %s (in %s ms)', parsed, (end - start) * 1000)
+        log.debug('Parsing result: %s (in %s ms)', parsed, (preferred_clock() - start) * 1000)
         return parsed
 
     # series_parser API
@@ -200,7 +205,7 @@ def parse_series(self, data, **kwargs):
             guessit_options['expected_title'] = ['re:' + title for title in expected_titles]
         if kwargs.get('id_regexps'):
             guessit_options['id_regexps'] = kwargs.get('id_regexps')
-        start = time.clock()
+        start = preferred_clock()
         # If no series name is provided, we don't tell guessit what kind of match we are looking for
         # This prevents guessit from determining that too general of matches are series
         parse_type = 'episode' if kwargs.get('name') else None
@@ -339,8 +344,7 @@ def parse_series(self, data, **kwargs):
             valid=valid
         )
 
-        end = time.clock()
-        log.debug('Parsing result: %s (in %s ms)', parsed, (end - start) * 1000)
+        log.debug('Parsing result: %s (in %s ms)', parsed, (preferred_clock() - start) * 1000)
         return parsed
 
     # TODO: The following functions are sort of legacy. No idea if they should be changed.
diff --git a/flexget/plugins/parsers/parser_internal.py b/flexget/plugins/parsers/parser_internal.py
--- a/flexget/plugins/parsers/parser_internal.py
+++ b/flexget/plugins/parsers/parser_internal.py
@@ -14,13 +14,20 @@
 log = logging.getLogger('parser_internal')
 
 
+try:
+    preferred_clock = time.process_time
+except AttributeError:
+    preferred_clock = time.clock
+
+
 class ParserInternal(object):
+
     # movie_parser API
 
     @plugin.priority(1)
     def parse_movie(self, data, **kwargs):
         log.debug('Parsing movie: `%s` kwargs: %s', data, kwargs)
-        start = time.clock()
+        start = preferred_clock()
         parser = MovieParser()
         try:
             parser.parse(data)
@@ -34,15 +41,14 @@ def parse_movie(self, data, **kwargs):
             proper_count=parser.proper_count,
             valid=bool(parser.name)
         )
-        end = time.clock()
-        log.debug('Parsing result: %s (in %s ms)', parser, (end - start) * 1000)
+        log.debug('Parsing result: %s (in %s ms)', parser, (preferred_clock() - start) * 1000)
         return result
 
     # series_parser API
     @plugin.priority(1)
     def parse_series(self, data, **kwargs):
         log.debug('Parsing series: `%s` kwargs: %s', data, kwargs)
-        start = time.clock()
+        start = preferred_clock()
         parser = SeriesParser(**kwargs)
         try:
             parser.parse(data)
@@ -65,8 +71,7 @@ def parse_series(self, data, **kwargs):
             strict_name=parser.strict_name,
             identified_by=parser.identified_by
         )
-        end = time.clock()
-        log.debug('Parsing result: %s (in %s ms)', parser, (end - start) * 1000)
+        log.debug('Parsing result: %s (in %s ms)', parser, (preferred_clock() - start) * 1000)
         return result
 
 


Test patch: