use of com.biglybt.core.content.ContentFile 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.content.ContentFile in project BiglyBT by BiglySoftware.
the class DeviceUPnPImpl method setupStreamXCode.
protected boolean setupStreamXCode(TranscodeFileImpl transcode_file) {
final TranscodeJobImpl job = transcode_file.getJob();
if (job == null) {
return (transcode_file.isComplete());
}
final String tf_key = transcode_file.getKey();
ContentFile acf;
synchronized (acf_map) {
acf = acf_map.get(tf_key);
}
if (acf != null) {
return (true);
}
IPCInterface ipc = upnpav_ipc;
if (ipc == null) {
return (false);
}
if (transcode_file.getDurationMillis() == 0) {
return (false);
}
try {
final DiskManagerFileInfo stream_file = new TranscodeJobOutputLeecher(job, transcode_file);
acf = new ContentFile() {
@Override
public DiskManagerFileInfo getFile() {
return (stream_file);
}
@Override
public Object getProperty(String name) {
if (name.equals(MY_ACF_KEY)) {
return (new Object[] { DeviceUPnPImpl.this, tf_key });
} else if (name.equals(PT_PERCENT_DONE)) {
return (new Long(1000));
} else if (name.equals(PT_ETA)) {
return (new Long(0));
}
return (null);
}
};
synchronized (acf_map) {
acf_map.put(tf_key, acf);
}
ipc.invoke("addContent", new Object[] { acf });
log("Set up stream-xcode for " + transcode_file.getName());
return (true);
} catch (Throwable e) {
return (false);
}
}
use of com.biglybt.core.content.ContentFile in project BiglyBT by BiglySoftware.
the class DeviceUPnPImpl method fileAdded.
public void fileAdded(TranscodeFile _transcode_file, boolean _new_file) {
TranscodeFileImpl transcode_file = (TranscodeFileImpl) _transcode_file;
IPCInterface ipc = upnpav_ipc;
synchronized (this) {
if (ipc == null) {
return;
}
if (!transcode_file.isComplete()) {
syncCategoriesAndTags(transcode_file, _new_file);
return;
}
ContentFile acf = (ContentFile) transcode_file.getTransientProperty(UPNPAV_FILE_KEY);
if (acf != null) {
return;
}
final String tf_key = transcode_file.getKey();
synchronized (acf_map) {
acf = acf_map.get(tf_key);
}
if (acf != null) {
return;
}
try {
final DiskManagerFileInfo f = transcode_file.getTargetFile();
acf = new ContentFile() {
@Override
public DiskManagerFileInfo getFile() {
return (f);
}
@Override
public Object getProperty(String name) {
if (name.equals(MY_ACF_KEY)) {
return (new Object[] { DeviceUPnPImpl.this, tf_key });
} else if (name.equals(PT_CATEGORIES)) {
TranscodeFileImpl tf = getTranscodeFile(tf_key);
if (tf != null) {
return (tf.getCategories());
}
return (new String[0]);
} else if (name.equals(PT_TAGS)) {
TranscodeFileImpl tf = getTranscodeFile(tf_key);
if (tf != null) {
return (tf.getTags(true));
}
return (new String[0]);
} else if (name.equals(PT_TITLE)) {
TranscodeFileImpl tf = getTranscodeFile(tf_key);
if (tf != null) {
return (tf.getName());
}
} else {
TranscodeFileImpl tf = getTranscodeFile(tf_key);
if (tf != null) {
long res = 0;
if (name.equals(PT_DURATION)) {
res = tf.getDurationMillis();
} else if (name.equals(PT_VIDEO_WIDTH)) {
res = tf.getVideoWidth();
} else if (name.equals(PT_VIDEO_HEIGHT)) {
res = tf.getVideoHeight();
} else if (name.equals(PT_DATE)) {
res = tf.getCreationDateMillis();
} else if (name.equals(PT_PERCENT_DONE)) {
if (tf.isComplete()) {
res = 1000;
} else {
TranscodeJob job = tf.getJob();
if (job == null) {
res = 0;
} else {
res = 10 * job.getPercentComplete();
}
}
return (res);
} else if (name.equals(PT_ETA)) {
if (tf.isComplete()) {
res = 0;
} else {
TranscodeJob job = tf.getJob();
if (job == null) {
res = Long.MAX_VALUE;
} else {
res = job.getETASecs();
}
}
return (res);
}
if (res > 0) {
return (new Long(res));
}
}
}
return (null);
}
};
transcode_file.setTransientProperty(UPNPAV_FILE_KEY, acf);
synchronized (acf_map) {
acf_map.put(tf_key, acf);
}
syncCategoriesAndTags(transcode_file, _new_file);
try {
ipc.invoke("addContent", new Object[] { acf });
} catch (Throwable e) {
Debug.out(e);
}
} catch (TranscodeException e) {
// file deleted
}
}
}
use of com.biglybt.core.content.ContentFile in project BiglyBT by BiglySoftware.
the class DeviceUPnPImpl method fileRemoved.
@Override
public void fileRemoved(TranscodeFile file) {
IPCInterface ipc = upnp_manager.getUPnPAVIPC();
if (ipc == null) {
return;
}
synchronized (this) {
ContentFile acf = (ContentFile) file.getTransientProperty(UPNPAV_FILE_KEY);
if (acf == null) {
return;
}
file.setTransientProperty(UPNPAV_FILE_KEY, null);
try {
ipc.invoke("removeContent", new Object[] { acf });
} catch (Throwable e) {
Debug.out(e);
}
}
synchronized (acf_map) {
acf_map.remove(((TranscodeFileImpl) file).getKey());
}
}
Aggregations