def add_vod_proxy_omdb(self, oid): server = current_user.get_current_server() if server: stream_object = server.make_proxy_vod() form = ProxyVodStreamForm(obj=stream_object.stream()) if request.method == 'GET': res = omdb.imdbid(oid) form.name.data = res['title'] form.tvg_logo.data = res['poster'] if res['type'] == 'series': form.vod_type.data = constants.VodType.SERIES form.country.data = res['country'] form.description.data = res['plot'] form.user_score.data = float(res['imdb_rating']) * 10 form.group.data = res['genre'].replace(',', ';') form.prime_date.data = datetime.datetime.strptime( res['released'], '%d %b %Y') runt_raw = res['runtime'] minutes = re.findall('\\d+', runt_raw) if minutes: # runt = datetime.time(minute=int(minutes[0])) # mseconds = (runt.hour * 60000 + runt.minute) * 60000 + runt.second * 1000 + runt.microsecond / 1000 form.duration.data = int(minutes[0]) * 60000 if request.method == 'POST' and form.validate_on_submit(): new_entry = form.make_entry() new_entry.save() server.add_stream(new_entry) return jsonify(status='ok'), 200 return render_template('stream/vod_proxy/add.html', form=form) return jsonify(status='failed'), 404
def add_own_proxy_vod(self): stream = ProxyVodStream.make_stream(None) form = ProxyVodStreamForm(obj=stream) form.price.validators = [] if request.method == 'POST' and form.validate_on_submit(): new_entry = form.make_entry() new_entry.save() current_user.add_own_stream(new_entry) return jsonify(status='ok'), 200 return render_template('stream/vod_proxy/add.html', form=form)
def add_proxy_vod(self): server = current_user.get_current_server() if server: stream_object = server.make_proxy_vod() form = ProxyVodStreamForm(obj=stream_object.stream()) if request.method == 'POST' and form.validate_on_submit(): new_entry = form.make_entry() new_entry.save() server.add_stream(new_entry) return jsonify(status='ok'), 200 return render_template('stream/vod_proxy/add.html', form=form) return jsonify(status='failed'), 404
def edit(self, sid): stream = current_user.find_own_stream(ObjectId(sid)) if not stream: return jsonify(status='failed'), 404 if stream.get_type() == constants.StreamType.PROXY: form = ProxyStreamForm(obj=stream) else: form = ProxyVodStreamForm(obj=stream) form.price.validators = [] if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) stream.save() return jsonify(status='ok'), 200 return render_template('stream/proxy/edit.html', form=form)
def edit(self, sid): server = current_user.get_current_server() if server: stream_object = server.find_stream_by_id(ObjectId(sid)) if stream_object: stream_type = stream_object.type stream = stream_object.stream() if stream_type == constants.StreamType.PROXY: form = ProxyStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template('stream/proxy/edit.html', form=form) elif stream_type == constants.StreamType.VOD_PROXY: form = ProxyVodStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template('stream/vod_proxy/edit.html', form=form) elif stream_type == constants.StreamType.RELAY: form = RelayStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/relay/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.ENCODE: form = EncodeStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/encode/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.TIMESHIFT_RECORDER: form = TimeshiftRecorderStreamForm(obj=stream) if request.method == 'POST': # FIXME form.validate_on_submit() stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/timeshift_recorder/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir(), timeshift_dir=stream_object.generate_timeshift_dir()) elif stream_type == constants.StreamType.CATCHUP: form = CatchupStreamForm(obj=stream) if request.method == 'POST': # FIXME form.validate_on_submit() stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/catchup/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir(), timeshift_dir=stream_object.generate_timeshift_dir()) elif stream_type == constants.StreamType.TIMESHIFT_PLAYER: form = TimeshiftPlayerStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/timeshift_player/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.TEST_LIFE: form = TestLifeStreamForm(obj=stream) if request.method == 'POST': # FIXME form.validate_on_submit() stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/test_life/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.VOD_RELAY: form = VodRelayStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/vod_relay/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.VOD_ENCODE: form = VodEncodeStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/vod_encode/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.COD_RELAY: form = CodRelayStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/cod_relay/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.COD_ENCODE: form = CodEncodeStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/cod_encode/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) elif stream_type == constants.StreamType.EVENT: form = EventStreamForm(obj=stream) if request.method == 'POST' and form.validate_on_submit(): stream = form.update_entry(stream) server.update_stream(stream) return jsonify(status='ok'), 200 return render_template( 'stream/event/edit.html', form=form, feedback_dir=stream_object.generate_feedback_dir()) return jsonify(status='failed'), 404