async def get_current_vodeo(request: Request, db: Session = Depends(get_db)): """ Get videos in channel playlist. Response will be list. Zeroth item is currently playing video. TODO: channel_id parameter is ignored until after MVP """ return SubmissionService.getCurrentlyPlaying(db)
async def skip_video(request: Request, submission_id: str, user_id: int = 0, db: Session = Depends(get_db)): """ Vote to skip video. Respond with success/error. TODO: If user has already voted to skip this video_id, deduct 1 karma from user. """ db_user = crud.get_account_from_hash(db, user_id) return SubmissionService.submissionVote(db, int(submission_id), db_user.accountid, val=-1, type='active')
async def submit_video(request: Request, channel_id: str, sr: SubmissionRequest, db: Session = Depends(get_db)): """ User-submitted video url. Respond with success/error. TODO: use request headers to determine user id TODO: validate url for video length TODO: channel_id parameter is ignored until after MVP """ db_user = crud.get_account_from_hash(db, sr.userid) await broadcast_data('pl', None) return SubmissionService.submitVideo(db, app.state.youtube, db_user.accountid, channel_id, sr.url)
async def run_playlist(db): if hasattr(app.state, 'playlistThread') and app.state.playlistThread: return app.state.playlistThread = True print("Starting playlist Thread") while (True): await asyncio.sleep(2) # print("tick") next_submission = SubmissionService.getNextVideo(db) print("found video:", next_submission) if next_submission: print("broadcasting") await broadcast_data('play', next_submission) SubmissionService.createPlayRecord(db, next_submission) print(next_submission) print("length", next_submission['length']) await asyncio.sleep(next_submission['length']) print("done playing, looking for next video") # mark as played else: print("no playlist found, waiting") await asyncio.sleep(3)
async def downvote_video(request: Request, submission_id: str, user_id: int = 0, db: Session = Depends(get_db)): """ Downvote video. Respond with success/error. TODO: If user has already downvoted this video_id, deduct 1 karma from user. """ db_user = crud.get_account_from_hash(db, user_id) await broadcast_data('pl', None) return SubmissionService.submissionVote(db, int(submission_id), db_user.accountid, val=-1, type='playlist')
('/.*', Web404Handler), ], cookie_secret=config.COOKIE_SECRET, compress_response=True, debug=config.DEBUG, autoescape='xhtml_escape', ui_modules=ui_modules, xheaders=True, ) global srv srv = tornado.httpserver.HTTPServer(app) if not config.DEBUG: srv.add_sockets(sock) else: srv.listen(config.PORT) Service.User = UserService(db, rs) Service.Problem = ProblemService(db, rs) Service.Submission = SubmissionService(db, rs) Service.Testdata = TestdataSerivce(db, rs) Service.Bulletin = BulletinService(db, rs) Service.Execute = ExecuteService(db, rs) Service.Contest = ContestService(db, rs) Service.Verdict = VerdictService(db, rs) Service.Group = GroupService(db, rs) Service.Tags = TagService(db, rs) Service.School = SchoolService(db, rs) Service.VerdictString = VerdictStringService(db, rs) Service.Score = ScoreService(db, rs) Service.Upload = UploadService(db, rs) Service.Permission = PermissionService signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) print('Server Started')