<commit_before>#!/usr/bin/env python3.3

import http.server
import socketserver
import socket
import subprocess
import re
import configparser

import jinja2
import sirius


class SeriousHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
    daemon_threads = True


class SeriousRequestHandler(http.server.BaseHTTPRequestHandler):
    def channel_stream(self, channel_number):
        channel = sxm.lineup[channel_number]

        self.protocol_version = 'ICY' # if we don't pretend to be shoutcast, doctors HATE us
        self.log_request(200)
        self.send_response_only(200)
        self.send_header('Content-type', 'audio/aacp')
        self.send_header('icy-br', '64')
        self.send_header('icy-name', channel['name'])
        self.send_header('icy-genre', channel['genre'])
        self.send_header('icy-url', url)
        self.end_headers()

        channel_id = str(channel['channelKey'])

        for packet in sxm.packet_generator(channel_id):
            command = ['ffmpeg', '-i', 'pipe:0', '-y', '-map', '0:1', '-c:a', 'copy', '-f', 'adts', 'pipe:1']
            proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            adts_data = proc.communicate(packet)[0]
            try:
                self.wfile.write(adts_data)
            except (ConnectionResetError, ConnectionAbortedError) as e:
                print('Connection dropped: ', e)
                return

        self.wfile.write(b'\r\n\r\n')


    def channel_playlist(self, channel_number):
        self.send_response(200)
        self.send_header('Content-type', 'audio/x-scpls')
        self.send_header('Content-disposition', 'attachment; filename="{} - {}.pls"'.format(
            channel_number, sxm.lineup[channel_number]['name']))
        self.end_headers()

        template = templates.get_template('playlist.pls')
        playlist = template.render({'url': url + 'channel/{}'.format(
            channel_number)})

        self.wfile.write(playlist.encode('utf-8'))
        self.wfile.write(b'\r\n\r\n')


    def index(self):
        self.send_response(200)<commit_msg>Added padding to audio chunks for metadata support<commit_after>#!/usr/bin/env python3.3

import http.server
import socketserver
import socket
import subprocess
import re
import configparser

import jinja2
import sirius


class SeriousHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
    daemon_threads = True


class SeriousRequestHandler(http.server.BaseHTTPRequestHandler):
    def channel_stream(self, channel_number):
        channel = sxm.lineup[channel_number]

        self.protocol_version = 'ICY' # if we don't pretend to be shoutcast, doctors HATE us
        self.log_request(200)
        self.send_response_only(200)
        self.send_header('Content-type', 'audio/aacp')
        self.send_header('icy-br', '64')
        self.send_header('icy-name', channel['name'])
        self.send_header('icy-genre', channel['genre'])
        self.send_header('icy-url', url)
        self.end_headers()

        channel_id = str(channel['channelKey'])

        for packet in sxm.packet_generator(channel_id):
            command = ['ffmpeg', '-i', 'pipe:0', '-y', '-map', '0:1', '-c:a', 'copy', '-f', 'adts', 'pipe:1']
            proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
            adts_data = proc.communicate(packet)[0]
            adts_data += b'\0' * (180000 - len(adts_data))
            print(len(adts_data))
            try:
                self.wfile.write(adts_data)
            except (ConnectionResetError, ConnectionAbortedError) as e:
                print('Connection dropped: ', e)
                return

        self.wfile.write(b'\r\n\r\n')


    def channel_playlist(self, channel_number):
        self.send_response(200)
        self.send_header('Content-type', 'audio/x-scpls')
        self.send_header('Content-disposition', 'attachment; filename="{} - {}.pls"'.format(
            channel_number, sxm.lineup[channel_number]['name']))
        self.end_headers()

        template = templates.get_template('playlist.pls')
        playlist = template.render({'url': url + 'channel/{}'.format(
            channel_number)})

        self.wfile.write(playlist.encode('utf-8'))
        self.wfile.write(b'\r\n\r\n')


    def index(self):
        self.send_response(200)
{'fraction_non_alphanumeric': 0.13757932910244786, 'fraction_numerical': 0.01201269265639166, 'mean_word_length': 2.919182948490231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2693942', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1374, 'n_words': 245}