Skip to content

Commit

Permalink
添加对niconico支持 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
misaka10843 authored Jul 30, 2023
1 parent c12a79f commit 2ea96c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 17 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import urllib
import uuid
from datetime import datetime
from http.cookies import SimpleCookie
from pathlib import Path
from typing import Dict, Tuple, Union
Expand Down Expand Up @@ -370,6 +371,22 @@ async def run(self):
await asyncio.to_thread(self.run_record, stream, url, title, 'ts')


class NicoNico(LiveRecoder):
async def run(self):
url = f'https://live.nicovideo.jp/watch/{self.id}'
if url not in recording:
response = (await self.request(
method='GET',
url=url,
)).text
live_json = json.loads(re.search('<script type="application/ld\+json">(.*?)</script>', response).group(1))
end_ts = datetime.strptime(live_json['publication']['endDate'], '%Y-%m-%dT%H:%M:%S%z').timestamp()
now_ts = datetime.now().timestamp()
if end_ts > now_ts:
stream = self.get_streamlink().streams(url).get('best') # HLSStream[mpegts]
await asyncio.to_thread(self.run_record, stream, url, live_json['name'], 'flv')


async def run():
with open('config.json', 'r', encoding='utf-8') as f:
config = json.load(f)
Expand Down
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

0 comments on commit 2ea96c7

Please sign in to comment.