Skip to content

Commit

Permalink
[update] pypresenceに渡すデータから終了時刻を削除する
Browse files Browse the repository at this point in the history
  • Loading branch information
okaits committed Dec 16, 2022
1 parent e95ef0d commit 6f12f48
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def get(self, user: Auth.User):
token.get(Auth.User("user1", "password"))

videodata_request = urllib.request.Request("http://localhost:5000/video", headers={"Authorization": f"Bearer {token.token}"})
beforevideodata = {}
beforeestimatedendtime = datetime.timedelta(seconds=0)
beforevideodata = {'status': 'closed'}
while True:
try:
videodata = json.loads(urllib.request.urlopen(videodata_request).read().decode())
Expand All @@ -49,7 +48,7 @@ def get(self, user: Auth.User):
continue
if videodata != beforevideodata:
print(videodata)
if videodata["status"] == "closed":
if videodata["status"] != "opened":
RPC.clear()
beforevideodata = videodata
continue
Expand All @@ -68,11 +67,6 @@ def get(self, user: Auth.User):
videolength = datetime.timedelta(hours=int(videolength[0]), minutes=int(videolength[1]), seconds=int(videolength[2]))
playingtime = datetime.timedelta(hours=int(videodata["hour"]), minutes=int(videodata["min"]), seconds=int(videodata["sec"]))
startedtime = datetime.datetime.now().replace(microsecond=0) - playingtime
estimatedendtime = datetime.datetime.now().replace(microsecond=0) + videolength - playingtime
if estimatedendtime == beforeestimatedendtime and videodata["sec"] == beforevideodata["sec"]:
beforevideodata = videodata
time.sleep(1)
continue
try:
author = video["user_nickname"]
except KeyError:
Expand All @@ -89,7 +83,6 @@ def get(self, user: Auth.User):
large_image=thumbnail_url,
large_text=vid,
start=startedtime.timestamp(),
end=estimatedendtime.timestamp(),
buttons=[{"label": "動画を視聴する", "url": url}],
instance=True
)
Expand Down

0 comments on commit 6f12f48

Please sign in to comment.