use of com.biglybt.core.devices.DeviceMediaRenderer in project BiglyBT by BiglySoftware.
the class TrancodeUIUtils method getTranscodeTargets.
public static TranscodeTarget[] getTranscodeTargets() {
List<TranscodeTarget> result = new ArrayList<>();
if (!COConfigurationManager.getStringParameter("ui").equals("az2")) {
try {
DeviceManager dm = DeviceManagerFactory.getSingleton();
Device[] devices = dm.getDevices();
for (final Device d : devices) {
if (d instanceof DeviceMediaRenderer) {
final DeviceMediaRenderer dmr = (DeviceMediaRenderer) d;
boolean hide_device = d.isHidden();
if (COConfigurationManager.getBooleanParameter("device.sidebar.ui.rend.hidegeneric", true)) {
if (dmr.isNonSimple()) {
hide_device = true;
}
}
if (hide_device) {
continue;
}
result.add(new TranscodeTarget() {
@Override
public String getName() {
return (d.getName());
}
@Override
public String getID() {
return (d.getID());
}
@Override
public TranscodeProfile[] getProfiles() {
List<TranscodeProfile> ps = new ArrayList<>();
com.biglybt.core.devices.TranscodeProfile[] profs = dmr.getTranscodeProfiles();
if (profs.length == 0) {
if (dmr.getTranscodeRequirement() == com.biglybt.core.devices.TranscodeTarget.TRANSCODE_NEVER) {
ps.add(new TranscodeProfile() {
@Override
public String getUID() {
return (dmr.getID() + "/" + dmr.getBlankProfile().getName());
}
@Override
public String getName() {
return (MessageText.getString("devices.profile.direct"));
}
});
}
} else {
for (final com.biglybt.core.devices.TranscodeProfile prof : profs) {
ps.add(new TranscodeProfile() {
@Override
public String getUID() {
return (prof.getUID());
}
@Override
public String getName() {
return (prof.getName());
}
});
}
}
return (ps.toArray(new TranscodeProfile[ps.size()]));
}
});
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
Collections.sort(result, new Comparator<TranscodeTarget>() {
@Override
public int compare(TranscodeTarget o1, TranscodeTarget o2) {
return (o1.getName().compareTo(o2.getName()));
}
});
return (result.toArray(new TranscodeTarget[result.size()]));
}
use of com.biglybt.core.devices.DeviceMediaRenderer in project BiglyBT by BiglySoftware.
the class DeviceDriveManager method addDevice.
protected DeviceMediaRendererManual addDevice(String target_name, String target_classification, File root, File target_directory, boolean generic) {
DeviceMediaRenderer existingDevice = getDeviceMediaRendererByClassification(target_classification);
if (existingDevice instanceof DeviceMediaRendererManual) {
mapDevice((DeviceMediaRendererManual) existingDevice, root, target_directory);
existingDevice.setGenericUSB(generic);
return (DeviceMediaRendererManual) existingDevice;
}
DeviceTemplate[] templates = manager.getDeviceTemplates(Device.DT_MEDIA_RENDERER);
DeviceMediaRendererManual renderer = null;
for (DeviceTemplate template : templates) {
if (template.getClassification().equalsIgnoreCase(target_classification)) {
try {
renderer = (DeviceMediaRendererManual) template.createInstance(target_name);
break;
} catch (Throwable e) {
log("Failed to add device", e);
}
}
}
if (renderer == null) {
try {
renderer = (DeviceMediaRendererManual) manager.createDevice(Device.DT_MEDIA_RENDERER, null, target_classification, target_name, true);
} catch (Throwable e) {
log("Failed to add device", e);
}
}
if (renderer != null) {
try {
renderer.setAutoCopyToFolder(true);
// This will cause a change event
renderer.setGenericUSB(generic);
mapDevice(renderer, root, target_directory);
return renderer;
} catch (Throwable e) {
log("Failed to add device", e);
}
}
return renderer;
}
use of com.biglybt.core.devices.DeviceMediaRenderer in project BiglyBT by BiglySoftware.
the class DeviceManagerUPnPImpl method addListener.
protected void addListener(PluginInterface pi) {
try {
IPCInterface my_ipc = new IPCInterfaceImpl(new Object() {
public Map<String, Object> browseReceived(TrackerWebPageRequest request, Map<String, Object> browser_args) {
Map headers = request.getHeaders();
String user_agent = (String) headers.get("user-agent");
String client_info = (String) headers.get("x-av-client-info");
InetSocketAddress client_address = request.getClientAddress2();
DeviceMediaRenderer explicit_renderer = null;
boolean handled = false;
if (user_agent != null) {
String lc_agent = user_agent.toLowerCase();
if (lc_agent.contains("playstation 3")) {
handlePS3(client_address);
handled = true;
} else if (lc_agent.contains("xbox")) {
handleXBox(client_address);
handled = true;
} else if (lc_agent.contains("nintendo wii")) {
handleWii(client_address);
handled = true;
}
}
if (client_info != null) {
String lc_info = client_info.toLowerCase();
if (lc_info.contains("playstation 3")) {
handlePS3(client_address);
handled = true;
} else if (lc_info.contains("azureus") || lc_info.contains("vuze") || lc_info.contains("biglybt")) {
explicit_renderer = handleVuzeMSBrowser(client_address, client_info);
handled = true;
}
}
if (!handled) {
handled = manager.browseReceived(request, browser_args);
}
if (!handled) {
String source = (String) browser_args.get("source");
if (source != null && source.equalsIgnoreCase("http")) {
handleBrowser(client_address);
handled = true;
}
}
/**
* System.out.println(
* "Received browse: " + request.getClientAddress() +
* ", agent=" + user_agent +
* ", info=" + client_info +
* ", handled=" + handled + ", " + request.getURL());
* System.out.println("\n\n");
* /*
*/
DeviceImpl[] devices = manager.getDevices();
final List<DeviceMediaRendererImpl> browse_devices = new ArrayList<>();
boolean restrict_access = false;
for (DeviceImpl device : devices) {
if (device instanceof DeviceMediaRendererImpl) {
DeviceMediaRendererImpl renderer = (DeviceMediaRendererImpl) device;
if (explicit_renderer != null) {
if (renderer != explicit_renderer) {
continue;
}
}
InetAddress device_address = renderer.getAddress();
try {
if (device_address != null) {
if (device_address.equals(client_address.getAddress())) {
if (renderer.canFilterFilesView()) {
boolean skip = false;
if (renderer.canRestrictAccess()) {
String restriction = renderer.getAccessRestriction().trim();
if (restriction.length() > 0) {
String x = client_address.getAddress().getHostAddress();
skip = true;
String[] ips = restriction.split(",");
for (String ip : ips) {
if (ip.startsWith("-")) {
ip = ip.substring(1);
if (ip.equals(x)) {
break;
}
} else {
if (ip.startsWith("+")) {
ip = ip.substring(1);
}
if (ip.equals(x)) {
skip = false;
break;
}
}
}
}
}
if (skip) {
restrict_access = true;
String host = client_address.getAddress().getHostAddress();
synchronized (access_logs) {
if (!access_logs.contains(host)) {
access_logs.add(host);
manager.log("Ignoring browse from " + host + " due to access restriction for '" + renderer.getName() + "'");
}
}
}
browse_devices.add(renderer);
renderer.browseReceived();
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
Map<String, Object> result = new HashMap<>();
if (browse_devices.size() > 0) {
synchronized (unassociated_devices) {
unassociated_devices.remove(client_address.getAddress());
}
final boolean f_restrict_access = restrict_access;
result.put("filter", new ContentFilter() {
@Override
public boolean isVisible(ContentDownload download, Map<String, Object> browse_args) {
if (f_restrict_access) {
return (false);
}
boolean visible = false;
for (DeviceUPnPImpl device : browse_devices) {
if (device.isVisible(download)) {
visible = true;
}
}
return (visible);
}
@Override
public boolean isVisible(ContentFile file, Map<String, Object> browse_args) {
if (f_restrict_access) {
return (false);
}
boolean visible = false;
for (DeviceUPnPImpl device : browse_devices) {
if (device.isVisible(file)) {
visible = true;
}
}
return (visible);
}
});
} else {
if (request.getHeader().substring(0, 4).equalsIgnoreCase("POST")) {
synchronized (unassociated_devices) {
unassociated_devices.put(client_address.getAddress(), user_agent);
}
}
}
return (result);
}
});
if (upnpav_ipc.canInvoke("addBrowseListener", new Object[] { my_ipc })) {
DeviceImpl[] devices = manager.getDevices();
for (DeviceImpl device : devices) {
if (device instanceof DeviceUPnPImpl) {
DeviceUPnPImpl u_d = (DeviceUPnPImpl) device;
u_d.resetUPNPAV();
}
}
upnpav_ipc.invoke("addBrowseListener", new Object[] { my_ipc });
} else {
manager.log("UPnPAV plugin needs upgrading");
}
} catch (Throwable e) {
manager.log("Failed to hook into UPnPAV", e);
}
}
use of com.biglybt.core.devices.DeviceMediaRenderer in project BiglyBT by BiglySoftware.
the class DeviceManagerUPnPImpl method handleVuzeMSBrowser.
protected DeviceMediaRenderer handleVuzeMSBrowser(InetSocketAddress address, String info) {
String[] bits = info.split(";");
String client = "";
for (String bit : bits) {
String[] temp = bit.split("=");
if (temp.length == 2 && temp[0].trim().equalsIgnoreCase("mn")) {
client = temp[1].trim();
if (client.startsWith("\"")) {
client = client.substring(1);
}
if (client.endsWith("\"")) {
client = client.substring(0, client.length() - 1);
}
}
}
if (client.length() == 0) {
client = "Vuze on " + address.getAddress().getHostAddress();
}
DeviceMediaRenderer result = handleGeneric(address, "vuze-ms-browser." + client, client);
result.setTranscodeRequirement(TranscodeTarget.TRANSCODE_NEVER);
return (result);
}
use of com.biglybt.core.devices.DeviceMediaRenderer in project BiglyBT by BiglySoftware.
the class DeviceDriveManager method getDeviceMediaRendererByClassification.
protected DeviceMediaRenderer getDeviceMediaRendererByClassification(String target_classification) {
DeviceImpl[] devices = manager.getDevices();
for (DeviceImpl device : devices) {
if (device instanceof DeviceMediaRenderer) {
DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
String classification = renderer.getClassification();
if (classification.equalsIgnoreCase(target_classification)) {
return renderer;
}
}
}
return null;
}
Aggregations