Skip to content

Commit

Permalink
fixed views/date for some languages | improved YouTubeLink slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ckscor3 committed Jun 8, 2016
1 parent 1304052 commit 3504937
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Devoice Geffy if he joins #bl4ckscor3
- Fixed private commands not working
- Fixed LinkManager sometimes executing ShowTweet code if "twitter" was present in the link itself
- Fixed YouTube stats' date and views for (probably) all languages using latin letters
- Internal changes

####5.7.2
Expand Down
12 changes: 4 additions & 8 deletions src/bl4ckscor3/bot/bl4ckb0t/misc/YouTubeStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ else if(s.contains("youtu.be/"))
if(currentLink != 0)
Utilities.sendMessage(channel, "------------------------------------------");

if(link.isShortLink())
link.setLink("www.youtube.com/watch?v=" + link.getLink().split("/")[3]);

//if someone posts the link without a space between the link and the word before it
if(!link.getLink().startsWith("w"))
link.setLink(link.getLink().split(":")[1].substring(2));
Expand All @@ -78,7 +75,7 @@ else if(s.contains("youtu.be/"))
Document doc = Jsoup.connect(link.getLink()).get();

title = doc.select("#eow-title").get(0).text();
views = doc.select(".watch-view-count").get(0).text().split(" ")[0];
views = doc.select(".watch-view-count").get(0).text();

try
{
Expand All @@ -90,12 +87,11 @@ else if(s.contains("youtu.be/"))
likes = (dislikes = L10N.getString("youtube.ratingDisabled", channel));
}

date = doc.select(".watch-time-text").get(0).text().split(" ")[2].trim();
date = doc.select(".watch-time-text").get(0).text();
uploader = doc.select(".yt-user-info > a:nth-child(1)").get(0).text();

if(!views.matches("[0-9.\\+]*")) //any amount of numbers with . and + inbetween
views = "0";

date = date.replaceAll("[^0-9.][^ A-Za-z ]*3", ""); //replace everything except 3 letters surrounded by spaces, numbers and . with nothing
views = views.replaceAll("[^0-9+.]", ""); //replace everything except numbers, + and . with nothing
Utilities.sendStarMsg(channel,
Colors.BOLD + Utilities.backgroundColor(Colors.WHITE, Colors.BLACK) + "You" + Utilities.backgroundColor(Colors.RED, Colors.WHITE) + "Tube" + Colors.NORMAL,
Colors.BOLD + L10N.getString("youtube.title", channel) + ": " + Colors.NORMAL + title,
Expand Down
12 changes: 1 addition & 11 deletions src/bl4ckscor3/bot/bl4ckb0t/util/YouTubeLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class YouTubeLink
{
private String link;
private boolean shortLink;

/**
* Saves information while a YouTube link is being analyzed
Expand All @@ -12,8 +11,7 @@ public class YouTubeLink
*/
public YouTubeLink(String l, boolean s)
{
link = l;
shortLink = s;
link = s ? "www.youtube.com/watch?v=" + l.split("/")[3] : l;
}

/**
Expand All @@ -32,12 +30,4 @@ public String getLink()
{
return link;
}

/**
* @return true if the link is a short link, false otherwise
*/
public boolean isShortLink()
{
return shortLink;
}
}

0 comments on commit 3504937

Please sign in to comment.