Skip to content

Commit

Permalink
Video length is a double vlaue on Twitch. changed to double in the Mo…
Browse files Browse the repository at this point in the history
…del and cast it to int. Improved the Download Worker. It should be more reliable. twitch has some issues lattly resulting to an incomplete download.
  • Loading branch information
LordH3lmchen committed Jul 19, 2015
1 parent ad5b1a5 commit c7ecd12
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public ChannelSyncController() {
this.progressFrame = new ChannelSyncLogFrame();
this.playlistFolderPath = TwitchToolPreferences.getInstance().get(TwitchToolPreferences.DESTINATION_DIR_PREFKEY, OsUtils.getUserHome()) + "/playlists/";
this.ffmpegExecutorService = new ThreadPoolExecutor(1, 1, 5000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
this.downloadExecutorService = new ThreadPoolExecutor(15, 15, 5000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
this.downloadExecutorService = new ThreadPoolExecutor(10, 10, 5000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); // (15, 15, 5000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>())

twitchVideoInfoWorkerQueue = new LinkedBlockingQueue<>();

Expand Down Expand Up @@ -441,6 +441,10 @@ private void concatVideoParts(TwitchVideoInfo tvi) {
Scanner sc = new Scanner(playlist);
while (sc.hasNextLine()) {
File videoPart = new File(sc.nextLine());
if(! videoPart.canRead()) {
System.err.printf("Unable to read %s, skipping file", videoPart);
continue;
}
if (outputStream == null) {
if (! videoPart.getPath().endsWith(".ts")) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class VideoInfoPanel extends JPanel implements ItemListener, ActionListen
private final JButton playBtn;
private final JButton convertBtn;
private final JButton deleteBtn;
private final JButton prefrencesBtn;

private final JLabel channelDisplayNameLbl;
private final JCheckBox markForBatchCheckbo;
Expand All @@ -63,9 +64,12 @@ public class VideoInfoPanel extends JPanel implements ItemListener, ActionListen
private static final Border downloadingBorder = BorderFactory.createMatteBorder(borderWidth, borderWidth, borderWidth, borderWidth, downloadingColor);
private static final Border convertingBorder = BorderFactory.createMatteBorder(borderWidth, borderWidth, borderWidth, borderWidth, convertingColor);


public VideoInfoPanel(final TwitchVideoInfo relatedTwitchVideoInfoObject, final ChannelSyncControllerInterface controller) throws IOException {
this.relatedTwitchVideoInfoObject = relatedTwitchVideoInfoObject;
this.relatedTwitchVideoInfoObject.addPropertyChangeListenern(this);


this.controller = controller;
setLayout(new GridBagLayout());

Expand Down Expand Up @@ -181,6 +185,10 @@ public void mouseClicked(MouseEvent e) {
playBtn.setActionCommand("watchVideo");
playBtn.addActionListener(this);

prefrencesBtn = new JButton("Prefrences");
prefrencesBtn.setActionCommand("prefrencesBtn");
prefrencesBtn.addActionListener(this);


convertBtn = new JButton("Convert");
convertBtn.addActionListener(this);
Expand Down Expand Up @@ -208,9 +216,9 @@ public void mouseClicked(MouseEvent e) {
private void layoutComponents() {

imageLbl.setBounds(0,0 ,320,180);
viewcountLbl.setBounds(5,0,310,25);
viewcountLbl.setBounds(5, 0, 310, 25);
viewcountLbl.setHorizontalAlignment(SwingConstants.LEFT);
durationLbl.setBounds(5,0,310,25);
durationLbl.setBounds(5, 0, 310, 25);
durationLbl.setHorizontalAlignment(SwingConstants.RIGHT);
//Adding a dark bar to the previewImage to increase the readability of the viewcount and duration
darkBarkLbl.setBounds(0,0,320,25);
Expand Down Expand Up @@ -267,6 +275,7 @@ private void layoutComponents() {

btnPanel.add(deleteBtn);
btnPanel.add(convertBtn);
btnPanel.add(prefrencesBtn);
btnPanel.add(downloadBtn);
btnPanel.add(playBtn);
add(btnPanel, c);
Expand All @@ -278,6 +287,7 @@ private void layoutComponents() {

private void setInitialLayout() {
downloadBtn.setVisible(true);
prefrencesBtn.setVisible(false); //TODO set to true whenn implemented
playBtn.setVisible(false);
deleteBtn.setVisible(false);
convertBtn.setVisible(false);
Expand All @@ -293,6 +303,7 @@ private void setDownloadingLayout() {

private void setDownloadedLayout() {
downloadBtn.setVisible(false);
prefrencesBtn.setVisible(false);
deleteBtn.setVisible(true);
deleteBtn.setEnabled(true);
playBtn.setVisible(true);
Expand Down Expand Up @@ -320,6 +331,7 @@ private void setQueuedLayout() {
deleteBtn.setEnabled(false);
downloadBtn.setEnabled(false);
markForBatchCheckbo.setEnabled(false);
prefrencesBtn.setEnabled(false);
}


Expand Down Expand Up @@ -355,9 +367,17 @@ public void actionPerformed(ActionEvent e) {
// Nothing right now
}

} else if(e.getSource() == prefrencesBtn) {
createPrefrenceDialog();
}
}

private void createPrefrenceDialog() {
VideoInfoPreferencesDialog preferencesDialog = new VideoInfoPreferencesDialog();
preferencesDialog.setVisible(true);

}

@Override
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==markForBatchCheckbo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.trabauer.twitchtools.gui.vod.channelsync;

import com.trabauer.twitchtools.model.twitch.TwitchVideoInfo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* Created by flo on 7/19/15.
*/
public class VideoInfoPreferencesDialog extends JDialog implements ActionListener {

private TwitchVideoInfo tvi;

private JTextField startOffsetFld;
private JSlider startOffsetSlider;
private JLabel startOffsetTimeLbl;

private JTextField endOffsetFld;
private JSlider endOffsetSlider;
private JLabel endOffsetTimeLbl;

JButton okBtn;

public VideoInfoPreferencesDialog() {
super();

setTitle("Video Download Settings");
GridBagLayout layout = new GridBagLayout();
this.setLayout(layout);
GridBagConstraints c = new GridBagConstraints();

startOffsetFld = new JTextField();
startOffsetFld.setColumns(10);
startOffsetSlider = new JSlider();
startOffsetTimeLbl = new JLabel("00:00:00");

endOffsetFld = new JTextField();
endOffsetFld.setColumns(10);
endOffsetSlider = new JSlider();
endOffsetTimeLbl = new JLabel("00:00:00");

okBtn = new JButton("OK");
okBtn.addActionListener(this);
okBtn.setActionCommand("okBtn");

// Start Offset
c.anchor = GridBagConstraints.LINE_START;
c.gridy = 0;
c.gridx = 0;
c.gridwidth = 4;
add(new JLabel("Start Offset"), c);

c.gridy++;
c.gridwidth=1;
add(new JLabel("Sec"), c);

c.gridx++;
add(startOffsetFld, c);

c.gridx++;
add(startOffsetSlider, c);

c.gridx++;
add(startOffsetTimeLbl, c);

//END Offset
c.gridy++;
c.gridx = 0;
c.gridwidth = 4;
add(new JLabel("End Offset"), c);

c.gridy++;
c.gridwidth=1;
add(new JLabel("Sec"), c);

c.gridx++;
add(endOffsetFld, c);

c.gridx++;
add(endOffsetSlider, c);

c.gridx++;
add(endOffsetTimeLbl, c);


c.gridy++;
c.gridx=3;
c.anchor = GridBagConstraints.LINE_END;
add(okBtn, c);

pack();


}

public TwitchVideoInfo getTvi() {
return tvi;
}

public void setTvi(TwitchVideoInfo tvi) {
this.tvi = tvi;
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("okBtn")) {
// tvi.setStartOffset(startOffsetSlider.getValue());
// tvi.setEndOffset(endOffsetSlider.getValue());
this.setVisible(false);
}
}
}
27 changes: 22 additions & 5 deletions src/com/trabauer/twitchtools/model/twitch/TwitchVideoInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum State {
@SerializedName("recorded_at")
private String recordedAt;
private String game;
private int length;
private double length; //Twitch changed that to double.
private String preview;
private String url;
private int views;
Expand All @@ -76,6 +76,9 @@ public enum State {
private TwitchVideoInfo.State state;
private HashMap<String, File> relatedFiles;

private int startOffset;
private int endOffset;


protected PropertyChangeSupport pcs;

Expand Down Expand Up @@ -140,7 +143,6 @@ public int hashCode() {
result = 31 * result + id.hashCode();
result = 31 * result + (recordedAt != null ? recordedAt.hashCode() : 0);
result = 31 * result + (game != null ? game.hashCode() : 0);
result = 31 * result + length;
result = 31 * result + (preview != null ? preview.hashCode() : 0);
result = 31 * result + (url != null ? url.hashCode() : 0);
result = 31 * result + views;
Expand Down Expand Up @@ -288,7 +290,7 @@ public String getGame() {
}

public int getLength() {
return length;
return (int)length;
}

public URL getPreviewUrl() throws MalformedURLException {
Expand Down Expand Up @@ -376,7 +378,6 @@ private void updateDLinfoNewVodSystem() throws IOException {
String previousPartFileName = null;
int startOffset = 0;
int endOffset = 0;
// TODO Test the new playlist parsing.
while (playlistSc.hasNextLine()) {
String partLine = playlistSc.nextLine();
// System.out.println(partLine);
Expand Down Expand Up @@ -480,7 +481,7 @@ public void setGame(String game) {
}

public void setLength(int length) {
int oldLength = this.length;
double oldLength = this.length;
this.length = length;
pcs.firePropertyChange("length", oldLength, length);
}
Expand Down Expand Up @@ -607,6 +608,22 @@ public LinkedHashMap<String, String> getStreamInformation() throws IOException {
return streamInformation;
}

public int getStartOffset() {
return startOffset;
}

public void setStartOffset(int startOffset) {
this.startOffset = startOffset;
}

public int getEndOffset() {
return endOffset;
}

public void setEndOffset(int endOffset) {
this.endOffset = endOffset;
}

public TwitchChannel getChannel() {
return channel;
}
Expand Down
34 changes: 34 additions & 0 deletions src/com/trabauer/twitchtools/worker/TwitchDownloadException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.trabauer.twitchtools.worker;

import com.trabauer.twitchtools.model.twitch.TwitchVideoPart;

/**
* Created by flo on 7/19/15.
*/
public class TwitchDownloadException extends Exception {
private TwitchVideoPart videoPart;

public TwitchDownloadException() {
}

public TwitchDownloadException(String message) {
super(message);
}

public TwitchDownloadException(TwitchVideoPart videoPart) {
this.videoPart = videoPart;
}

public TwitchDownloadException(String message, TwitchVideoPart videoPart) {
super(message);
this.videoPart = videoPart;
}

public TwitchVideoPart getVideoPart() {
return videoPart;
}

public void setVideoPart(TwitchVideoPart videoPart) {
this.videoPart = videoPart;
}
}
Loading

0 comments on commit c7ecd12

Please sign in to comment.