warp-beacon 2.5.0__py3-none-any.whl → 2.5.1__py3-none-any.whl

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.
@@ -1,2 +1,2 @@
1
- __version__ = "2.5.0"
1
+ __version__ = "2.5.1"
2
2
 
@@ -49,7 +49,7 @@ class YoutubeMusicScraper(YoutubeAbstract):
49
49
  "local_media_path": self.rename_local_file(local_file),
50
50
  "performer": yt.author,
51
51
  "thumb": thumbnail,
52
- "canonical_name": stream.title,
52
+ "canonical_name": yt.title,
53
53
  "media_type": JobType.AUDIO
54
54
  })
55
55
  except Exception:
@@ -1,5 +1,8 @@
1
+ import time
2
+ import os
1
3
  import logging
2
4
 
5
+ import av
3
6
  from pytubefix.exceptions import AgeRestrictedError
4
7
 
5
8
  from warp_beacon.jobs.types import JobType
@@ -29,6 +32,110 @@ class YoutubeScraper(YoutubeAbstract):
29
32
  return False
30
33
 
31
34
  def _download(self, url: str, session: bool = True, timeout: int = 60) -> list:
35
+ res = None
36
+ try:
37
+ res = self._download_pytubefix_max_res(url=url, session=session, timeout=timeout)
38
+ except Exception as e:
39
+ logging.error("Failed to download video with highest resolution via pytubefix!")
40
+ logging.exception(e)
41
+
42
+ if not res:
43
+ try:
44
+ res = self._download_pytube_dash(url=url, session=session, timeout=timeout)
45
+ except Exception as e:
46
+ logging.error("Failed to download DASH stream video via pytubefix!")
47
+ logging.exception(e)
48
+
49
+ return res
50
+
51
+ def mux_raw_copy(self, video_path: str, audio_path: str, output_path: str) -> str:
52
+ try:
53
+ with av.open(video_path) as input_video, av.open(audio_path) as input_audio, av.open(output_path, mode='w') as output:
54
+ in_video_stream = input_video.streams.video[0]
55
+ in_audio_stream = input_audio.streams.audio[0]
56
+
57
+ out_video_stream = output.add_stream(codec_name=in_video_stream.codec.name)
58
+ out_audio_stream = output.add_stream(codec_name=in_audio_stream.codec.name)
59
+
60
+ for packet in input_video.demux(in_video_stream):
61
+ if packet.dts is None:
62
+ continue
63
+ packet.stream = out_video_stream
64
+ output.mux(packet)
65
+
66
+ for packet in input_audio.demux(in_audio_stream):
67
+ if packet.dts is None:
68
+ continue
69
+ packet.stream = out_audio_stream
70
+ output.mux(packet)
71
+ except Exception as e:
72
+ logging.error("Failed to mux audio and video!")
73
+ logging.exception(e)
74
+ return ''
75
+
76
+ return output_path
77
+
78
+ def _download_pytubefix_max_res(self, url: str, session: bool = True, timeout: int = 60) -> list:
79
+ res = []
80
+ local_video_file, local_audio_file = '', ''
81
+ try:
82
+ thumbnail = None
83
+ video_id = self.get_video_id(url)
84
+ if video_id:
85
+ thumbnail = self.download_hndlr(self.download_thumbnail, video_id)
86
+ yt = self.build_yt(url, session=session)
87
+
88
+ if self.is_live(yt.initial_data):
89
+ raise YoutubeLiveError("Youtube Live is not supported")
90
+
91
+ video_stream = yt.streams.filter(adaptive=True, file_extension='mp4', only_video=True).order_by('resolution').desc().first()
92
+ audio_stream = yt.streams.filter(adaptive=True, file_extension='mp4', only_audio=True).order_by('abr').desc().first()
93
+
94
+ local_video_file = video_stream.download(
95
+ output_path=self.DOWNLOAD_DIR,
96
+ max_retries=3,
97
+ timeout=timeout,
98
+ skip_existing=False,
99
+ filename_prefix="yt_download_video_"
100
+ )
101
+ local_video_file = self.rename_local_file(local_video_file)
102
+ logging.debug("Temp video filename: '%s'", local_video_file)
103
+ local_audio_file = audio_stream.download(
104
+ output_path=self.DOWNLOAD_DIR,
105
+ max_retries=3,
106
+ timeout=timeout,
107
+ skip_existing=False,
108
+ filename_prefix="yt_download_audio_"
109
+ )
110
+ local_audio_file = self.rename_local_file(local_audio_file)
111
+ logging.debug("Temp audio filename: '%s'", local_audio_file)
112
+
113
+ muxed_video = self.mux_raw_copy(
114
+ video_path=local_video_file,
115
+ audio_path=local_audio_file,
116
+ output_path=f"{self.DOWNLOAD_DIR}/yt_muxed_video_{int(time.time())}.mp4")
117
+ if muxed_video:
118
+ muxed_video = self.rename_local_file(muxed_video)
119
+ logging.debug("Temp muxed filename: '%s'", muxed_video)
120
+
121
+ res.append({
122
+ "local_media_path": muxed_video,
123
+ "performer": yt.author,
124
+ "thumb": thumbnail,
125
+ "canonical_name": yt.title,
126
+ "media_type": JobType.VIDEO
127
+ })
128
+ except AgeRestrictedError as e:
129
+ raise YotubeAgeRestrictedError("Youtube Age Restricted error")
130
+ finally:
131
+ if os.path.exists(local_video_file):
132
+ os.unlink(local_video_file)
133
+ if os.path.exists(local_audio_file):
134
+ os.unlink(local_audio_file)
135
+
136
+ return res
137
+
138
+ def _download_pytube_dash(self, url: str, session: bool = True, timeout: int = 60) -> list:
32
139
  res = []
