Skip to content

Commit

Permalink
Implemented slection for past broadacasts and highlights with radio b…
Browse files Browse the repository at this point in the history
…uttons
  • Loading branch information
LordH3lmchen committed Jun 4, 2015
1 parent abe73a0 commit 9c23ac3
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 45 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@


[ProjectPage](http://lordh3lmchen.github.io/TwitchDownloader)

It's a small tool to download past broadcasts from Twitch.tv. You can enter a URL to a past broadcast.

# HowTo use it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public JPanel getMainPanel() {
}

@Override
public void searchFldText(String text) throws IOException {
public void searchFldText(String text, boolean pastBroadcasts) throws IOException {

ArrayList<TwitchVideoInfo> cachedTVIs = new ArrayList<>();

Expand All @@ -163,7 +163,7 @@ public void searchFldText(String text) throws IOException {
}
}

twitchVideoInfoList.update(text, true, 40, 0, cachedTVIs); //Updates Videos Except new
twitchVideoInfoList.update(text, pastBroadcasts, 40, 0, cachedTVIs); //Updates Videos Except new
for(TwitchVideoInfo tvi: twitchVideoInfoList.getTwitchVideoInfos()) { //Search related file on disk
searchLocalFiles(tvi);
}
Expand Down Expand Up @@ -331,7 +331,7 @@ private void initializeDownload() {
String quality = currentTwitchVideoInfo.getDownloadInfo().getPreferedQuality(TwitchToolPreferences.getQualityOrder()); //select quality based on TwitchToolsPreferences
videoParts = currentTwitchVideoInfo.getDownloadInfo().getTwitchBroadcastParts(quality); //get the Parts of a Video
} catch (IOException e) {
JOptionPane.showMessageDialog(mainPanel, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); //TODO JDialog Output
JOptionPane.showMessageDialog(mainPanel, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
mainPanel.getDownloadProgressPanel().setMaximum(videoParts.size() * 100);
mainPanel.getDownloadProgressPanel().setValue(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ChannelSyncControllerInterface extends ActionListener, Property

public JPanel getMainPanel();

void searchFldText(String text) throws IOException;
void searchFldText(String text, boolean pastBroadcasts) throws IOException;

void openUrlInBrowser(URL url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void actionPerformed(ActionEvent e) {
if(e.getSource()==closeBtn) {
this.setVisible(false);
} else if(e.getSource()==licenseBtn) {
this.setVisible(false); //TODO show license instead
this.setVisible(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class SyncChannelMainPanel extends JPanel implements PropertyChangeListen
private final JPanel bottomPanel;
private final JButton downloadAllBtn;
private final JButton selectMostRecentBtn;
private final JRadioButton highlightRadioBtn;
private final JRadioButton pastBroadcastsRadioBtn;
private final JSpinner recentDaysSpinner;
private final JLabel daysLabel;
private OverallProgressPanel downloadProgressPanel;
Expand Down Expand Up @@ -69,6 +71,17 @@ public SyncChannelMainPanel(ChannelSyncController controller, TwitchVideoInfoLis
downloadAllBtn.addActionListener(this);
loadMoreBtn = new JButton("load more ... ");
loadMoreBtn.addActionListener(this);

highlightRadioBtn = new JRadioButton("Highlights");
pastBroadcastsRadioBtn = new JRadioButton("Past Broadcasts");
ButtonGroup vodTypeBtnGroup = new ButtonGroup();
vodTypeBtnGroup.add(highlightRadioBtn);
vodTypeBtnGroup.add(pastBroadcastsRadioBtn);
pastBroadcastsRadioBtn.setSelected(true);
highlightRadioBtn.addActionListener(this);
pastBroadcastsRadioBtn.addActionListener(this);


selectMostRecentBtn = new JButton("Select most Recent");
// selectMostRecentBtn.setEnabled(false);
selectMostRecentBtn.addActionListener(this);
Expand Down Expand Up @@ -117,6 +130,12 @@ private void layoutComponents() {

c.weightx = 0.0;
c.gridx = 2;
channelInputPanel.add(highlightRadioBtn, c);

c.gridx++;
channelInputPanel.add(pastBroadcastsRadioBtn, c);

c.gridx++;
channelInputPanel.add(channelInputBtn, c);


Expand All @@ -139,9 +158,6 @@ private void layoutComponents() {
c.gridy++;
bottomPanel.add(convertProgressPanel, c);




c.gridx=0;
c.gridy++;
c.weightx=0.0;
Expand Down Expand Up @@ -236,7 +252,7 @@ public void actionPerformed(ActionEvent e) {

if (e.getSource() == channelInputBtn || e.getSource() == channelInputFld) {
try {
controller.searchFldText(channelInputFld.getText());
controller.searchFldText(channelInputFld.getText(), pastBroadcastsRadioBtn.isSelected());
} catch (MalformedURLException e1) {
JOptionPane.showMessageDialog(this, "Weird Channel Input " + channelInputFld.getText() + " isn't a valid channel name", "Invalid channel namen", JOptionPane.ERROR_MESSAGE);
e1.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private void layoutComponents() {
c.insets = new Insets(2, 2, 2, 2);
c.gridy++;
c.gridwidth=2;
// title. //TODO limit width
add(titleLbl, c);
titleLbl.setMinimumSize(new Dimension(300, 20));
titleLbl.setMaximumSize(new Dimension(300, 100));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ public void addObserver(Observer observer) {
}


class Chunks { //TODO maybe anyone has a solution to replace that with a Hashmap (Twitch could change the names of qualities from time to time)
class Chunks {
// maybe anyone has a better solution to replace that with a Hashmap (Twitch could change the names
// of qualities from time to time)

// no need for a better solution. Twitch changed VODs entirely. This ist still remaining to be compatible
// to old VODs

@SerializedName("live")private ArrayList<TwitchVideoPart> source;
@SerializedName("240p")private ArrayList<TwitchVideoPart> mobile;
@SerializedName("360p")private ArrayList<TwitchVideoPart> low;
Expand Down
11 changes: 9 additions & 2 deletions src/com/trabauer/twitchtools/model/twitch/TwitchStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ public int hashCode() {
return result;
}


public static TwitchStream getTwitchStream(String channelName) throws IOException {
/**
* Creates a TwitchStream object from https://api.twitch.tv/kraken/channels/channelname
*
*
* @param channelName
* @return
* @throws IOException
*/
public static TwitchStream getTwitchStreamFromAPI(String channelName) throws IOException {
URL streamApiURL = new URL(APIURL + channelName);
InputStream is = streamApiURL.openStream();
InputStreamReader ir = new InputStreamReader(is);
Expand Down
32 changes: 5 additions & 27 deletions src/com/trabauer/twitchtools/model/twitch/TwitchVideoInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,6 @@ public int hashCode() {
public String channel;
}

// private class Channel { //TODO remove this class
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Channel channel = (Channel) o;
//
// if (!name.equals(channel.name)) return false;
//
// return true;
// }
//
// @Override
// public int hashCode() {
// return name.hashCode();
// }
//
// public String name;
// @SerializedName("display_name")
// public String displayName;
// }

public void addPropertyChangeListenern(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}
Expand Down Expand Up @@ -266,6 +242,8 @@ public void update(String id) throws IOException {
}

public void update(TwitchVideoInfo tvi) {
if(this.channel == null) this.channel = new TwitchChannel();
if(this.links == null) this.links = new Links();
setTitle(tvi.title);
setDescription(tvi.description);
setBroadcastId(tvi.broadcastId);
Expand Down Expand Up @@ -403,7 +381,7 @@ private void updateDLinfoNewVodSystem() throws IOException {
Scanner qualityPlaylistSc = new Scanner(qualityPlaylistIs);
while (qualityPlaylistSc.hasNextLine()) {
String line = qualityPlaylistSc.nextLine();
System.out.println(line);
// System.out.println(line);
if (!Pattern.matches("^#.*$", line)) { //filter Out comment lines
String quality = line.split("/")[7];
URL playlistUrl = new URL(line);
Expand All @@ -416,8 +394,8 @@ private void updateDLinfoNewVodSystem() throws IOException {
if (partLine.isEmpty())
continue;
if (!Pattern.matches("^#.*$", partLine)) { // filter out Comments
partLine = line.replace("index-dvr.m3u8", "").concat(partLine);
// this.addTwitchVideoPart(quality, new TwitchVideoPart(new URL(partLine), partNumber++));
String m3uFilename = new File(playlistUrl.getFile()).getName();
partLine = line.replace(m3uFilename, "").concat(partLine);
TwitchVideoPart tbp = new TwitchVideoPart(partLine, -1, null , null);
if(quality.equals("chunked")) dlInfo.addSourceTwitchBroadcastPart(tbp);
else if(quality.equals("high")) dlInfo.addHighTwitchBroadcastPart(tbp);
Expand Down
17 changes: 15 additions & 2 deletions src/com/trabauer/twitchtools/tests/TwitchApiTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.trabauer.twitchtools.model.twitch.TwitchChannel;
import com.trabauer.twitchtools.model.twitch.TwitchStream;
import com.trabauer.twitchtools.model.twitch.TwitchVideoInfo;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -31,19 +32,31 @@ public void channelTest() {
public void streamTest() {
TwitchStream takeTvStream = null;
try {
takeTvStream = TwitchStream.getTwitchStream("taketv");
takeTvStream = TwitchStream.getTwitchStreamFromAPI("taketv");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(takeTvStream);
// cryaotic
TwitchStream cryaoticStream = null;
try {
cryaoticStream = TwitchStream.getTwitchStream("cryaotic");
cryaoticStream = TwitchStream.getTwitchStreamFromAPI("cryaotic");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(cryaoticStream);

}

@Test
public void highlightTest() {
TwitchVideoInfo tvi = new TwitchVideoInfo();
try {
tvi.update("v5724050");
tvi.getDownloadInfo();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(tvi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ protected Void doInBackground() throws Exception {

if(relatedTvi!=null) {
relatedTvi.setState(TwitchVideoInfo.State.CONVERTED);
relatedTvi.setMainRelatedFileOnDisk(destinationVideoFile); //TODO is now done by the converter worker after converting. Testing required!
relatedTvi.setMainRelatedFileOnDisk(destinationVideoFile);
}



return null;
}

Expand Down

0 comments on commit 9c23ac3

Please sign in to comment.