Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Commit

Permalink
Episode title, Title from Filename, Thumbnail error checking. Partially
Browse files Browse the repository at this point in the history
implementing #43
  • Loading branch information
becast committed Jan 17, 2017
1 parent 2b2c64f commit fca9d72
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/main/java/at/becast/youploader/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Main {
public static boolean debug = false;
public static final String DB_FILE = System.getProperty("user.home") + "/YouPloader/data/data.db";
public static final String APP_NAME = "YouPloader";
public static final String VERSION = "0.9.1";
public static final String VERSION = "0.9.2";
public static final int DB_VERSION = 10;
private static final ResourceBundle LANG = UTF8ResourceBundle.getBundle("lang", Locale.getDefault());
public static Settings s;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/at/becast/youploader/gui/AddTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package at.becast.youploader.gui;

import java.awt.Toolkit;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

Expand All @@ -28,8 +27,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.becast.youploader.account.Account;
import at.becast.youploader.oauth.OAuth2;
import at.becast.youploader.settings.Settings;
import at.becast.youploader.util.UTF8ResourceBundle;
import java.awt.event.KeyAdapter;
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/at/becast/youploader/gui/EditPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import org.slf4j.Logger;
Expand Down Expand Up @@ -285,7 +286,7 @@ public synchronized void drop(DropTargetDropEvent evt) {
DataFlavor.javaFileListFlavor);
for (File file : droppedFiles) {
if(file.getName().endsWith(".jpg") || file.getName().endsWith(".png") || file.getName().endsWith(".jpeg")){
txtThumbnail.setText(file.getAbsolutePath());
checkThumbnail(file.getAbsolutePath());
}
}
} catch (Exception ex) {
Expand All @@ -304,7 +305,7 @@ public void actionPerformed(ActionEvent e) {
chooser.setFileFilter(new FileNameExtensionFilter("Image Files", "jpg", "jpeg", "png"));
int returnVal = chooser.showOpenDialog(getParent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
txtThumbnail.setText(chooser.getSelectedFile().getAbsolutePath().toString());
checkThumbnail(chooser.getSelectedFile().getAbsolutePath().toString());
}
}
});
Expand Down Expand Up @@ -511,6 +512,19 @@ public void setLicence(String license){
}
}

private void checkThumbnail(String path){
File file = new File(path);
if(!file.exists()){
txtThumbnail.setText(path);
return;
}
if(file.length() > 2048000){
JOptionPane.showMessageDialog(null, LANG.getString("frmMain.errorThumbnail.Message"),LANG.getString("frmMain.errorThumbnail.title"), JOptionPane.ERROR_MESSAGE);
}else{
txtThumbnail.setText(file.getAbsolutePath());
}
}

