Prechádzať zdrojové kódy

Add support for batch file downloading

Cammy 6 rokov pred
rodič
commit
d3a3197e22
4 zmenil súbory, kde vykonal 97 pridanie a 64 odobranie
  1. 28 22
      pyinstalive/dlfuncs.py
  2. 2 0
      pyinstalive/pil.py
  3. 31 6
      pyinstalive/startup.py
  4. 36 36
      setup.py

+ 28 - 22
pyinstalive/dlfuncs.py

@@ -379,28 +379,7 @@ def download_following():
             logger.info("The following users have available {:s}.".format(is_checking))
             logger.info(', '.join(available_total))
             logger.separator()
-            for user in available_total:
-                try:
-                    if os.path.isfile(os.path.join(pil.dl_path, user + '.lock')):
-                        logger.warn("Lock file is already present for '{:s}', there is probably another download "
-                                    "ongoing!".format(user))
-                        logger.warn("If this is not the case, manually delete the file '{:s}' and try again.".format(user + '.lock'))
-                    else:
-                        logger.info("Launching daemon process for '{:s}'.".format(user))
-                        start_result = helpers.run_command("pyinstalive -d {:s} -cp '{:s}' -dp '{:s}' {:s} {:s}".format(
-                            user, pil.config_path, pil.dl_path,
-                            '--no-lives' if not pil.dl_lives else '', '--no-replays' if not pil.dl_replays else ''))
-                        if start_result:
-                            logger.warn("Could not start process: {:s}".format(str(start_result)))
-                        else:
-                            logger.info("Process started successfully.")
-                    logger.separator()
-                    time.sleep(2)
-                except Exception as e:
-                    logger.warn("Could not start processs: {:s}".format(str(e)))
-                except KeyboardInterrupt:
-                    logger.binfo('The process launching has been aborted by the user.')
-                    logger.separator()
+            iterate_users(available_total)
         else:
             logger.info("There are currently no available {:s}.".format(is_checking))
             logger.separator()
@@ -412,6 +391,33 @@ def download_following():
         logger.separator()
 
 
+def iterate_users(user_list):
+    for user in user_list:
+        try:
+            if os.path.isfile(os.path.join(pil.dl_path, user + '.lock')):
+                logger.warn("Lock file is already present for '{:s}', there is probably another download "
+                            "ongoing!".format(user))
+                logger.warn(
+                    "If this is not the case, manually delete the file '{:s}' and try again.".format(user + '.lock'))
+            else:
+                logger.info("Launching daemon process for '{:s}'.".format(user))
+                start_result = helpers.run_command("pyinstalive -d {:s} -cp '{:s}' -dp '{:s}' {:s} {:s}".format(
+                    user, pil.config_path, pil.dl_path,
+                    '--no-lives' if not pil.dl_lives else '', '--no-replays' if not pil.dl_replays else ''))
+                if start_result:
+                    logger.warn("Could not start process: {:s}".format(str(start_result)))
+                else:
+                    logger.info("Process started successfully.")
+            logger.separator()
+            time.sleep(2)
+        except Exception as e:
+            logger.warn("Could not start process: {:s}".format(str(e)))
+        except KeyboardInterrupt:
+            logger.binfo('The process launching has been aborted by the user.')
+            logger.separator()
+            break
+
+
 def get_live_comments(comments_json_file):
     try:
         comments_downloader = CommentsDownloader(destination_file=comments_json_file)

+ 2 - 0
pyinstalive/pil.py

@@ -16,6 +16,7 @@ def initialize():
     global ig_user
     global ig_pass
     global dl_user
+    global dl_batchusers
     global dl_path
     global dl_lives
     global dl_replays
@@ -45,6 +46,7 @@ def initialize():
     ig_user = ""
     ig_pass = ""
     dl_user = ""
+    dl_batchusers = []
     dl_path = os.getcwd()
     dl_lives = True
     dl_replays = True

+ 31 - 6
pyinstalive/startup.py

@@ -12,6 +12,7 @@ try:
     import helpers
     import downloader
     import assembler
+    import dlfuncs
     from constants import Constants
 except ImportError:
     from . import pil
@@ -20,6 +21,7 @@ except ImportError:
     from . import helpers
     from . import downloader
     from . import assembler
+    from . import dlfuncs
     from .constants import Constants
 
 
@@ -30,14 +32,14 @@ def validate_inputs(config, args, unknown_args):
 
         if args.download:
             pil.dl_user = args.download
-            if args.downloadfollowing:
+            if args.downloadfollowing or args.batchfile:
                 logger.banner()
-                logger.warn("Please use either argument --download or --download-following, not both.")
+                logger.warn("Please use only one download method. Use -h for more information.")
                 logger.separator()
                 return False
-        elif not args.clean and not args.info and not args.assemble and not args.downloadfollowing:
+        elif not args.clean and not args.info and not args.assemble and not args.downloadfollowing and not args.batchfile:
             logger.banner()
-            logger.error("Missing --download or --download-following argument, please use either of the two.")
+            logger.error("Please use a download method. Use -h for more information.")
             logger.separator()
             return False
 
@@ -51,6 +53,21 @@ def validate_inputs(config, args, unknown_args):
 
         logger.banner()
 
