Przeglądaj źródła

Merge branch 'master' into master

Cammy 6 lat temu
rodzic
commit
75236fb496

+ 3 - 3
.github/issue_template.md

@@ -2,7 +2,7 @@
 #### Check the boxes below by filling `[ ]` with an `x` so it looks like `[x]`.
 #### Check the boxes below by filling `[ ]` with an `x` so it looks like `[x]`.
 #### Use the Preview button to ensure the template is filled in correctly.
 #### Use the Preview button to ensure the template is filled in correctly.
 ##
 ##
-- [ ] I am using the latest version of PyInstaLive: 3.1.1.
+- [ ] I am using the latest version of PyInstaLive: 3.1.3.
 - [ ] I have installed either Python 2.7.x or 3.5+: `YOUR VERSION HERE`
 - [ ] I have installed either Python 2.7.x or 3.5+: `YOUR VERSION HERE`
 - [ ] I have read the [README](https://github.com/notcammy/pyinstalive/blob/master/README.md).
 - [ ] I have read the [README](https://github.com/notcammy/pyinstalive/blob/master/README.md).
 - [ ] I have read the [FAQ](https://github.com/notcammy/pyinstalive/blob/master/FAQ.md).
 - [ ] I have read the [FAQ](https://github.com/notcammy/pyinstalive/blob/master/FAQ.md).
@@ -27,11 +27,11 @@ Run ```pyinstalive --info``` and paste its output below. Don't forget to omit yo
 ```bash
 ```bash
 $ pyinstalive --info
 $ pyinstalive --info
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
-[I] PYINSTALIVE (SCRIPT V3.1.1 - PYTHON V3.6.3) - 01-02-2019 07:00:17 PM
+[I] PYINSTALIVE (SCRIPT V3.1.3 - PYTHON V3.6.3) - 01-02-2019 07:00:17 PM
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 [I] To see all the available arguments, use the -h argument.
 [I] To see all the available arguments, use the -h argument.
 
 
-[I] PyInstaLive version:        3.1.1
+[I] PyInstaLive version:        3.1.3
 [I] Python version:             3.6.3
 [I] Python version:             3.6.3
 [I] FFmpeg framework:           Available
 [I] FFmpeg framework:           Available
 [I] Cookie files:               2 (johndoe.json matches config user)
 [I] Cookie files:               2 (johndoe.json matches config user)

+ 2 - 0
.gitignore

@@ -63,3 +63,5 @@ pildev/
 
 
 *.txt

 *.txt

 venv/
 venv/
+
+\.vscode/\.ropeproject/

+ 6 - 6
README.md

@@ -1,5 +1,5 @@
 # PyInstaLive
 # PyInstaLive
-![Version 3.1.1](https://img.shields.io/badge/Version-3.1.1-orange.svg)
+![Version 3.1.3](https://img.shields.io/badge/Version-3.1.3-orange.svg)
 ![Python 2.7, 3.5](https://img.shields.io/badge/Python-2.7%2C%203.5%2B-3776ab.svg)
 ![Python 2.7, 3.5](https://img.shields.io/badge/Python-2.7%2C%203.5%2B-3776ab.svg)
 
 
 This Python script enables you to download any ongoing Instagram livestreams as well as any available replays. It is based on [another script](https://github.com/taengstagram/instagram-livestream-downloader) that has now been discontinued.
 This Python script enables you to download any ongoing Instagram livestreams as well as any available replays. It is based on [another script](https://github.com/taengstagram/instagram-livestream-downloader) that has now been discontinued.
@@ -50,21 +50,21 @@ Make sure all tools are accessible via command line (added to your PATH if on Wi
 
 
 ## Installation
 ## Installation
 
 
-*Tip — To install PyInstaLive with the latest commit changes, remove the version tag from the install command (e.g. **@3.1.1**).*
+*Tip — To install PyInstaLive with the latest commit changes, remove the version tag from the install command (e.g. **@3.1.3**).*
 
 
 #### Installing
 #### Installing
 
 
 Run the following command in your command line (might need to be run as administrator on Windows):
 Run the following command in your command line (might need to be run as administrator on Windows):
 ```bash
 ```bash
-pip install git+https://github.com/notcammy/PyInstaLive.git@3.1.1 --process-dependency-links
+pip install git+https://github.com/notcammy/PyInstaLive.git@3.1.3 --process-dependency-links
 ```
 ```
 
 
 #### Updating
 #### Updating
 
 
-To update PyInstaLive to the latest version (currently **3.1.1**) run the following command:
+To update PyInstaLive to the latest version (currently **3.1.3**) run the following command:
 
 
 ```bash
 ```bash
-pip install git+https://github.com/notcammy/PyInstaLive.git@3.1.1 --process-dependency-links --upgrade
+pip install git+https://github.com/notcammy/PyInstaLive.git@3.1.3 --process-dependency-links --upgrade
 ```
 ```
 
 
 #### Specific versions
 #### Specific versions
@@ -122,7 +122,7 @@ Below is an example of PyInstaLive's output after downloading a livestream:
 > pyinstalive -d "janedoe"
 > pyinstalive -d "janedoe"
 
 
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
-[I] PYINSTALIVE (SCRIPT V3.1.1 - PYTHON V3.6.3) - 01-02-2019 06:56:29 PM
+[I] PYINSTALIVE (SCRIPT V3.1.3 - PYTHON V3.6.3) - 01-02-2019 06:56:29 PM
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 [I] Successfully logged into account: johndoe
 [I] Successfully logged into account: johndoe
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------

+ 2 - 2
pyinstalive/comments.py

@@ -123,7 +123,7 @@ class CommentsDownloader(object):
         python_version = sys.version.split(' ')[0]
         python_version = sys.version.split(' ')[0]
         comments_timeline = {}
         comments_timeline = {}
         wide_build = sys.maxunicode > 65536
         wide_build = sys.maxunicode > 65536
-        for i, c in enumerate(comments):
+        for c in comments:
             if 'offset' in c:
             if 'offset' in c:
                 for k in c.get('comment').keys():
                 for k in c.get('comment').keys():
                     c[k] = c.get('comment', {}).get(k)
                     c[k] = c.get('comment', {}).get(k)
@@ -138,7 +138,7 @@ class CommentsDownloader(object):
             total_comments = 0
             total_comments = 0
             timestamps = sorted(comments_timeline.keys())
             timestamps = sorted(comments_timeline.keys())
             subs = []
             subs = []
-            for i, tc in enumerate(timestamps):
+            for tc in timestamps:
                 t = comments_timeline[tc]
                 t = comments_timeline[tc]
                 clip_start = int(tc) - int(download_start_time) + int(comments_delay)
                 clip_start = int(tc) - int(download_start_time) + int(comments_delay)
                 if clip_start < 0:
                 if clip_start < 0:

+ 1 - 1
pyinstalive/constants.py

@@ -2,7 +2,7 @@ import sys
 
 
 
 
 class Constants:
 class Constants:
-    SCRIPT_VER = "3.1.1"
+    SCRIPT_VER = "3.1.3"
     PYTHON_VER = sys.version.split(' ')[0]
     PYTHON_VER = sys.version.split(' ')[0]
     CONFIG_TEMPLATE = """
     CONFIG_TEMPLATE = """
 [pyinstalive]
 [pyinstalive]

+ 16 - 11
pyinstalive/dlfuncs.py

@@ -51,7 +51,7 @@ def get_stream_duration(duration_type):
         if stream_started_secs:
         if stream_started_secs:
             stream_duration_str += ' and %d seconds' % stream_started_secs
             stream_duration_str += ' and %d seconds' % stream_started_secs
         return stream_duration_str
         return stream_duration_str
-    except Exception as e:
+    except Exception:
         return "Not available"
         return "Not available"
 
 
 
 
@@ -110,6 +110,9 @@ def get_broadcasts_info():
             return True
             return True
         else:
         else:
             return False
             return False
+    except ClientThrottledError:
+        logger.error('Could not check because you are making too many requests at this time.')
+        return False
     except Exception as e:
     except Exception as e:
         logger.error('Could not finish checking: {:s}'.format(str(e)))
         logger.error('Could not finish checking: {:s}'.format(str(e)))
         if "timed out" in str(e):
         if "timed out" in str(e):
@@ -119,10 +122,7 @@ def get_broadcasts_info():
                          'again.')
                          'again.')
         return False
         return False
     except KeyboardInterrupt:
     except KeyboardInterrupt:
-        logger.binfo('Aborted checking for livestreams and replays, exiting.'.format(pil.dl_user))
-        return False
-    except ClientThrottledError as cte:
-        logger.error('Could not check because you are making too many requests at this time.')
+        logger.binfo('Aborted checking for livestreams and replays, exiting.')
         return False
         return False
 
 
 
 
@@ -296,13 +296,18 @@ def download_replays():
         for replay_index, replay_obj in enumerate(pil.replays_obj):
         for replay_index, replay_obj in enumerate(pil.replays_obj):
             exists = False
             exists = False
             pil.livestream_obj = replay_obj
             pil.livestream_obj = replay_obj
-            if Constants.PYTHON_VER[0][0] == '2':
-                directories = (os.walk(pil.dl_path).next()[1])
-            else:
-                directories = (os.walk(pil.dl_path).__next__()[1])
+            dl_path_files = os.listdir(pil.dl_path)
+
+            if pil.verbose:
+                logger.separator()
+                logger.plain("Listing contents of the folder '{}':".format(pil.dl_path))
+                for dl_path_file in dl_path_files:
+                    logger.plain(dl_path_file)
+                logger.separator()
+                logger.separator()
 
 
-            for directory in directories:
-                if (str(replay_obj.get('id')) in directory) and ("_live_" not in directory):
+            for dl_path_file in dl_path_files:
+                if (str(replay_obj.get('id')) in dl_path_file) and ("_live_" not in dl_path_file) and (dl_path_file.endswith(".mp4")):
                     logger.binfo("Already downloaded a replay with ID '{:s}'.".format(str(replay_obj.get('id'))))
                     logger.binfo("Already downloaded a replay with ID '{:s}'.".format(str(replay_obj.get('id'))))
                     exists = True
                     exists = True
             if not exists:
             if not exists:

+ 116 - 115
pyinstalive/organize.py

@@ -1,115 +1,116 @@
-import os
-import shutil
-from datetime import datetime
-import time
-try:
-    import pil
-    import logger
-except ImportError:
-    from . import pil
-    from . import logger
-
-def organize_videos():
-
-    try:
-        # Make a variable equal to the names of the files in the current directory.
-        download_path_files = os.listdir(pil.dl_path)
-
-        # Count the amount of files moved and not moved because they already exist etc.
-        not_moved = 0
-        has_moved = 0
-
-        # The downloaded livestream(s) are in MP4 format.
-        video_format = ['mp4']
-
-        # Find the MP4 files and save them in a variable called 'filenames'.
-        filenames = [filename for filename in download_path_files
-            if filename.split('.')[-1] in video_format]
-        
-        if len(filenames) == 0:
-            print("No MP4 files in the current directory.")
-            return
-
-        for filename in filenames:
-            # Split the filenames into parts.
-            filename_parts = filename.split('_')
-
-            # Get the date from the filename.
-            date = datetime.strptime(filename_parts[0], '%Y%m%d').strftime('%d-%m-%Y')
-
-            # Get the username from the filename. 
-            username = '_'.join(filename_parts[1:-3])
-
-            # Get the time from the unix timestamp.
-            time_from_unix_timestamp = time.strftime('%I.%M%p', time.localtime(int(filename_parts[-2])))
-
-            # # Remove the leading zero from single-digit hours.
-            if float(time_from_unix_timestamp[0:2]) < 10:
-                time_from_unix_timestamp = time_from_unix_timestamp[1:]
-
-            # Get the last part of the filename ("live.mp4" or "replay.mp4").
-            live_or_replay = filename_parts[-1]
-            
-            # The path of each original filename is as follows:
-            old_filename_path = os.path.join(pil.dl_path, filename)
-
-            # We want to change the format of each filename to:
-            new_filename_format = date + " " + username + " [" + time_from_unix_timestamp + "] " + live_or_replay
-
-            # The path of each new filename is as follows:
-            new_filename_path = os.path.join(pil.dl_path, new_filename_format)
-
-            # Change the filenames.
-            os.rename(old_filename_path, new_filename_path)
-
-        # Now that the files have been renamed, we need to rescan the files in the directory.
-        download_path_files = os.listdir(pil.dl_path)
-
-        new_filenames = [filename for filename in download_path_files if filename.split('.')[-1] in video_format]
-        
-        # We want a dictionary where the filenames are the keys
-        # and the usernames are the values.
-        filenames_to_usernames = {}
-
-        # Populate the dictionary with a loop.
-        for filename in new_filenames:
-            # Split the filenames into parts so we get just the usernames:
-            filename_parts = filename.split()
-            # This is how to get the usernames from the split filenames:
-            username = filename_parts[1]
-            # Filename = key and username = value:
-            filenames_to_usernames[filename] = username
-    
-        # We only want one folder for each username, so convert the list into a set to remove duplicates.
-        usernames = set(filenames_to_usernames.values())
-
-        # Make a folder for each username.
-        for username in usernames:
-            username_path = os.path.join(pil.dl_path, username)
-            if not os.path.isdir(username_path):
-                os.mkdir(username_path)
-
-        # Move the videos into the folders
-        for filename, username in filenames_to_usernames.items():
-            filename_base = os.path.basename(filename)
-            source_path = os.path.join(pil.dl_path, filename)
-            destination_path = os.path.join(pil.dl_path, username, filename_base)
-            if not os.path.isfile(destination_path):
-                try:
-                    shutil.move(source_path, destination_path)
-                    logger.info("Moved '{:s}' successfully.".format(filename_base))
-                    has_moved += 1
-                except OSError as oe:
-                    logger.warn("Could not move {:s}: {:s}".format(filename_base, str(oe)))
-                    not_moved += 1
-            else:
-                logger.binfo("Did not move '{:s}' because it already exists.".format(filename_base))
-                not_moved += 1
-
-        logger.separator()
-        logger.info("{} {} moved.".format(has_moved, "file was" if has_moved == 1 else "files were"))
-        if not_moved:
-            logger.binfo("{} {} not moved.".format(not_moved, "file was" if not_moved == 1 else "files were"))
-        logger.separator()
-    except Exception as e:
-        logger.error("Could not organize files: {:s}".format(str(e)))
+import os
+import shutil
+from datetime import datetime
+import time
+try:
+    import pil
+    import logger
+except ImportError:
+    from . import pil
+    from . import logger
+
+def organize_videos():
+
+    try:
+        # Make a variable equal to the names of the files in the current directory.
+        download_path_files = os.listdir(pil.dl_path)
+
+        # Count the amount of files moved and not moved because they already exist etc.
+        not_moved = 0
+        has_moved = 0
+
+        # The downloaded livestream(s) are in MP4 format.
+        video_format = ['mp4']
+
+        # Find the MP4 files and save them in a variable called 'filenames'.
+        filenames = [filename for filename in download_path_files
+            if filename.split('.')[-1] in video_format]
+        
+        if len(filenames) == 0:
+            logger.binfo("No files were found to organize.")
+            logger.separator()
+            return
+
+        for filename in filenames:
+            # Split the filenames into parts.
+            filename_parts = filename.split('_')
+
+            # Get the date from the filename.
+            date = datetime.strptime(filename_parts[0], '%Y%m%d').strftime('%d-%m-%Y')
+
+            # Get the username from the filename. 
+            username = '_'.join(filename_parts[1:-3])
+
+            # Get the time from the unix timestamp.
+            time_from_unix_timestamp = time.strftime('%I.%M%p', time.localtime(int(filename_parts[-2])))
+
+            # # Remove the leading zero from single-digit hours.
+            if float(time_from_unix_timestamp[0:2]) < 10:
+                time_from_unix_timestamp = time_from_unix_timestamp[1:]
+
+            # Get the last part of the filename ("live.mp4" or "replay.mp4").
+            live_or_replay = filename_parts[-1]
+            
+            # The path of each original filename is as follows:
+            old_filename_path = os.path.join(pil.dl_path, filename)
+
+            # We want to change the format of each filename to:
+            new_filename_format = date + " " + username + " [" + time_from_unix_timestamp + "] " + live_or_replay
+
+            # The path of each new filename is as follows:
+            new_filename_path = os.path.join(pil.dl_path, new_filename_format)
+
+            # Change the filenames.
+            os.rename(old_filename_path, new_filename_path)
+
+        # Now that the files have been renamed, we need to rescan the files in the directory.
+        download_path_files = os.listdir(pil.dl_path)
+
+        new_filenames = [filename for filename in download_path_files if filename.split('.')[-1] in video_format]
+        
+        # We want a dictionary where the filenames are the keys
+        # and the usernames are the values.
+        filenames_to_usernames = {}
+
+        # Populate the dictionary with a loop.
+        for filename in new_filenames:
+            # Split the filenames into parts so we get just the usernames:
+            filename_parts = filename.split()
+            # This is how to get the usernames from the split filenames:
+            username = filename_parts[1]
+            # Filename = key and username = value:
+            filenames_to_usernames[filename] = username
+    
+        # We only want one folder for each username, so convert the list into a set to remove duplicates.
+        usernames = set(filenames_to_usernames.values())
+
+        # Make a folder for each username.
+        for username in usernames:
+            username_path = os.path.join(pil.dl_path, username)
+            if not os.path.isdir(username_path):
+                os.mkdir(username_path)
+
+        # Move the videos into the folders
+        for filename, username in filenames_to_usernames.items():
+            filename_base = os.path.basename(filename)
+            source_path = os.path.join(pil.dl_path, filename)
+            destination_path = os.path.join(pil.dl_path, username, filename_base)
+            if not os.path.isfile(destination_path):
+                try:
+                    shutil.move(source_path, destination_path)
+                    logger.info("Moved '{:s}' successfully.".format(filename_base))
+                    has_moved += 1
+                except OSError as oe:
+                    logger.warn("Could not move {:s}: {:s}".format(filename_base, str(oe)))
+                    not_moved += 1
+            else:
+                logger.binfo("Did not move '{:s}' because it already exists.".format(filename_base))
+                not_moved += 1
+
+        logger.separator()
+        logger.info("{} {} moved.".format(has_moved, "file was" if has_moved == 1 else "files were"))
+        if not_moved:
+            logger.binfo("{} {} not moved.".format(not_moved, "file was" if not_moved == 1 else "files were"))
+        logger.separator()
+    except Exception as e:
+        logger.error("Could not organize files: {:s}".format(str(e)))

+ 7 - 5
pyinstalive/startup.py

@@ -33,10 +33,6 @@ def validate_inputs(config, args, unknown_args):
     try:
     try:
         config.read(pil.config_path)
         config.read(pil.config_path)
 
 
-        if args.organize:
-            organize.organize_videos()
-            return False
-
         if args.download:
         if args.download:
             pil.dl_user = args.download
             pil.dl_user = args.download
             if args.downloadfollowing or args.batchfile:
             if args.downloadfollowing or args.batchfile:
@@ -44,7 +40,7 @@ def validate_inputs(config, args, unknown_args):
                 logger.warn("Please use only one download method. Use -h for more information.")
                 logger.warn("Please use only one download method. Use -h for more information.")
                 logger.separator()
                 logger.separator()
                 return False
                 return False
-        elif not args.clean and not args.info and not args.assemble and not args.downloadfollowing and not args.batchfile:
+        elif not args.clean and not args.info and not args.assemble and not args.downloadfollowing and not args.batchfile and not args.organize:
             logger.banner()
             logger.banner()
             logger.error("Please use a download method. Use -h for more information.")
             logger.error("Please use a download method. Use -h for more information.")
             logger.separator()
             logger.separator()
@@ -174,6 +170,9 @@ def validate_inputs(config, args, unknown_args):
         if args.noreplays:
         if args.noreplays:
             pil.dl_replays = False
             pil.dl_replays = False
 
 
+        if args.verbose:
+            pil.verbose = True
+
         if not pil.dl_lives and not pil.dl_replays:
         if not pil.dl_lives and not pil.dl_replays:
             logger.error("You have disabled both livestream and replay downloading.")
             logger.error("You have disabled both livestream and replay downloading.")
             logger.error("Please enable at least one of them and try again.")
             logger.error("Please enable at least one of them and try again.")
@@ -230,6 +229,9 @@ def validate_inputs(config, args, unknown_args):
             pil.assemble_arg = args.assemble
             pil.assemble_arg = args.assemble
             assembler.assemble()
             assembler.assemble()
             return False
             return False
+        elif args.organize:
+            organize.organize_videos()
+            return False
 
 
         return True
         return True
     except Exception as e:
     except Exception as e:

+ 1 - 1
setup.py

@@ -2,7 +2,7 @@ from setuptools import setup
 
 
 __author__ = 'notcammy'
 __author__ = 'notcammy'
 __email__ = 'neus2benen@gmail.com'
 __email__ = 'neus2benen@gmail.com'
-__version__ = '3.1.1'
+__version__ = '3.1.3'
 
 
 _api_version = '1.5.7'
 _api_version = '1.5.7'
 _api_extensions_version = '0.3.8'
 _api_extensions_version = '0.3.8'