TwitchTV LiveStream Interactive Plugin

Discussion in 'Archived: Plugin Requests' started by TheFluffyWalrus, Oct 24, 2013.

  1. Offline

    TheFluffyWalrus

    Plugin category: General/Informational

    Suggested name: TwitchLive

    What I want: This plugin would consist of two parts... Part 2: really isnt that important and i would be more than satisfied with just Part 1

    Part 1: A Broadcaster that watches for when a user starts to live stream and then broadcasts a custom broadcast message for that user...


    Part 2: Integrated Live Chat that allows the user to chat with the chat-room that is integrated with Minecraft. When you do /livestream on ExampleUsername2 it would log you in to the twitch chat api allowing you to chat with the viewers the player would have to have the permission node twitchlive.exampleusername2 to be able to do /livestream on exampleusername2... the password would be hashed in the config file then decoded by the plugin to send it to the twitch.tv api

    Below is an example of how the config.yml could be set up for the broadcast part:

    Code:
    #Username & Custom broadcast config
    ExampleUsername1
    - MD5 hashedpassword
        - Custom Broadcast message when ExampleUsername1 comes online
            - Custom message broadcast interval in ticks for ExampleUsername1
        - Message when user stops live streaming
    ExampleUsername2
    - fdc94bf9572d3d1dc136a73a75c05666
        - ExampleUsername2 has started live streaming @ http://www.twitch.tv/ExampleUsername2
            - 6000
        - ExampleUsername2 has stopped live streaming
    Ideas for commands:
    /livestream login [username]
    /livestream logoff [username]

    Ideas for permissions:
    twitchlive.[username]

    When I'd like it by: Whenever is most convenient for the saint willing to create the plugin... I understand your taking the time to develop this plugin and i am eternally greatful for the person who does...

    I hope i have provided enough information to make this plugin possible thank you for looking at it...

    I have provided a link to the API you would need to be able to develop this plugin properly i hope it helps
    http://apiwiki.justin.tv/mediawiki/index.php/Main_Page
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    TheFluffyWalrus

    Dude i didnt expect anyone to even consider a look at this that fast ty for reading it ^.^
     
  4. Offline

    timtower Administrator Administrator Moderator

    No problem ;) Don't expect this to go really fast. And I am glad that you gave that API link, it is really helping
     
    AndyMcB1 likes this.
  5. Offline

    BillyGalbreath

  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    BillyGalbreath

    Oh, I didnt realize he wanted automatic.. Is that even possible?
     
  8. Offline

    timtower Administrator Administrator Moderator

    BillyGalbreath likes this.
  9. Offline

    TheFluffyWalrus

    The
    The main reason i was asking for this plugin our coder made a working due plugin but after the 1.6.4 update plugin quit working all it did was part 1 he quit working on it due to health rasons. so i figured asking someone to make a second part would be nice i was able to talk to him and after annoying him i was able to get snippets of his code i figured this would make your life easier
    Code:java
    1. +/*
    2. + * To change this template, choose Tools | Templates
    3. + * and open the template in the editor.
    4. + */
    5. +package net.twitch.livestream;
    6. +
    7. +import java.util.Map;
    8. +import org.bukkit.Bukkit;
    9. +import org.bukkit.ChatColor;
    10. +
    11. +/**
    12. + *
    13. + * @author SUPERCOMPUTER
    14. + */
    15. +public class Broadcaster implements Runnable {
    16. +
    17. + @Override
    18. + public void run() {
    19. + for (Map.Entry<String, String> entry : Main.channels.entrySet()) {
    20. + StreamStatus m = new StreamStatus();
    21. +
    22. + String key = entry.getKey();
    23. + String status = entry.getValue();
    24. +
    25. +
    26. + if (status.equalsIgnoreCase("Online")) {
    27. + Bukkit.getServer().broadcastMessage(Main.prefix + key + " is currently LiveStreaming!"
    28. + + ChatColor.GOLD+" To watch " + key + ", click:");
    29. + }
    30. + }
    31. + }
    32. +}

    Code:java
    1. +package net.twitch.livestream;
    2. +
    3. +import java.io.BufferedReader;
    4. +import java.io.IOException;
    5. +import java.io.InputStreamReader;
    6. +import java.net.URL;
    7. +import java.util.logging.Level;
    8. +import java.util.logging.Logger;
    9. +
    10. +public class StreamStatus {
    11. +
    12. + public String liveStatus(String streamname) {
    13. + String liveStatus = "Offline";
    14. + BufferedReader readurl = null;
    15. + try {
    16. +
    17. +
    18. + URL url = new URL("[url]http://api.justin.tv/api/stream/list.json?jsonp=&channel=[/url]" + streamname);
    19. + readurl = new BufferedReader(new InputStreamReader(url.openStream()));
    20. +
    21. + String wir = readurl.readLine();
    22. + String compare = "[]";
    23. +
    24. + if (wir.equals(compare)) {
    25. + liveStatus = "Offline";
    26. + } else {
    27. + liveStatus = "Online";
    28. + }
    29. +
    30. +
    31. + } catch (IOException ex) {
    32. + Logger.getLogger(StreamStatus.class.getName()).log(Level.SEVERE, null, ex);
    33. +
    34. + Logger.getLogger(StreamStatus.class.getName()).log(Level.SEVERE, null, ex);
    35. + } finally {
    36. +
    37. + try {
    38. + readurl.close();
    39. + } catch (IOException ex) {
    40. + Logger.getLogger(StreamStatus.class.getName()).log(Level.SEVERE, null, ex);
    41. + }
    42. + }
    43. + return liveStatus;
    44. +
    45. +
    46. + }
    47. +}

    Code:java
    1. +/*
    2. + * To change this template, choose Tools | Templates
    3. + * and open the template in the editor.
    4. + */
    5. +package net.twitch.livestream;
    6. +
    7. +import java.util.Map;
    8. +import org.bukkit.Bukkit;
    9. +import org.bukkit.ChatColor;
    10. +import org.bukkit.Color;
    11. +
    12. +/**
    13. + *
    14. + * @author SUPERCOMPUTER
    15. + */
    16. +public class StatusUpdater implements Runnable {
    17. +
    18. + @Override
    19. + public void run() {
    20. + if (Main.Debug) {
    21. + System.out.println("Parsing...");
    22. + }
    23. + for (Map.Entry<String, String> entry : Main.channels.entrySet()) {
    24. + StreamStatus m = new StreamStatus();
    25. + String key = entry.getKey();
    26. +
    27. + //before Check
    28. + String value = entry.getValue();
    29. + //after Check
    30. + String stat = m.liveStatus(key);
    31. +
    32. +
    33. + if (value.equalsIgnoreCase(stat)) {
    34. + if (Main.Debug) {
    35. + System.out.println("Channel " + key + " is still " + stat);
    36. + }
    37. +
    38. + } else {
    39. + if (Main.Debug) {
    40. + System.out.println("Channel " + key + " is now " + stat);
    41. + }
    42. + if (stat.equalsIgnoreCase("offline")) {
    43. + Bukkit.getServer().broadcastMessage(Main.prefix + key + " is now offline!");
    44. + }
    45. + if (stat.equalsIgnoreCase("online")) {
    46. + Bukkit.getServer().broadcastMessage(Main.prefix + key + " is now online!"
    47. + +ChatColor.GOLD+" To watch " + key + ", click: ");
    48. + }
    49. + Main.channels.put(key, stat);
    50. + }
    51. + }
    52. + if (Main.Debug) {
    53. + System.out.println(Main.channels);
    54. + }
    55. + }
    56. +}
     
  10. Offline

    timtower Administrator Administrator Moderator

    TheFluffyWalrus Code looks semi-useful, but this doesn't even do the first part completely, missing the main file
     
    AndyMcB1 likes this.
  11. Offline

    TheFluffyWalrus

    Code:java
    1. +/*
    2. + * To change this template, choose Tools | Templates
    3. + * and open the template in the editor.
    4. + */
    5. +package net.twitch.livestream;
    6. +
    7. +import java.util.HashMap;
    8. +import java.util.logging.Logger;
    9. +import org.bukkit.Bukkit;
    10. +import org.bukkit.ChatColor;
    11. +import org.bukkit.command.Command;
    12. +import org.bukkit.command.CommandSender;
    13. +import org.bukkit.plugin.PluginDescriptionFile;
    14. +import org.bukkit.plugin.java.JavaPlugin;
    15. +
    16. +/**
    17. + *
    18. + * @author SUPERCOMPUTER
    19. + */
    20. +public class Main extends JavaPlugin {
    21. +
    22. + public static HashMap<String, String> channels = new HashMap<String, String>();
    23. + public static HashMap<String, String> broadTask = new HashMap<String, String>();
    24. + public static boolean Debug = false;
    25. + public static String prefix = ChatColor.AQUA + "[" + ChatColor.RED + "KC" + ChatColor.GRAY
    26. + + "Livestream" + ChatColor.AQUA + "] " + ChatColor.YELLOW;
    27. + Logger log;
    28. +
    29. + public static int broadID = 0;
    30. + public static int statID = 0;
    31. +
    32. + @Override
    33. + public void onEnable() {
    34. +
    35. + this.log = getLogger();
    36. +
    37. + PluginDescriptionFile pdf = this.getDescription();
    38. + channels.put("usernamehere", "Offline");
    39. +
    40. +
    41. + log.info(pdf.getName() + " version " + pdf.getVersion() + " has been enabled!");
    42. + //checkUpdates();
    43. + Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Broadcaster(), 20L, 6000L);
    44. + Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new StatusUpdater(), 20L, 2400L);
    45. +
    46. + }
    47. +
    48. + @Override
    49. + public void onDisable() {
    50. + Bukkit.getServer().getScheduler().cancelTask(broadID);
    51. + Bukkit.getServer().getScheduler().cancelTask(statID);
    52. + log.info("[KCLiveStream] has been disabled!");
    53. + }
    54. +
    55. +
    56. +
    57. + @Override
    58. + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    59. +
    60. + if (cmd.getName().equalsIgnoreCase("stream")) {
    61. +
    62. +
    63. + try{
    64. +
    65. + if(args[0].equalsIgnoreCase("debug")){
    66. +
    67. + if(Main.Debug == true){
    68. + Main.Debug = false;
    69. + sender.sendMessage(prefix + "Disabled debug mode.");
    70. + }else{
    71. + Main.Debug = true;
    72. + sender.sendMessage(prefix + "Enabled debug mode.");
    73. + }
    74. +
    75. + }else if (channels.containsKey(args[0]) || channels.containsKey(args[0].toLowerCase())) {
    76. + sender.sendMessage(prefix + "Click to view: [url]http://twitch.tv/[/url]" + args[0].toLowerCase());
    77. + return true;
    78. +
    79. + } else {
    80. + sender.sendMessage(prefix + "Channel not found! Valid channels: " + channels.keySet());
    81. + return true;
    82. + }
    83. +
    84. +
    85. + sender.sendMessage(prefix+" Incorrect syntax! /stream <Channel> ");
    86. + return true;
    87. + }
    88. +
    89. +
    90. + }
    91. + return false;
    92. + }
    93. +}


    should be the main for you
     
  12. Offline

    timtower Administrator Administrator Moderator

    TheFluffyWalrus That was the thing I was talking about, but I think that I will make this from scratch, then I know what I am doing.
     
  13. Offline

    TheFluffyWalrus

    i would prefer you use it from scratch lol i figured you would like to see the code at least of the previous plugin so you could see that it was possible... for part 1 i hope its helped at least for a reference on how he did it
     
  14. Offline

    DarkRiddles

    What tim said...
     
  15. Offline

    timtower Administrator Administrator Moderator

  16. Offline

    TheFluffyWalrus

    Very Grateful! XD And The name YES thats awesome! lol by any chance do you release your code or do you keep it closed source
     
  17. Offline

    timtower Administrator Administrator Moderator

    Mostly using LikeMe in my plugin names, and if people want the source they can PM me
     
  18. Offline

    TheFluffyWalrus

    very cool by any chance could you add a reload command to the plugin so once you edit the config if not ill just use Plug Manager to reload the plugin again thank you didnt expect anyone to write a plugin so quickly very impressed

    also forgot to ask is it server ticks or in seconds?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  19. Offline

    timtower Administrator Administrator Moderator

    Working on it.
    For easy usage I used seconds
     
    TheFluffyWalrus likes this.
  20. Offline

    TheFluffyWalrus


    I also noticed when you load the plugin it forces your live stream info back into the config file was that on purpose or just a fluke? no biggie to me just thought it was interesting
     
  21. Offline

    timtower Administrator Administrator Moderator

    Already know what is causing that (facepalm)
     
    TheFluffyWalrus likes this.
  22. Offline

    TheFluffyWalrus

    lol its all cool so i think you should submit this to bukkit it is quite nice and im more than impressed
    i feel like im asking so much again thank you so much
     
  23. Offline

    timtower Administrator Administrator Moderator

    https://www.dropbox.com/s/pxpmc5wy8ys7vcu/TwitchLikeMe.jar
    TwitchLikeMe:
    description: Main command
    usage: /TwitchLikeMe
    permission: twitchlikeme.command
    permission-message: You dont have permission to use this
     
  24. Offline

    TheFluffyWalrus

    The plugin has worked perfectly since recently we are getting these errors
    Code:
    2013-11-18 08:01:19 [SEVERE] java.net.UnknownHostException: api.justin.tv
    2013-11-18 08:01:19 [SEVERE]    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    2013-11-18 08:01:19 [SEVERE]    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    2013-11-18 08:01:19 [SEVERE]    at java.net.Socket.connect(Socket.java:579)
    2013-11-18 08:01:19 [SEVERE]    at java.net.Socket.connect(Socket.java:528)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    2013-11-18 08:01:19 [SEVERE]    at java.net.URL.openStream(URL.java:1037)
    2013-11-18 08:01:19 [SEVERE]    at nl.timdebrouwer.twitchlikeme.Broadcaster.getStatus(Broadcaster.java:50)
    2013-11-18 08:01:19 [SEVERE]    at nl.timdebrouwer.twitchlikeme.BroadcastCheckRunner.run(BroadcastCheckRunner.java:10)
    2013-11-18 08:01:19 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    2013-11-18 08:01:19 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    2013-11-18 08:01:19 [SEVERE] java.net.UnknownHostException: api.justin.tv
    2013-11-18 08:01:19 [SEVERE]    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    2013-11-18 08:01:19 [SEVERE]    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    2013-11-18 08:01:19 [SEVERE]    at java.net.Socket.connect(Socket.java:579)
    2013-11-18 08:01:19 [SEVERE]    at java.net.Socket.connect(Socket.java:528)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    2013-11-18 08:01:19 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    2013-11-18 08:01:19 [SEVERE]    at java.net.URL.openStream(URL.java:1037)
    2013-11-18 08:01:19 [SEVERE]    at nl.timdebrouwer.twitchlikeme.Broadcaster.getStatus(Broadcaster.java:50)
    2013-11-18 08:01:19 [SEVERE]    at nl.timdebrouwer.twitchlikeme.BroadcastCheckRunner.run(BroadcastCheckRunner.java:10)
    2013-11-18 08:01:19 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    2013-11-18 08:01:19 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    2013-11-18 08:01:19 [SEVERE]    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Code:
    2013-11-18 08:05:41 [SEVERE] java.io.IOException: Server returned HTTP response code: 502 for URL: http://api.justin.tv/api/stream/list.json?channel=rushnett
    2013-11-18 08:05:41 [SEVERE]    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
    2013-11-18 08:05:41 [SEVERE]    at java.net.URL.openStream(URL.java:1037)
    2013-11-18 08:05:41 [SEVERE]    at nl.timdebrouwer.twitchlikeme.Broadcaster.getStatus(Broadcaster.java:50)
    2013-11-18 08:05:41 [SEVERE]    at nl.timdebrouwer.twitchlikeme.BroadcastCheckRunner.run(BroadcastCheckRunner.java:10)
    2013-11-18 08:05:41 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    2013-11-18 08:05:41 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2013-11-18 08:05:41 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    2013-11-18 08:05:41 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    2013-11-18 08:05:41 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    2013-11-18 08:05:41 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    2013-11-18 08:05:41 [SEVERE]    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    i figured i would let you know
     
  25. Offline

    timtower Administrator Administrator Moderator

    TheFluffyWalrus Next time when this happens try opening that link yourself, if you also get an error then it is an issue server side at twitch, will add an exception for this so you won't get this message anymore ;)
     
  26. Offline

    TheFluffyWalrus

    ty XD this plugin has been quite nice we appreciate you
     
  27. Offline

    timtower Administrator Administrator Moderator

  28. Offline

    AndyMcB1

    Don't forget Twitch integration is being added into MC :p
     
  29. Offline

    timtower Administrator Administrator Moderator

    Even more use for this plugin :p
     
    Mathias Eklund likes this.
  30. Offline

    TheFluffyWalrus

    That means my asking for this plugin was perfect timing lol
     
    timtower likes this.

Share This Page