Browse Source

Add config option for broadcast heartbeat

Cammy 6 years ago
parent
commit
2f14c1d0a6
6 changed files with 24 additions and 3 deletions
  1. 3 0
      MOREHELP.md
  2. 1 0
      README.md
  3. 1 0
      pyinstalive/constants.py
  4. 7 3
      pyinstalive/dlfuncs.py
  5. 2 0
      pyinstalive/pil.py
  6. 10 0
      pyinstalive/startup.py

+ 3 - 0
MOREHELP.md

@@ -44,6 +44,7 @@ run_at_start =
 run_at_finish =
 run_at_finish =
 use_locks = True
 use_locks = True
 clear_temp_files = False
 clear_temp_files = False
+do_heartbeat = True
 ```
 ```
 
 
 ```username```  **—**  Instagram username to login with.
 ```username```  **—**  Instagram username to login with.
@@ -71,3 +72,5 @@ clear_temp_files = False
 ```use_locks```  **—**  When set to true, PyInstaLive will create several .lock files to prevent duplicate downloads from starting for the same user if you are running PyInstaLive using some form of automation such as batch/shell loops.
 ```use_locks```  **—**  When set to true, PyInstaLive will create several .lock files to prevent duplicate downloads from starting for the same user if you are running PyInstaLive using some form of automation such as batch/shell loops.
 
 
 ```clear_temp_files```  **—**  When set to True, PyInstaLive will delete all temporary files that were downloaded as well as the folders which contained these files. Replay folders created by PyInstaLive will not be deleted because they are used to determine if a replay has already been downloaded.
 ```clear_temp_files```  **—**  When set to True, PyInstaLive will delete all temporary files that were downloaded as well as the folders which contained these files. Replay folders created by PyInstaLive will not be deleted because they are used to determine if a replay has already been downloaded.
+
+```do_heartbeat```  **—**  When set to True, PyInstaLive will check the livestream's active status. If set to False no checks will be conducted, and the logged in user will not show up as a viewer during the livestream. May cause degraded performance.

+ 1 - 0
README.md

@@ -101,6 +101,7 @@ run_at_start =
 run_at_finish =
 run_at_finish =
 use_locks = True
 use_locks = True
 clear_temp_files = False
 clear_temp_files = False
+do_heartbeat = True
 ```
 ```
 
 
 #### Example
 #### Example

+ 1 - 0
pyinstalive/constants.py

@@ -19,4 +19,5 @@ run_at_start =
 run_at_finish =
 run_at_finish =
 use_locks = True
 use_locks = True
 clear_temp_files = False
 clear_temp_files = False
+do_heartbeat = False
     """
     """

+ 7 - 3
pyinstalive/dlfuncs.py

@@ -176,7 +176,8 @@ def merge_segments():
 def download_livestream():
 def download_livestream():
     try:
     try:
         def print_status(sep=True):
         def print_status(sep=True):
-            heartbeat_info = pil.ig_api.broadcast_heartbeat_and_viewercount(pil.livestream_obj.get('id'))
+            if pil.do_heartbeat:
+                heartbeat_info = pil.ig_api.broadcast_heartbeat_and_viewercount(pil.livestream_obj.get('id'))
             viewers = pil.livestream_obj.get('viewer_count', 0)
             viewers = pil.livestream_obj.get('viewer_count', 0)
             if sep:
             if sep:
                 logger.separator()
                 logger.separator()
@@ -184,8 +185,11 @@ def download_livestream():
                 logger.info('Username    : {:s}'.format(pil.dl_user))
                 logger.info('Username    : {:s}'.format(pil.dl_user))
             logger.info('Viewers     : {:s} watching'.format(str(int(viewers))))
             logger.info('Viewers     : {:s} watching'.format(str(int(viewers))))
             logger.info('Airing time : {:s}'.format(get_stream_duration(0)))
             logger.info('Airing time : {:s}'.format(get_stream_duration(0)))
-            logger.info('Status      : {:s}'.format(heartbeat_info.get('broadcast_status').title()))
-            return heartbeat_info.get('broadcast_status') not in ['active', 'interrupted']
+            if pil.do_heartbeat:
+                logger.info('Status      : {:s}'.format(heartbeat_info.get('broadcast_status').title()))
+                return heartbeat_info.get('broadcast_status') not in ['active', 'interrupted']
+            else:
+                return None
 
 
         mpd_url = (pil.livestream_obj.get('dash_manifest')
         mpd_url = (pil.livestream_obj.get('dash_manifest')
                    or pil.livestream_obj.get('dash_abr_playback_url')
                    or pil.livestream_obj.get('dash_abr_playback_url')

+ 2 - 0
pyinstalive/pil.py

@@ -42,6 +42,7 @@ def initialize():
     global ffmpeg_path
     global ffmpeg_path
     global clear_temp_files
     global clear_temp_files
     global has_guest
     global has_guest
+    global do_heartbeat
     ig_api = None
     ig_api = None
     ig_user = ""
     ig_user = ""
     ig_pass = ""
     ig_pass = ""
@@ -72,3 +73,4 @@ def initialize():
     ffmpeg_path = None
     ffmpeg_path = None
     clear_temp_files = False
     clear_temp_files = False
     has_guest = None
     has_guest = None
+    do_heartbeat = False

+ 10 - 0
pyinstalive/startup.py

@@ -117,6 +117,16 @@ def validate_inputs(config, args, unknown_args):
         else:
         else:
             pil.clear_temp_files = False
             pil.clear_temp_files = False
 
 
+        if helpers.bool_str_parse(config.get('pyinstalive', 'do_heartbeat')) == "Invalid":
+            pil.do_heartbeat = True
+            error_arr.append(['do_heartbeat', 'True'])
+        elif helpers.bool_str_parse(config.get('pyinstalive', 'do_heartbeat')):
+            pil.do_heartbeat = True
+        else:
+            pil.do_heartbeat = False
+            logger.warn("Getting livestream heartbeat disabled, this may cause degraded performance.")
+            logger.separator()
+
         if not args.nolives and helpers.bool_str_parse(config.get('pyinstalive', 'download_lives')) == "Invalid":
         if not args.nolives and helpers.bool_str_parse(config.get('pyinstalive', 'download_lives')) == "Invalid":
             pil.dl_lives = True
             pil.dl_lives = True
             error_arr.append(['download_lives', 'True'])
             error_arr.append(['download_lives', 'True'])