public void setVisibility(String visibility, String releaseAt){
for (int i = 0; i < cmbVisibility.getItemCount(); i++) {
if (cmbVisibility.getItemAt(i).getData().equals(visibility)) {
Expand Down
70 changes: 46 additions & 24 deletions src/main/java/at/becast/youploader/gui/FrmMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -117,12 +115,10 @@
import at.becast.youploader.youtube.data.GameDataItem;
import at.becast.youploader.youtube.data.Video;
import at.becast.youploader.youtube.data.VideoMetadata;
import at.becast.youploader.youtube.exceptions.UploadException;
import at.becast.youploader.youtube.playlists.Playlist;
import at.becast.youploader.youtube.playlists.PlaylistManager;
import at.becast.youploader.youtube.playlists.PlaylistUpdater;
import at.becast.youploader.youtube.upload.GistUploader;
import at.becast.youploader.youtube.upload.SimpleHTTP;
import at.becast.youploader.youtube.upload.UploadManager;
import ch.qos.logback.classic.LoggerContext;
import net.miginfocom.layout.CC;
Expand Down Expand Up @@ -157,6 +153,7 @@ public class FrmMain extends JFrame implements IMainMenu {
private JTextArea txtDescription;
private JTabbedPane TabbedPane;
private JComboBox<String> cmbFile;
private JCheckBox chckbxTitleFromFilename;
private JMenu mnuAcc;
private JTextField txtTitle;
private JCheckBoxMenuItem chckbxmntmCheckForUpdates;
Expand All @@ -177,6 +174,7 @@ public class FrmMain extends JFrame implements IMainMenu {
protected static int speed = 0;
private DefaultContextMenu contextMenu = new DefaultContextMenu();
private DefaultListModel<AccountType> AccListModel = new DefaultListModel<AccountType>();
private JTextField txtEpisode;
//private static native boolean setAppUserModelID();

/**
Expand All @@ -185,7 +183,7 @@ public class FrmMain extends JFrame implements IMainMenu {
public FrmMain() {
self = this;
this.tos = false;
this.setMinimumSize(new Dimension(900, 580));
this.setMinimumSize(new Dimension(900, 620));
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
Expand Down Expand Up @@ -271,7 +269,7 @@ public void initComponents() {
int top = Integer.parseInt(Main.s.get("top","0"));
int width = Integer.parseInt(Main.s.get("width",DEFAULT_WIDTH));
int height = Integer.parseInt(Main.s.get("height", DEFAULT_HEIGHT));
setBounds(left, top, width, height);
setBounds(left, top, 900, 593);
TabbedPane = new JTabbedPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(Main.APP_NAME + " " + Main.VERSION);
Expand Down Expand Up @@ -342,7 +340,7 @@ public void initMainTab(){
FormSpecs.RELATED_GAP_COLSPEC,
ColumnSpec.decode("20px:grow"),
FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
ColumnSpec.decode("23px"),
ColumnSpec.decode("23px:grow"),
ColumnSpec.decode("33px"),
FormSpecs.UNRELATED_GAP_COLSPEC,
ColumnSpec.decode("61px"),
Expand All @@ -362,6 +360,8 @@ public void initMainTab(){
RowSpec.decode("14px"),
RowSpec.decode("25px"),
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
RowSpec.decode("14px"),
RowSpec.decode("25px"),
FormSpecs.LINE_GAP_ROWSPEC,
Expand All @@ -379,13 +379,23 @@ public void initMainTab(){
FormSpecs.PARAGRAPH_GAP_ROWSPEC,
RowSpec.decode("24px"),
RowSpec.decode("23px"),}));

JLabel lblEpisode = new JLabel("Episode:");
panel.add(lblEpisode, "3, 6, left, default");

txtEpisode = new JTextField();
panel.add(txtEpisode, "4, 6, 2, 1, fill, default");
txtEpisode.setColumns(10);

chckbxTitleFromFilename = new JCheckBox("Title from Filename");
panel.add(chckbxTitleFromFilename, "11, 6, 6, 1");

lbltitlelenght = new JLabel("(0/100)");
panel.add(lbltitlelenght, "14, 6, 3, 1, right, top");
panel.add(lbltitlelenght, "14, 8, 3, 1, right, top");

txtTitle = new JTextField();
//contextMenu.add(txtTitle);
panel.add(txtTitle, "3, 7, 14, 1, fill, fill");
panel.add(txtTitle, "3, 9, 14, 1, fill, fill");
txtTitle.setColumns(10);
txtTitle.addKeyListener(new KeyAdapter() {
@Override
Expand All @@ -395,17 +405,17 @@ public void keyReleased(KeyEvent e) {
});

JLabel lblCategory = new JLabel(LANG.getString("frmMain.Category"));
panel.add(lblCategory, "3, 9, 4, 1, left, bottom");
panel.add(cmbCategory, "3, 10, 14, 1, fill, fill");
panel.add(lblCategory, "3, 11, 4, 1, left, bottom");
panel.add(cmbCategory, "3, 12, 14, 1, fill, fill");

JLabel lblDescription = new JLabel(LANG.getString("frmMain.Description"));
panel.add(lblDescription, "3, 12, 4, 1, left, bottom");
panel.add(lblDescription, "3, 14, 4, 1, left, bottom");

lblDesclenght = new JLabel("(0/5000)");
panel.add(lblDesclenght, "14, 12, 3, 1, right, bottom");
panel.add(lblDesclenght, "14, 14, 3, 1, right, bottom");

JScrollPane DescriptionScrollPane = new JScrollPane();
panel.add(DescriptionScrollPane, "3, 13, 14, 1, fill, fill");
panel.add(DescriptionScrollPane, "3, 15, 14, 1, fill, fill");

txtDescription = new JTextArea();
//contextMenu.add(txtDescription);
Expand All @@ -421,13 +431,13 @@ public void keyReleased(KeyEvent e) {
});

JLabel lblTags = new JLabel(LANG.getString("frmMain.Tags"));
panel.add(lblTags, "3, 15, 4, 1, left, bottom");
panel.add(lblTags, "3, 17, 4, 1, left, bottom");

lblTagslenght = new JLabel("(0/500)");
panel.add(lblTagslenght, "14, 15, 3, 1, right, top");
panel.add(lblTagslenght, "14, 17, 3, 1, right, top");

JScrollPane TagScrollPane = new JScrollPane();
panel.add(TagScrollPane, "3, 16, 14, 1, fill, fill");
panel.add(TagScrollPane, "3, 18, 14, 1, fill, fill");

txtTags = new JTextArea();
//contextMenu.add(txtTags);
Expand All @@ -444,17 +454,17 @@ public void keyReleased(KeyEvent e) {
});

JLabel lblAccount = new JLabel(LANG.getString("frmMain.Account"));
panel.add(lblAccount, "3, 18, 4, 1, left, bottom");
panel.add(lblAccount, "3, 20, 4, 1, left, bottom");
cmbAccount = new JComboBox<AccountType>();
panel.add(getCmbAccount(), "3, 19, 14, 1, fill, fill");
panel.add(getCmbAccount(), "3, 21, 14, 1, fill, fill");
cmbAccount.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeUser();
}
});
btnAddToQueue = new JButton(LANG.getString("frmMain.addtoQueue"));
btnAddToQueue.setEnabled(false);
panel.add(btnAddToQueue, "3, 21, 6, 1, fill, fill");
panel.add(btnAddToQueue, "3, 23, 6, 1, fill, fill");
btnAddToQueue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
queueButton();
Expand Down Expand Up @@ -490,15 +500,15 @@ public synchronized void drop(DropTargetDropEvent evt) {
btnSelectMovie.setIcon(new ImageIcon(getClass().getResource("/film_add.png")));

JLabel lblTitle = new JLabel(LANG.getString("frmMain.Title"));
panel.add(lblTitle, "3, 6, 4, 1, left, bottom");
panel.add(lblTitle, "3, 8, 4, 1, left, bottom");

JButton btnReset = new JButton(LANG.getString("frmMain.Reset"));
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
resetEdit();
}
});
panel.add(btnReset, "11, 21, 6, 1, fill, fill");
panel.add(btnReset, "11, 23, 6, 1, fill, fill");
btnSelectMovie.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EditPanel edit = (EditPanel) ss1.contentPane;
Expand All @@ -512,6 +522,9 @@ public void actionPerformed(ActionEvent e) {
if (returnVal == JFileChooser.APPROVE_OPTION) {
cmbFile.removeAllItems();
cmbFile.addItem(chooser.getSelectedFile().getAbsolutePath().toString());
if(chckbxTitleFromFilename.isSelected()){
txtTitle.setText(chooser.getSelectedFile().getName().replaceAll("\\..*", ""));
}
}
}
});
Expand Down Expand Up @@ -743,10 +756,10 @@ public void actionPerformed(ActionEvent evt) {
mnLanguage.setEnabled(false);
mnLanguage.setVisible(false);

JMenu mnTemplates = new JMenu("frmMain.menu.Templates");
JMenu mnTemplates = new JMenu(LANG.getString("frmMain.menu.Templates"));
mnuBar.add(mnTemplates);

JMenuItem mntmAddTemplate = new JMenuItem("frmMain.menu.addTemplate");
JMenuItem mntmAddTemplate = new JMenuItem(LANG.getString("frmMain.menu.addTemplate"));
mnTemplates.add(mntmAddTemplate);
mnuBar.add(mnLanguage);

Expand Down Expand Up @@ -1145,6 +1158,10 @@ private void queueButton() {
this.editItem = -1;
} else {
if (cmbFile.getSelectedItem() != null && !cmbFile.getSelectedItem().toString().equals("")) {
String title = txtTitle.getText();
if(!txtEpisode.getText().equals("")){
title.replaceAll("%ep%", txtEpisode.getText());
}
createUpload(cmbFile.getSelectedItem().toString(), txtTitle.getText(), acc.getValue());
cmbFile.removeAllItems();
} else {
Expand Down Expand Up @@ -1235,6 +1252,7 @@ public void createTemplate(String name) {
if (txtTags != null && !txtTags.getText().equals("")) {
v.snippet.tags = TagUtil.trimTags(txtTags.getText());
}
t.setTitlefromfile(chckbxTitleFromFilename.isSelected());
VisibilityType visibility = (VisibilityType) edit.getCmbVisibility().getSelectedItem();
if (visibility == VisibilityType.SCHEDULED) {
v.status.publishAt = edit.getDateTimePicker().getEditor().getText();
Expand Down Expand Up @@ -1262,6 +1280,7 @@ public void loadTemplate(Item item) {
txtTitle.setText(t.videodata.snippet.title);
txtDescription.setText(t.videodata.snippet.description);
txtTags.setText(TagUtil.prepareTagsfromArray(t.videodata.snippet.tags));
chckbxTitleFromFilename.setSelected(t.isTitlefromfile());
edit.setLicence(t.videodata.status.license);
if (t.videodata.status.publishAt != null && !t.videodata.status.publishAt.equals("0")
&& t.videodata.status.privacyStatus.equals("private")) {
Expand All @@ -1281,6 +1300,7 @@ public void loadTemplate(Item item) {
}
if(t.getMetadata()!=null){
resetMetadata(t.getMetadata());
txtEpisode.setText(t.metadata.getEp());
}
calcNotifies();
edit.setUpdating(false);
Expand Down Expand Up @@ -1335,6 +1355,7 @@ public void saveTemplate(int id) {
Template t = TemplateMgr.get(id);
t.setMetadata(metadata);
v.snippet.title = txtTitle.getText();
t.setTitlefromfile(chckbxTitleFromFilename.isSelected());
Categories cat = (Categories) cmbCategory.getSelectedItem();
v.snippet.categoryId = cat.getID();
v.snippet.description = txtDescription.getText();
Expand Down Expand Up @@ -1404,6 +1425,7 @@ public VideoMetadata createMetadata() {
PlaylistPanel play = (PlaylistPanel) ss2.contentPane;
MonetPanel monet = (MonetPanel) ss3.contentPane;
meta.setPlaylists(play.getSelectedPlaylists());
meta.setEp(txtEpisode.getText());
meta.setMonetized(monet.getChckbxMonetize().isSelected());
SyndicationType syn = (SyndicationType) monet.getCmbContentSyndication().getSelectedItem();
meta.setSyndication(syn.getData());
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/at/becast/youploader/templates/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Template {

public String name;
public Video videodata;
public boolean titlefromfile = false;
public VideoMetadata metadata;
public String startdir;

Expand Down Expand Up @@ -69,4 +70,12 @@ public void setStartdir(String startdir) {
public String toString(){
return name;
}

public boolean isTitlefromfile() {
return titlefromfile;
}

public void setTitlefromfile(boolean titlefromfile) {
this.titlefromfile = titlefromfile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class VideoMetadata {
private String message;
private String gametitle;
private String gameid;
private String ep = "1";
private ArrayList<String> playlists = new ArrayList<String>();
private boolean restricted;
private boolean monetized = false;
Expand Down Expand Up @@ -230,6 +231,14 @@ public ArrayList<String> getPlaylists() {
return playlists;
}

public String getEp() {
return ep;
}

public void setEp(String ep) {
this.ep = ep;
}

public void setPlaylists(ArrayList<String> playlists) {
this.playlists = playlists;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public void prepare(){

public void setThumbnail(){
try {
this.uploader.uploadThumbnail(new File(this.metadata.getThumbnail()), upload);
File f = new File(this.metadata.getThumbnail().replaceAll("%ep%", this.metadata.getEp()));
if(f.exists() && f.length() <= 2048000){
this.uploader.uploadThumbnail(new File(this.metadata.getThumbnail()), upload);
}else{
LOG.info("Could not set Thumbnail {}. File does either not exist, or is too big.", f.getAbsolutePath());
}
} catch (IOException | UploadException e) {
LOG.error("Could not set Thumbnail ",e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/lang.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ frmMain.titleerror.title=Error
frmMain.titleerror.text=You have to at least set a Title.
frmMain.fileerror.title=You have to select a file
frmMain.fileerror.text=Give me something to work with!
frmMain.errorThumbnail.title=Error
frmMain.errorThumbnail.Message = The selected Thumbnail is to big! Limit 2MB!
UpdateNotice.download=Download
UpdateNotice.changelog=Changelog:
tray.exit=Exit
Expand Down
Loading

0 comments on commit fca9d72

Please sign in to comment.