+        if args.batchfile:
+            if os.path.isfile(args.batchfile):
+                pil.dl_batchusers = [user.rstrip('\n') for user in open(args.batchfile)]
+                if not pil.dl_batchusers:
+                    logger.error("The specified file is empty.")
+                    logger.separator()
+                    return False
+                else:
+                    logger.info("Downloading {:d} users from batch file.".format(len(pil.dl_batchusers)))
+                    logger.separator()
+            else:
+                logger.error('The specified file does not exist.')
+                logger.separator()
+                return False
+
         if unknown_args:
             pil.uargs = unknown_args
             logger.warn("The following unknown argument(s) were provided and will be ignored: ")
@@ -199,6 +216,8 @@ def run():
                         help="Instagram password to login with.")
     parser.add_argument('-d', '--download', dest='download', type=str, required=False,
                         help="The username of the user whose livestream or replay you want to save.")
+    parser.add_argument('-b,', '--batch-file', dest='batchfile', type=str, required=False,
+                        help="Read a text file of usernames to download livestreams or replays from.")
     parser.add_argument('-i', '--info', dest='info', action='store_true', help="View information about PyInstaLive.")
     parser.add_argument('-nr', '--no-replays', dest='noreplays', action='store_true',
                         help="When used, do not check for any available replays.")
@@ -248,5 +267,11 @@ def run():
             pil.ig_api = auth.authenticate(username=args.username, password=args.password, force_use_login_args=True)
 
         if pil.ig_api:
-            downloader.start()
-
+            if pil.dl_user:
+                downloader.start()
+            elif pil.dl_batchusers:
+                if not helpers.command_exists("pyinstalive"):
+                    logger.error("PyInstaLive must be properly installed when using the -b argument.")
+                    logger.separator()
+                else:
+                    dlfuncs.iterate_users(pil.dl_batchusers)

+ 36 - 36
setup.py

@@ -8,42 +8,42 @@ _api_version = '1.5.7'
 _api_extensions_version = '0.3.8'
 
 long_description = 'This Python script enables you to download any ongoing Instagram livestreams as well as any ' \
-				   'available replays. It is based on another script that has now been discontinued. '
+                   'available replays. It is based on another script that has now been discontinued. '
 
 setup(
-	name='pyinstalive',
-	version=__version__,
-	author=__author__,
-	author_email=__email__,
-	url='https://github.com/notcammy/PyInstaLive',
-	packages=['pyinstalive'],
-	entry_points={
-		'console_scripts': [
-			'pyinstalive = pyinstalive.__main__:run',
-		]
-	},
-	install_requires=[ 
-		'instagram_private_api>=%(api)s' % {'api': _api_version},
-		'instagram_private_api_extensions>=%(ext)s' % {'ext': _api_extensions_version},
-		'argparse',
-		'configparser'
-	],
-	dependency_links=[
-		'https://github.com/ping/instagram_private_api/archive/%(api)s.tar.gz'
-		'#egg=instagram_private_api-%(api)s' % {'api': _api_version},
-		'https://github.com/ping/instagram_private_api_extensions/archive/%(ext)s.tar.gz'
-		'#egg=instagram_private_api_extensions-%(ext)s' % {'ext': _api_extensions_version}
-	],
-	include_package_data=True,
-	platforms='any',
-	long_description=long_description,
-	keywords='instagram-livestream-recorder record-instagram-livestreams live instagram record livestream video '
-			 'recorder downloader download save',
-	description='This script enables you to download Instagram livestreams and replays.',
-	classifiers=[
-		'Environment :: Console',
-		'Programming Language :: Python :: 2.7',
-		'Programming Language :: Python :: 3.5',
-		'Programming Language :: Python :: 3.6',
-	]
+    name='pyinstalive',
+    version=__version__,
+    author=__author__,
+    author_email=__email__,
+    url='https://github.com/notcammy/PyInstaLive',
+    packages=['pyinstalive'],
+    entry_points={
+        'console_scripts': [
+            'pyinstalive = pyinstalive.__main__:run',
+        ]
+    },
+    install_requires=[
+        'instagram_private_api>=%(api)s' % {'api': _api_version},
+        'instagram_private_api_extensions>=%(ext)s' % {'ext': _api_extensions_version},
+        'argparse',
+        'configparser'
+    ],
+    dependency_links=[
+        'https://github.com/ping/instagram_private_api/archive/%(api)s.tar.gz'
+        '#egg=instagram_private_api-%(api)s' % {'api': _api_version},
+        'https://github.com/ping/instagram_private_api_extensions/archive/%(ext)s.tar.gz'
+        '#egg=instagram_private_api_extensions-%(ext)s' % {'ext': _api_extensions_version}
+    ],
+    include_package_data=True,
+    platforms='any',
+    long_description=long_description,
+    keywords='instagram-livestream-recorder record-instagram-livestreams live instagram record livestream video '
+             'recorder downloader download save',
+    description='This script enables you to download Instagram livestreams and replays.',
+    classifiers=[
+        'Environment :: Console',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3.5',
+        'Programming Language :: Python :: 3.6',
+    ]
 )