33
140
  try:
34
141
  thumbnail = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: warp_beacon
3
- Version: 2.5.0
3
+ Version: 2.5.1
4
4
  Summary: Telegram bot for expanding external media links
5
5
  Home-page: https://github.com/sb0y/warp_beacon
6
6
  Author: Andrey Bagrintsev
@@ -4,7 +4,7 @@ var/warp_beacon/accounts.json,sha256=OsXdncs6h88xrF_AP6_WDCK1waGBn9SR-uYdIeK37GM
4
4
  var/warp_beacon/placeholder.gif,sha256=cE5CGJVaop4Sx21zx6j4AyoHU0ncmvQuS2o6hJfEH88,6064
5
5
  var/warp_beacon/proxies.json,sha256=VnjlQDXumOEq72ZFjbh6IqHS1TEHqn8HPYAZqWCeSIA,95
6
6
  warp_beacon/__init__.py,sha256=_rThNODmz0nDp_n4mWo_HKaNFE5jk1_7cRhHyYaencI,163
7
- warp_beacon/__version__.py,sha256=yD2fQ5Bqhm2OUVsEBxqOfmSxIDd9-R8jWxUE6ePf5Zk,23
7
+ warp_beacon/__version__.py,sha256=CuP8A044Dx_SN-2FdWp2DpPo-sVcAap_snue2AkcA_s,23
8
8
  warp_beacon/warp_beacon.py,sha256=7KEtZDj-pdhtl6m-zFLsSojs1ZR4o7L0xbqtdmYPvfE,342
9
9
  warp_beacon/yt_auth.py,sha256=GUTKqYr_tzDC-07Lx_ahWXSag8EyLxXBUnQbDBIkEmk,6022
10
10
  warp_beacon/compress/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,9 +32,9 @@ warp_beacon/scraper/instagram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
32
32
  warp_beacon/scraper/instagram/instagram.py,sha256=KyOZnIt6A8wkroXkZcIJMscuy5N5ZEz9-v3Ciwo0C7M,14654
33
33
  warp_beacon/scraper/youtube/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  warp_beacon/scraper/youtube/abstract.py,sha256=r_g6zkEX9h5VqQVHaQFAD-lWsEOs7Um353N98nB3tfA,11548
35
- warp_beacon/scraper/youtube/music.py,sha256=-R6Iys8IpglH5UL7F640UQ3ieYHitvGXA0A2GhSemVA,2927
35
+ warp_beacon/scraper/youtube/music.py,sha256=m-1iPYe1p0OZmOlYl8gjHErsazCcXqs3qDA7KyIT6GI,2923
36
36
  warp_beacon/scraper/youtube/shorts.py,sha256=sPrOjhcLlV0m5a-j4mSFsF6CkNapeUdGZqoWAYheiCM,1894
37
- warp_beacon/scraper/youtube/youtube.py,sha256=B1NBz6vv0-zIuf3MDmT2QB7eX2qO8k9orj7-4wU6MBk,2839
37
+ warp_beacon/scraper/youtube/youtube.py,sha256=xvMNxmw9Aa_koWZzl1VAA0BtNKH3m6tJrdh2Qc6Xvek,6477
38
38
  warp_beacon/storage/__init__.py,sha256=0Vajd0oITKJfu2vmNx5uQSt3-L6vwIvUYWJo8HZCjco,3398
39
39
  warp_beacon/storage/mongo.py,sha256=qC4ZiO8XXvPnP0rJwz4CJx42pqFsyAjCiW10W5QdT6E,527
40
40
  warp_beacon/telegram/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -44,9 +44,9 @@ warp_beacon/telegram/handlers.py,sha256=uvR6TPHSqdSxigp3wR-ewiE6t3TvVcbVLVcYGwkg
44
44
  warp_beacon/telegram/placeholder_message.py,sha256=wN9-BRiyrtHG-EvXtZkGJHt2CX71munQ57ITttjt0mw,6400
45
45
  warp_beacon/telegram/utils.py,sha256=9uebX53G16mV7ER7WgfdWBLFHHw14S8HBt9URrIskg0,4440
46
46
  warp_beacon/uploader/__init__.py,sha256=e75mOcC0vrUVjrTNMQzVUTgXGdGo4J6n8t5doOnYG5I,5616
47
- warp_beacon-2.5.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
48
- warp_beacon-2.5.0.dist-info/METADATA,sha256=PTJjikxncRfegZp8y6ZJAJRYYksORllUPwWPCd7YCt8,22625
49
- warp_beacon-2.5.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
50
- warp_beacon-2.5.0.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
51
- warp_beacon-2.5.0.dist-info/top_level.txt,sha256=4ML0-mXsezLtRXyxQUntL_ktc5HX9npTeQWzvV8kFvA,1161
52
- warp_beacon-2.5.0.dist-info/RECORD,,
47
+ warp_beacon-2.5.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
48
+ warp_beacon-2.5.1.dist-info/METADATA,sha256=d-WLa0lelUQAJol-ELP3dSTvSFaQgjUPCOEcs6CK28Y,22625
49
+ warp_beacon-2.5.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
50
+ warp_beacon-2.5.1.dist-info/entry_points.txt,sha256=eSB61Rb89d56WY0O-vEIQwkn18J-4CMrJcLA_R_8h3g,119
51
+ warp_beacon-2.5.1.dist-info/top_level.txt,sha256=4ML0-mXsezLtRXyxQUntL_ktc5HX9npTeQWzvV8kFvA,1161
52
+ warp_beacon-2.5.1.dist-info/RECORD,,