def upload_files(self): form = UploadM3uForm() if form.validate_on_submit(): files = request.files.getlist("files") for file in files: m3u_parser = M3uParser() data = file.read().decode('utf-8') m3u_parser.load_content(data) m3u_parser.parse() for entry in m3u_parser.files: title = entry['title'] if len(title) > constants.MAX_STREAM_NAME_LENGTH: continue line = _get_m3u_vod_by_name(title) if not line: line = M3uParseVods(name=title) tvg_group = entry['tvg-group'] if len(tvg_group) and len( tvg_group ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH: line.group.append(tvg_group) tvg_logo = entry['tvg-logo'] if len(tvg_logo ) and len(tvg_logo) < constants.MAX_URL_LENGTH: if is_valid_http_url(tvg_logo, timeout=0.1): line.tvg_logo.append(tvg_logo) line.save() return redirect(url_for('M3uParseVodsView:show'))
def upload_file(self): form = UploadM3uForm() server = current_user.get_current_server() if server and form.validate_on_submit(): stream_type = form.type.data file_handle = form.file.data m3u_parser = M3uParser() m3u_parser.load_content(file_handle.read().decode('utf-8')) m3u_parser.parse() for file in m3u_parser.files: if stream_type == constants.StreamType.PROXY: stream = server.make_proxy_stream() elif stream_type == constants.StreamType.RELAY: stream = server.make_relay_stream() stream.output.urls[0] = stream.generate_http_link() elif stream_type == constants.StreamType.ENCODE: stream = server.make_encode_stream() stream.output.urls[0] = stream.generate_http_link() elif stream_type == constants.StreamType.VOD_RELAY: stream = server.make_vod_relay_stream() stream.output.urls[0] = stream.generate_vod_link() elif stream_type == constants.StreamType.VOD_ENCODE: stream = server.make_vod_encode_stream() stream.output.urls[0] = stream.generate_vod_link() elif stream_type == constants.StreamType.CATCHUP: stream = server.make_catchup_stream() else: stream = server.make_test_life_stream() input_url = file['link'] if stream_type == constants.StreamType.PROXY: stream.output.urls[0].uri = input_url else: stream.input.urls[0].uri = input_url if file['title'] and len( file['title']) < constants.MAX_STREAM_NAME_LENGTH: stream.name = file['title'] if file['tvg-id'] and len( file['tvg-id']) < constants.MAX_STREAM_TVG_ID_LENGTH: stream.tvg_id = file['tvg-id'] if file['tvg-name'] and len( file['tvg-name']) < constants.MAX_STREAM_NAME_LENGTH: stream.tvg_name = file['tvg-name'] if file['tvg-group'] and len( file['tvg-group'] ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH: stream.group_title = file['tvg-group'] if file['tvg-logo'] and len( file['tvg-logo']) < constants.MAX_URL_LENGTH: logo_url = file['tvg-logo'] if is_valid_http_url(logo_url): stream.tvg_logo = logo_url stream.save() server.add_stream(stream) return redirect(url_for('ProviderView:dashboard'))
def my_channels(self): form = UploadM3uForm(type=constants.StreamType.PROXY) form.type.choices = [(constants.StreamType.PROXY, 'Proxy Stream'), (constants.StreamType.VOD_PROXY, 'Proxy Vod')] streams = [] for stream in current_user.own_streams(): streams.append(stream.to_dict()) return render_template('subscriber/my_channels.html', form=form, streams=streams)
def upload_files(self): form = UploadM3uForm() if form.validate_on_submit(): files = request.files.getlist("files") for file in files: m3u_parser = M3uParser() m3u_parser.load_content(file.read().decode('utf-8')) m3u_parser.parse() default_logo_path = constants.DEFAULT_STREAM_PREVIEW_ICON_URL for file in m3u_parser.files: if form.type.data == constants.StreamType.PROXY: stream = ProxyStream.make_stream(None) else: stream = ProxyVodStream.make_stream(None) input_url = file['link'] stream.output.urls[0].uri = input_url stream.tvg_logo = default_logo_path title = file['title'] if len(title) < constants.MAX_STREAM_NAME_LENGTH: stream.name = title tvg_id = file['tvg-id'] if len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH: stream.tvg_id = tvg_id tvg_name = file['tvg-name'] if len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH: stream.tvg_name = tvg_name tvg_group = file['tvg-group'] if len(tvg_group ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH: stream.group = tvg_group tvg_logo = file['tvg-logo'] if len(tvg_logo) < constants.MAX_URL_LENGTH: if is_valid_http_url(tvg_logo, timeout=0.1): stream.tvg_logo = tvg_logo stream.save() current_user.add_own_stream(stream) return redirect(url_for('SubscriberView:my_channels'))
def upload_m3u(self): form = UploadM3uForm() return render_template('service/upload_m3u.html', form=form)
def upload_files(self): form = UploadM3uForm() server = current_user.get_current_server() if server and form.validate_on_submit(): stream_type = form.type.data files = request.files.getlist("files") for file in files: m3u_parser = M3uParser() m3u_parser.load_content(file.read().decode('utf-8')) m3u_parser.parse() streams = [] default_logo_path = self.default_logo_url() for file in m3u_parser.files: if stream_type == constants.StreamType.PROXY: stream = server.make_proxy_stream() elif stream_type == constants.StreamType.VOD_PROXY: stream = server.make_proxy_vod() elif stream_type == constants.StreamType.RELAY: stream = server.make_relay_stream() stream.output.urls[0] = stream.generate_http_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.ENCODE: stream = server.make_encode_stream() stream.output.urls[0] = stream.generate_http_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.VOD_RELAY: stream = server.make_vod_relay_stream() stream.output.urls[0] = stream.generate_vod_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.VOD_ENCODE: stream = server.make_vod_encode_stream() stream.output.urls[0] = stream.generate_vod_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.COD_RELAY: stream = server.make_cod_relay_stream() stream.output.urls[0] = stream.generate_cod_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.COD_ENCODE: stream = server.make_cod_encode_stream() stream.output.urls[0] = stream.generate_cod_link( constants.HlsType.HLS_PULL) elif stream_type == constants.StreamType.CATCHUP: stream = server.make_catchup_stream() else: stream = server.make_test_life_stream() input_url = file['link'] if stream_type == constants.StreamType.PROXY or stream_type == constants.StreamType.VOD_PROXY: stream.output.urls[0].uri = input_url else: stream.input.urls[0].uri = input_url stream.tvg_logo = default_logo_path title = file['title'] if len(title) < constants.MAX_STREAM_NAME_LENGTH: stream.name = title tvg_id = file['tvg-id'] if len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH: stream.tvg_id = tvg_id tvg_name = file['tvg-name'] if len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH: stream.tvg_name = tvg_name tvg_group = file['tvg-group'] if len(tvg_group ) < constants.MAX_STREAM_GROUP_TITLE_LENGTH: stream.group = tvg_group tvg_logo = file['tvg-logo'] if len(tvg_logo) < constants.MAX_URL_LENGTH: if is_valid_http_url(tvg_logo, timeout=0.1): stream.tvg_logo = tvg_logo stream.save() streams.append(stream) server.add_streams(streams) return redirect(url_for('ProviderView:dashboard'))
def upload_files(self): form = UploadM3uForm() server = current_user.get_current_server() if server and form.validate_on_submit(): stream_type = form.type.data files = request.files.getlist("files") for file in files: m3u_parser = M3uParser() data = file.read().decode('utf-8') m3u_parser.load_content(data) m3u_parser.parse() streams = [] for mfile in m3u_parser.files: input_url = mfile['link'] if not is_valid_url(input_url): logging.warning('Skipped invalid url: %s', input_url) continue if stream_type == constants.StreamType.PROXY: stream_object = server.make_proxy_stream() stream = stream_object.stream() elif stream_type == constants.StreamType.VOD_PROXY: stream_object = server.make_proxy_vod() stream = stream_object.stream() elif stream_type == constants.StreamType.RELAY: stream_object = server.make_relay_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_http_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.ENCODE: stream_object = server.make_encode_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_http_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.VOD_RELAY: stream_object = server.make_vod_relay_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_vod_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.VOD_ENCODE: stream_object = server.make_vod_encode_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_vod_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.COD_RELAY: stream_object = server.make_cod_relay_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_cod_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.COD_ENCODE: stream_object = server.make_cod_encode_stream() stream = stream_object.stream() sid = stream.output[0].id stream.output = [stream_object.generate_cod_link(constants.HlsType.HLS_PULL, oid=sid)] elif stream_type == constants.StreamType.CATCHUP: stream_object = server.make_catchup_stream() stream = stream_object.stream() else: stream_object = server.make_test_life_stream() stream = stream_object.stream() if stream_type == constants.StreamType.PROXY or stream_type == constants.StreamType.VOD_PROXY: stream.output[0].uri = input_url else: stream.input[0].uri = input_url title = mfile['title'] if len(title) < constants.MAX_STREAM_NAME_LENGTH: stream.name = title tvg_id = mfile['tvg-id'] if tvg_id and len(tvg_id) < constants.MAX_STREAM_TVG_ID_LENGTH: stream.tvg_id = tvg_id tvg_name = mfile['tvg-name'] if tvg_name and len(tvg_name) < constants.MAX_STREAM_NAME_LENGTH: stream.tvg_name = tvg_name tvg_group = mfile['tvg-group'] if tvg_group: stream.groups = [tvg_group] tvg_logo = mfile['tvg-logo'] if tvg_logo and len(tvg_logo) < constants.MAX_URI_LENGTH: if is_valid_http_url(tvg_logo, timeout=0.05): stream.tvg_logo = tvg_logo is_valid_stream = stream.is_valid() if is_valid_stream: stream.save() streams.append(stream) server.add_streams(streams) return redirect(url_for('ProviderView:dashboard'))
def upload_m3u(self): form = UploadM3uForm() return render_template('autofill/upload_m3u_vods.html', form=form)