<commit_before>package org.talkingpuffin.util

import java.net.{HttpURLConnection, URL}
import org.talkingpuffin.ui.LinkExtractor

/**
 * URL shortening and expanding.
 */
object ShortUrl extends Loggable {
  private val shortenerRegexStrings = List("""http://digg\.com/""" + LinkExtractor.urlCharClass + "{4,10}")
  private val shortenerRegexes = shortenerRegexStrings.map(_.r)
  private val redirBypassesWrapperHosts = List("su.pr", "ow.ly")
  private val shortenerDomains = List("bit.ly", "ff.im", "is.gd", "j.mp", "ping.fm", 
    "r2.ly", "short.ie", "su.pr", 
    "tinyurl.com", "tr.im") ::: redirBypassesWrapperHosts
  private val regex = "http://(" + shortenerDomains.map(_.replace(".","""\.""")).mkString("|") + ")/" + 
      LinkExtractor.urlCharClass + "*"
  private val redirectionCodes = List(301, 302)
  private type LongUrlReady = ResourceReady[String,String]
  
  private val fetcher = new BackgroundResourceFetcher[String, String]("URL") {
    override def getResourceFromSource(urlString: String): String = {
      debug("Connecting to " + urlString)
      val url = new URL(urlString)
      val conn = url.openConnection.asInstanceOf[HttpURLConnection]
      conn.setRequestMethod("HEAD")
      conn.setInstanceFollowRedirects(false)
      conn.setRequestProperty("User-agent", "TalkingPuffin")
      if (redirectionCodes.contains(conn.getResponseCode)) {
        val loc = {
          val locHeader = conn.getHeaderField("Location")
          if (locHeader.startsWith("/")) (new URL(url.getProtocol, url.getHost, locHeader)).toString else locHeader
        }
        debug("Redirected to " + loc)
        loc
      } else {<commit_msg>Add some more URL shortening service domain names. (These should come from a config file.)<commit_after>package org.talkingpuffin.util

import java.net.{HttpURLConnection, URL}
import org.talkingpuffin.ui.LinkExtractor

/**
 * URL shortening and expanding.
 */
object ShortUrl extends Loggable {
  private val shortenerRegexStrings = List("""http://digg\.com/""" + LinkExtractor.urlCharClass + "{4,10}")
  private val shortenerRegexes = shortenerRegexStrings.map(_.r)
  private val redirBypassesWrapperHosts = List("su.pr", "ow.ly")
  private val shortenerDomains = List("bit.ly", "ff.im", "is.gd", "j.mp", "ping.fm", 
    "r2.ly", "short.ie", "su.pr", 
    "tinyurl.com", "tr.im", "goo.gl", "t.co", "huff.to", "scoble.it", "oreil.ly") ::: redirBypassesWrapperHosts
  private val regex = "http://(" + shortenerDomains.map(_.replace(".","""\.""")).mkString("|") + ")/" + 
      LinkExtractor.urlCharClass + "*"
  private val redirectionCodes = List(301, 302)
  private type LongUrlReady = ResourceReady[String,String]
  
  private val fetcher = new BackgroundResourceFetcher[String, String]("URL") {
    override def getResourceFromSource(urlString: String): String = {
      debug("Connecting to " + urlString)
      val url = new URL(urlString)
      val conn = url.openConnection.asInstanceOf[HttpURLConnection]
      conn.setRequestMethod("HEAD")
      conn.setInstanceFollowRedirects(false)
      conn.setRequestProperty("User-agent", "TalkingPuffin")
      if (redirectionCodes.contains(conn.getResponseCode)) {
        val loc = {
          val locHeader = conn.getHeaderField("Location")
          if (locHeader.startsWith("/")) (new URL(url.getProtocol, url.getHost, locHeader)).toString else locHeader
        }
        debug("Redirected to " + loc)
        loc
      } else {
{'fraction_non_alphanumeric': 0.14655423088107009, 'fraction_numerical': 0.005815644082582146, 'mean_word_length': 3.8933143669985775, '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': '4507505', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1081, 'n_words': 227}