Skip to content

Commit d34d7f1

Browse files
committed
v3.4
- Removed youtube-dl - Replaced m3u8 with flv
1 parent 3a19a60 commit d34d7f1

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Info(Enum):
4646
def __str__(self):
4747
return str(self.value)
4848

49-
VERSION = 3.3
49+
VERSION = 3.4
5050

5151
BANNER = f"""
5252

prova.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import requests
2+
from urllib.parse import urljoin
3+
from moviepy.editor import VideoFileClip, concatenate_videoclips
4+
5+
playlist_url = 'https://pull-hls-f16-gcp01.tiktokcdn.com/stage/stream-3283529153973059756_or4/index.m3u8'
6+
response = requests.get(playlist_url)
7+
playlist = response.text.strip().split('\n')
8+
9+
# Find the media segment lines in the playlist
10+
media_segments = [line for line in playlist if not line.startswith('#')]
11+
12+
# Combine the media segment URLs with the playlist URL to create valid URLs
13+
media_urls = [urljoin(playlist_url, segment_url) for segment_url in media_segments]
14+
15+
# Download each media segment and save it to a file
16+
clips = []
17+
for i, segment_url in enumerate(media_urls):
18+
response = requests.get(segment_url)
19+
with open(f'segment_{i}.ts', 'wb') as f:
20+
f.write(response.content)
21+
clip = VideoFileClip(f'segment_{i}.ts')
22+
clips.append(clip)
23+
24+
# Concatenate the clips and save the result as an .mp4 file
25+
final_clip = concatenate_videoclips(clips)
26+
final_clip.write_videofile('merged_video.mp4')

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
requests
2-
argparse
3-
streamlink
2+
argparse

tiktokbot.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import signal
2-
import sys
31
import time
42
import requests as req
53
import re
6-
import subprocess
74
import os
85
from enums import Mode, Error, StatusCode, TimeOut
9-
6+
import shutil
107

118
class TikTok:
129

@@ -65,14 +62,23 @@ def start_recording(self):
6562

6663
print("\n[*] STARTED RECORDING... [PRESS ONLY ONCE CTRL + C TO STOP]")
6764

68-
cmd = f"streamlink {live_url} best -o {output}"
65+
try:
66+
response = req.get(live_url, stream=True)
67+
with open(output, "wb") as out_file:
68+
shutil.copyfileobj(response.raw, out_file)
69+
except KeyboardInterrupt:
70+
pass
71+
72+
print("FINISH", output)
73+
74+
#cmd = f"streamlink {live_url} best -o {output}"
6975
#cmd = f"youtube-dl --hls-prefer-ffmpeg --no-continue --no-part -o {output} {live_url}"
76+
'''
7077
with open("error.log", "w") as error_log, open("info.log", "w") as info:
7178
p = subprocess.Popen(cmd, stderr=error_log, stdout=info, shell=True)
7279
signal.signal(signal.SIGINT, lambda x, y: sys.exit(0))
7380
p.communicate()
74-
75-
print(f"[*] FINISH {output}")
81+
'''
7682

7783
def get_live_url(self) -> str:
7884
try:
@@ -81,9 +87,10 @@ def get_live_url(self) -> str:
8187
json = req.get(url).json()
8288

8389
live_url_m3u8 = json['data']['stream_url']['hls_pull_url']
84-
print("[*] URL M3U8", live_url_m3u8)
90+
live_url_flv = json['data']['stream_url']['rtmp_pull_url']
91+
print("[*] URL FLV", live_url_flv)
8592

86-
return live_url_m3u8
93+
return live_url_flv
8794
except Exception as ex:
8895
print(ex)
8996

0 commit comments

Comments
 (0)