<commit_before>// Copyright 2014, Truveris Inc. All Rights Reserved.

package main

import (
	"crypto/md5"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"os/exec"
	"path"
	"strings"
)

func PathIsHttp(path string) bool {
	if strings.HasPrefix(path, "http://") {
		return true
	}

	if strings.HasPrefix(path, "https://") {
		return true
	}

	return false
}

func MD5(url string) string {
	h := md5.New()
	io.WriteString(h, url)
	return fmt.Sprintf("%x", h.Sum(nil))
}

func getRemoteSize(url string) int64 {
	resp, err := http.Head(url)
	if err != nil {
		return 0
	}

	return resp.ContentLength
}

// Download the given URL to the given filepath.
func downloadFile(url, filepath string) error {
	resp, err := http.Get(url)
	if err != nil {
		return err
	}

	file, err := os.Create(filepath)
	if err != nil {
		return err
	}

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		return err
	}

	return nil
}

func mplayer(tune Noise) *exec.Cmd {
	var filepath string
	var cmd *exec.Cmd

	if PathIsHttp(tune.Path) {
		log.Printf("play: path is http")
		size := getRemoteSize(tune.Path)
		if size == 0 {
			log.Printf("play: unable to read HTTP length")
			// say("unable to read HTTP length")<commit_msg>according to the doc: The client must close the response body when finished with it<commit_after>// Copyright 2014, Truveris Inc. All Rights Reserved.

package main

import (
	"crypto/md5"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"os/exec"
	"path"
	"strings"
)

func PathIsHttp(path string) bool {
	if strings.HasPrefix(path, "http://") {
		return true
	}

	if strings.HasPrefix(path, "https://") {
		return true
	}

	return false
}

func MD5(url string) string {
	h := md5.New()
	io.WriteString(h, url)
	return fmt.Sprintf("%x", h.Sum(nil))
}

func getRemoteSize(url string) int64 {
	resp, err := http.Head(url)
	if err != nil {
		return 0
	}

	return resp.ContentLength
}

// Download the given URL to the given filepath.
func downloadFile(url, filepath string) error {
	resp, err := http.Get(url)
	if err != nil {
		return err
	}

	defer resp.Body.Close()

	file, err := os.Create(filepath)
	if err != nil {
		return err
	}

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		return err
	}

	return nil
}

func mplayer(tune Noise) *exec.Cmd {
	var filepath string
	var cmd *exec.Cmd

	if PathIsHttp(tune.Path) {
		log.Printf("play: path is http")
		size := getRemoteSize(tune.Path)
		if size == 0 {
			log.Printf("play: unable to read HTTP length")
			// say("unable to read HTTP length")
{'fraction_non_alphanumeric': 0.13946945337620578, 'fraction_numerical': 0.008842443729903537, 'mean_word_length': 3.343804537521815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4294836', 'n_tokens_mistral': 993, 'n_tokens_neox': 940, 'n_words': 279}