하꼬

자동으로 m3u8 따주는 프로그램

작성자 정보

컨텐츠 정보

본문

여러 사람들이 m3u8을 따는 여러 방법을 알아냈지만 아직 모든 다시보기를 살려낼 순 없었지

그래서 내가 만들어왔어!


켜놓고만 있으면 알아서 10분마다 여러 방송이 켜져있는지 확인하고 켜져있으면 m3u8 링크를 따주는 프로그램이야


다운링크는 댓에 남길게


https://www.godo.dev/tutorials/python-record-twitch/

https://github.com/siddhantdubey/getdeletedtwitchvods/blob/main/script.py


이 두 코드를 참고했음


쓰는 방법을 알려줄게


일단 exe 파일을 다운받은 뒤에 아무 폴더나 만들어서 넣어놔


그리고 그 폴더에 streamers.txt 를 만들어



16130924037739.png


이렇게 말이지


폴더는 만들 필요 없어 프로그램이 만들어줄거거든


그리고 저 txt파일 안에 m3u8을 받고싶은 채널의 id 를 넣어



16130924049055.png


이런식으로


나는 추가적으로 작업을 해서 abc순으로 정렬되어있지만 안해도 잘 굴러간다


그리고 이거 할때 주의사항이 있는데



16130924060048.png


이런 식의 빈 줄이 들어 가 있으면 프로그램이 튕긴다


이외에도 철자가 이상하면 튕길거다


이제 너가 제대로 세팅을 했고 저기 쓴 사람 중 아무나 방송을 켰으면 저기에 폴더가 생기고 그 안에 방송을 킨 스트리머 아이디.txt가 생길 거임


그리고 그 안에 m3u8 링크가 있을거임


그리고 매일 밤 자정 12:00 ~ 12:10 사이면 파일 내에 그 날 날짜가 기록 될거임


이 프로그램에는 단점이 있긴 해


프로그램을 끌 거라는 전제를 깔지 않았기에 컴퓨터나 프로그램을 끄면 그때 동안의 m3u8링크는 따지 못할 뿐만 아니라,


스트리머가 방송을 계속 켜고 있을 경우 같은 m3u8 링크가 한번 더 기록되거든


아 그리고 인터넷도 끊기면 안될거임 프로그램이 트위치 api를 활용하기 때문이지


뭐 그래도 사양은 많이 안먹는다


i5 - 2450m이라는 구데기 cpu로 10분에 한번 잠깐 최고 3%대 점유율을 보이고 일반적으로 0% 대임

메모리도 최고 10mb 대만 먹고 일반적으로 6mb 대를 먹음


소스를 남길테니 알아서 쓰셈


import requests
import hashlib
import datetime
import time
import os

# pyinstaller --noconsole --onefile getstreaminfo.py


class Twitchinfo:
def __init__(self):
# global configuration
self.client_id = "jzkbprff40iqj646a697cyrvl0zt2m6" # don't change this

# user configuration
self.username = "kumikomii"
self.VodId = 0
self.timestamp = ''

def check_vod_id(self):
url = 'https://api.twitch.tv/kraken/channels/' + self.username
info = None

try:
h = {"Client-ID": self.client_id, "Accept": "application/vnd.twitchtv.v5+json"}
r = requests.get(f"https://api.twitch.tv/kraken/users?login={self.username}", headers=h)
user_id = r.json().get("users", [{}])[0].get("_id", "")

r = requests.get(f"https://api.twitch.tv/kraken/streams/{user_id}", headers=h, timeout=15)
r.raise_for_status()

r_dict = r.json()
if r_dict["stream"]:
info = [r_dict["stream"]['_id'], r_dict["stream"]['created_at'], self.username]
self.VodId = info[0]
self.timestamp = info[1]

else:
info = []
# except requests.exceptions.RequestException as e:
except (KeyboardInterrupt, SystemExit): # temporary workaround for all kinds of possible exceptions, notably JSONDecodeError
raise

return info

def makem3u8(self):

year = int(self.timestamp[:4])
month = int(self.timestamp[5:7])
day = int(self.timestamp[8:10])
# 날짜 입력한거 분해하기

hour = int(self.timestamp[11:13])
minute = int(self.timestamp[14:16])
seconds = int(self.timestamp[17:19])
# 시간 입력한거 분해하기

td = datetime.datetime(year, month, day, hour, minute, seconds)
converted_timestamp = totimestamp(td) # 시간부분 번역

formattedstring = self.username + "_" + str(self.VodId) + "_" + str(int(converted_timestamp)) # 해쉬구하기용 합치기

hash = str(hashlib.sha1(formattedstring.encode('utf-8')).hexdigest())
requiredhash = hash[:20] # 해쉬구하기

finalformattedstring = requiredhash + '_' + formattedstring # 해쉬까지 합치기

self.url = f"https://vod-secure.twitch.tv/{finalformattedstring}/chunked/index-dvr.m3u8" # m3u8 주소에 끼워넣기

return self.url

def tofile(self):
createFolder(self.timestamp[:7])
file = open(f'{self.timestamp[:7]}\{self.username}.txt', 'at')
file.write(self.url)
file.write(' ')
file.close()

def filedate(self):
createFolder(self.timestamp[:7])
file = open(f'{self.timestamp[:7]}\{self.username}.txt', 'at')
file.write(' ')
file.write(self.timestamp[:10])
file.write(' ')
file.close()


def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
return -1
# print('Error: Creating directory. ' + directory)


def totimestamp(dt, epoch=datetime.datetime(1970, 1, 1)):
td = dt - epoch
# return td.total_seconds()
return (td.microseconds + (td.seconds + td.days * 86400) * 10**6) / 10**6


def main():
twitch_recorder = Twitchinfo()
f = open('streamers.txt', 'rt')
streamer = f.read()
f.close()
streamer = streamer.split(' ')

prev = {}

for i in streamer:
prev[i] = []

while True:
now = time.time()
# print()
# print(time.strftime('%x %X', time.localtime(time.time())))

f = open('streamers.txt', 'rt')
streamer = f.read()
f.close()
streamer = streamer.split(' ')

for i in streamer:
# print(i, end=' : ')
twitch_recorder.username = i
info = twitch_recorder.check_vod_id()
# print(info)
if info and info != prev[i]:
prev[i] = info
twitch_recorder.makem3u8()
twitch_recorder.tofile()

if 0 <= (time.time() + 32400) % 86400 < 600:
# print("자정")
for i in streamer:
twitch_recorder.username = i
twitch_recorder.filedate()

time.sleep(600 + now - time.time())


if __name__ == "__main__":
main()



관련자료

댓글 0
등록된 댓글이 없습니다.
Total 2,733 / 22 Page
번호
제목
이름

새댓글


  • 댓글이 없습니다.
알림 0