-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamingSiteOpener.java
166 lines (147 loc) · 5.63 KB
/
StreamingSiteOpener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* This class provides an advanced utility to open major streaming sites and custom URLs
* in the default web browser. It includes a graphical user interface (GUI) with progress
* tracking, error logging, and the ability to import URLs from a file.
*/
public class StreamingSiteOpener extends JFrame {
private static final Desktop desktop;
private static final List<String> streamingSites;
private JTextArea urlTextArea;
private JProgressBar progressBar;
private JButton openButton, importButton;
static {
desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
streamingSites = new ArrayList<>();
streamingSites.add("https://www.netflix.com");
streamingSites.add("https://www.hulu.com");
streamingSites.add("https://www.primevideo.com");
streamingSites.add("https://www.disneyplus.com");
streamingSites.add("https://www.hbomax.com");
streamingSites.add("https://www.paramountplus.com");
streamingSites.add("https://www.peacocktv.com");
streamingSites.add("https://www.appletv.apple.com");
}
public StreamingSiteOpener() {
setTitle("Streaming Site Opener");
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel inputPanel = new JPanel(new BorderLayout());
urlTextArea = new JTextArea(10, 30);
inputPanel.add(new JScrollPane(urlTextArea), BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
openButton = new JButton("Open URLs");
openButton.addActionListener(e -> openURLs());
buttonPanel.add(openButton);
importButton = new JButton("Import URLs from File");
importButton.addActionListener(e -> importURLsFromFile());
buttonPanel.add(importButton);
inputPanel.add(buttonPanel, BorderLayout.SOUTH);
add(inputPanel, BorderLayout.NORTH);
progressBar = new JProgressBar();
add(progressBar, BorderLayout.SOUTH);
setVisible(true);
}
/**
* Opens the URLs specified in the text area in the default web browser.
*/
private void openURLs() {
String[] urlsArray = urlTextArea.getText().split("\\s+");
List<String> urls = new ArrayList<>(urlsArray.length + streamingSites.size());
for (String url : urlsArray) {
urls.add(url);
}
urls.addAll(streamingSites);
int totalUrls = urls.size();
progressBar.setMaximum(totalUrls);
progressBar.setValue(0);
int openedUrls = 0;
for (String url : urls) {
if (openStreamingSite(url)) {
openedUrls++;
}
progressBar.setValue(openedUrls);
}
if (openedUrls == totalUrls) {
JOptionPane.showMessageDialog(this, "All URLs opened successfully.");
} else {
JOptionPane.showMessageDialog(this, "Error opening some URLs. Check the logs for details.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Opens the given streaming site URL in the default web browser.
*
* @param siteUrl The URL of the streaming site to open.
* @return true if the site was opened successfully, false otherwise.
*/
private boolean openStreamingSite(String siteUrl) {
if (desktop == null) {
logError("Desktop is not supported on this platform.");
return false;
}
try {
desktop.browse(new URI(siteUrl));
return true;
} catch (IOException | URISyntaxException e) {
logError("Failed to open: " + siteUrl);
e.printStackTrace();
return false;
}
}
/**
* Imports URLs from a text file and populates the text area.
*/
private void importURLsFromFile() {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt");
fileChooser.setFileFilter(filter);
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
StringBuilder urlsBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
urlsBuilder.append(line).append(" ");
}
urlTextArea.setText(urlsBuilder.toString());
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "Error reading file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
/**
* Logs an error message to the console.
*
* @param message The error message to log.
*/
private static void logError(String message) {
System.err.println(message);
}
/**
* The main entry point of the program.
*
* @param args The command-line arguments.
*/
public static void main(String[] args) {
if (args.length > 0) {
for (String arg : args) {
openStreamingSite(arg);
}
} else {
SwingUtilities.invokeLater(StreamingSiteOpener::new);
}
}
}