lazysdk 0.1.2__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {lazysdk-0.1.2 → lazysdk-0.1.4}/PKG-INFO +1 -1
  2. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazym3u8.py +114 -25
  3. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk.egg-info/PKG-INFO +1 -1
  4. {lazysdk-0.1.2 → lazysdk-0.1.4}/setup.py +1 -1
  5. {lazysdk-0.1.2 → lazysdk-0.1.4}/README.md +0 -0
  6. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/__init__.py +0 -0
  7. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyCrypto.py +0 -0
  8. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazybase64.py +0 -0
  9. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazydict.py +0 -0
  10. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyenv.py +0 -0
  11. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyexcel.py +0 -0
  12. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyfile.py +0 -0
  13. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyflask.py +0 -0
  14. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyid.py +0 -0
  15. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyip.py +0 -0
  16. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazymd5.py +0 -0
  17. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazypath.py +0 -0
  18. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyprocess.py +0 -0
  19. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyproxies.py +0 -0
  20. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyrandom.py +0 -0
  21. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyredis.py +0 -0
  22. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyrequests.py +0 -0
  23. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazytext.py +0 -0
  24. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazytime.py +0 -0
  25. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazyua.py +0 -0
  26. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk/lazywebhook.py +0 -0
  27. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk.egg-info/SOURCES.txt +0 -0
  28. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk.egg-info/dependency_links.txt +0 -0
  29. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk.egg-info/requires.txt +0 -0
  30. {lazysdk-0.1.2 → lazysdk-0.1.4}/lazysdk.egg-info/top_level.txt +0 -0
  31. {lazysdk-0.1.2 → lazysdk-0.1.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lazysdk
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: 基于Python的懒人包
5
5
  Home-page: https://gitee.com/ZeroSeeker/lazysdk
6
6
  Author: ZeroSeeker
@@ -5,6 +5,7 @@ from . import lazytime
5
5
  from . import lazyfile
6
6
  from . import lazypath
7
7
  from . import lazymd5
8
+ from . import lazyprocess
8
9
  import subprocess
9
10
  import threading
10
11
  import requests
@@ -16,6 +17,7 @@ import time
16
17
  import sys
17
18
  import os
18
19
  import re
20
+ from rich.progress import track
19
21
 
20
22
 
21
23
  timeout = 10
@@ -435,7 +437,7 @@ def download_fragment(
435
437
  :return:
436
438
  """
437
439
  if headers is None:
438
- headers_local = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}
440
+ headers_local = default_headers
439
441
  else:
440
442
  headers_local = headers
441
443
 
@@ -452,17 +454,18 @@ def download_fragment(
452
454
  fragment_file_name_list = list()
453
455
  print('开始下载...')
454
456
  for index, each_url in enumerate(url_list):
455
- print(each_url)
457
+ print('正在下载', each_url)
456
458
  fragment_file_name = '%s%s%s.%s' % (fragment_path_new, path_separator, index, fragment_suffix) # 生成碎片文件名
457
459
  # 开始下载碎片文件
458
460
  while True:
459
461
  try:
460
462
  with open(fragment_file_name, "ab+") as f:
461
- time_pre = time.time()
462
- response = requests.get(url=each_url,
463
- headers=headers_local,
464
- stream=True,
465
- timeout=10)
463
+ response = requests.get(
464
+ url=each_url,
465
+ headers=headers_local,
466
+ stream=True,
467
+ timeout=timeout
468
+ )
466
469
  total_length = response.headers.get('content-length')
467
470
 
468
471
  if total_length is None:
@@ -470,9 +473,12 @@ def download_fragment(
470
473
  else:
471
474
  dl = 0
472
475
  total_length = int(total_length)
473
- char_list = ['\\', '|', '/', '-']
474
- _index_ = 0
475
- for data in response.iter_content(chunk_size=8192):
476
+ for data in track(
477
+ sequence=response.iter_content(chunk_size=8192),
478
+ description='下载中',
479
+ total=total_length/8192,
480
+ show_speed=True
481
+ ):
476
482
  dl += len(data)
477
483
  if aes_key is None:
478
484
  data_decode = data
@@ -480,18 +486,9 @@ def download_fragment(
480
486
  data_decode = lazyCrypto.aes_decode(data, aes_key)
481
487
  f.write(data_decode)
482
488
  f.flush()
483
- done = int(40 * dl / total_length)
484
- time_now = time.time()
485
- sys.stdout.write("\r第 [ %s/%s ] 部分下载中: %s [%s%s] %.2f%% %.2fMB / %.2fMB SPEED: %.2fMB/s" % (
486
- index + 1, len(url_list), char_list[_index_], '=' * done, ' ' * (40 - done), (dl / total_length) * 100,
487
- dl / 1000000, total_length / 1000000, (dl / (1024.0 * 1024.0 * 1024.0)) / ((time_now - time_pre) / 1000)))
488
- sys.stdout.flush()
489
- _index_ = (_index_ + 1) % len(char_list)
490
- # print("")
491
489
  break
492
490
  except:
493
- print('下载超时,将在1秒后重试...')
494
- showlog.error('')
491
+ showlog.warning('下载超时,将在1秒后重试...')
495
492
  os.remove(fragment_file_name)
496
493
  time.sleep(1)
497
494
  pass
@@ -507,6 +504,103 @@ def download_fragment(
507
504
  return download_res
508
505
 
509
506
 
507
+ def download_fragment_single(
508
+ task_index,
509
+ task_info,
510
+ ):
511
+ """
512
+ 模块功能:下载单个碎片到指定文件夹
513
+ :param fragment_url: 碎片下载地址
514
+ :param fragment_url_name: 碎片名
515
+ :param fragment_path:碎片保存路径
516
+ :param aes_key: aes解密key
517
+ :param headers:请求头
518
+ :param fragment_suffix:碎片文件后缀名
519
+ :return:
520
+ """
521
+ fragment_url = task_info['fragment_url']
522
+ fragment_url_name = task_info['fragment_url_name']
523
+ fragment_path = task_info['fragment_path']
524
+ aes_key = None,
525
+ headers = None,
526
+ fragment_suffix = task_info['fragment_suffix']
527
+
528
+ if headers is None:
529
+ headers_local = default_headers
530
+ else:
531
+ headers_local = headers
532
+
533
+ print('正在下载', fragment_url_name, fragment_url)
534
+ fragment_file_name = '%s%s%s.%s' % (fragment_path, path_separator, fragment_url_name, fragment_suffix) # 生成碎片文件名
535
+ # 开始下载碎片文件
536
+ while True:
537
+ try:
538
+ with open(fragment_file_name, "ab+") as f:
539
+ response = requests.get(
540
+ url=fragment_url,
541
+ headers=headers_local,
542
+ stream=True,
543
+ timeout=timeout
544
+ )
545
+ total_length = response.headers.get('content-length')
546
+
547
+ if total_length is None:
548
+ print("Attention: There is no content length in header!") # 未返回长度信息
549
+ else:
550
+ dl = 0
551
+ total_length = int(total_length)
552
+ for data in track(
553
+ sequence=response.iter_content(chunk_size=8192),
554
+ description='下载中',
555
+ total=total_length/8192,
556
+ show_speed=True
557
+ ):
558
+ dl += len(data)
559
+ if aes_key is None:
560
+ data_decode = data
561
+ else:
562
+ data_decode = lazyCrypto.aes_decode(data, aes_key)
563
+ f.write(data_decode)
564
+ f.flush()
565
+ break
566
+ except:
567
+ showlog.warning('下载超时,将在1秒后重试...')
568
+ os.remove(fragment_file_name)
569
+ time.sleep(1)
570
+ pass
571
+
572
+
573
+ def download_fragment_quick(
574
+ url_list
575
+ ):
576
+ fragment_path = 'fragment_%s' % str(time.time()).replace('.', '') # 使用时间戳命名
577
+ fragment_suffix = 'ts'
578
+ lazypath.make_path(fragment_path)
579
+ task_list = list()
580
+ fragment_file_name_list = list()
581
+ for url_index, each_url in enumerate(url_list):
582
+ task_list.append(
583
+ {
584
+ 'fragment_url': each_url,
585
+ 'fragment_url_name': url_index,
586
+ 'fragment_path': fragment_path,
587
+ 'fragment_suffix': fragment_suffix
588
+ }
589
+ )
590
+ fragment_file_name = '%s%s%s.%s' % (fragment_path, path_separator, url_index, fragment_suffix) # 生成碎片文件名
591
+ fragment_file_name_list.append(fragment_file_name)
592
+ lazyprocess.run(
593
+ task_list=url_list,
594
+ task_function=download_fragment_single
595
+ )
596
+ download_res = {
597
+ 'fragment_path': fragment_path,
598
+ 'fragment_suffix': fragment_suffix,
599
+ 'fragment_file_name_list': fragment_file_name_list
600
+ }
601
+ return download_res
602
+
603
+
510
604
  def download_m3u8(
511
605
  m3u8_link=None,
512
606
  m3u8_file_path=None,
@@ -742,8 +836,3 @@ def convert_video(
742
836
  flags = ["ffmpeg", "-i", f"{video_input}.ts", "-acodec", "copy", "-vcodec", "copy", video_output]
743
837
  subprocess.Popen(flags, stdout=subprocess.DEVNULL).wait()
744
838
  # os.unlink(f"{video_input}.ts") # 删除文件
745
-
746
-
747
- if __name__ == '__main__':
748
- test_m3u8_url = input('请输入需要下载的m3u8地址:')
749
- download_m3u8_to_file(m3u8_url=test_m3u8_url)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lazysdk
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: 基于Python的懒人包
5
5
  Home-page: https://gitee.com/ZeroSeeker/lazysdk
6
6
  Author: ZeroSeeker
@@ -13,7 +13,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
13
13
 
14
14
  setuptools.setup(
15
15
  name="lazysdk",
16
- version="0.1.2",
16
+ version="0.1.4",
17
17
  description="基于Python的懒人包",
18
18
  long_description=long_description,
19
19
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes