|
|
|
|
@ -60,6 +60,7 @@ public class ExoUtil { |
|
|
|
|
private static DataSource.Factory dataSourceFactory; |
|
|
|
|
private static ExtractorsFactory extractorsFactory; |
|
|
|
|
private static DatabaseProvider database; |
|
|
|
|
private static boolean proxy; |
|
|
|
|
private static Cache cache; |
|
|
|
|
|
|
|
|
|
public static LoadControl buildLoadControl() { |
|
|
|
|
@ -105,22 +106,23 @@ public class ExoUtil { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MediaSource getSource(Result result, int errorCode) { |
|
|
|
|
return getSource(result.getHeaders(), result.getRealUrl(), result.getFormat(), result.getSubs(), null, errorCode); |
|
|
|
|
return getSource(result.getHeaders(), result.isProxy(), result.getRealUrl(), result.getFormat(), result.getSubs(), null, errorCode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MediaSource getSource(Channel channel, int errorCode) { |
|
|
|
|
return getSource(channel.getHeaders(), channel.getUrl(), null, Collections.emptyList(), channel.getDrm(), errorCode); |
|
|
|
|
return getSource(channel.getHeaders(), channel.isProxy(), channel.getUrl(), null, Collections.emptyList(), channel.getDrm(), errorCode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static MediaSource getSource(Map<String, String> headers, String url, int errorCode) { |
|
|
|
|
return getSource(headers, url, null, Collections.emptyList(), null, errorCode); |
|
|
|
|
return getSource(headers, false, url, null, Collections.emptyList(), null, errorCode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static MediaSource getSource(Map<String, String> headers, String url, String format, List<Sub> subs, Drm drm, int errorCode) { |
|
|
|
|
private static MediaSource getSource(Map<String, String> headers, boolean proxy, String url, String format, List<Sub> subs, Drm drm, int errorCode) { |
|
|
|
|
if (ExoUtil.proxy != proxy) reset(); |
|
|
|
|
Uri uri = Uri.parse(url.trim().replace("\\", "")); |
|
|
|
|
String mimeType = getMimeType(format, errorCode); |
|
|
|
|
if (uri.getUserInfo() != null) headers.put(HttpHeaders.AUTHORIZATION, Util.basic(uri)); |
|
|
|
|
return new DefaultMediaSourceFactory(getDataSourceFactory(headers), getExtractorsFactory()).createMediaSource(getMediaItem(uri, mimeType, subs, drm)); |
|
|
|
|
return new DefaultMediaSourceFactory(getDataSourceFactory(headers, ExoUtil.proxy = proxy), getExtractorsFactory()).createMediaSource(getMediaItem(uri, mimeType, subs, drm)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static MediaItem getMediaItem(Uri uri, String mimeType, List<Sub> subs, Drm drm) { |
|
|
|
|
@ -169,13 +171,13 @@ public class ExoUtil { |
|
|
|
|
return extractorsFactory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static synchronized HttpDataSource.Factory getHttpDataSourceFactory() { |
|
|
|
|
if (httpDataSourceFactory == null) httpDataSourceFactory = Setting.getHttp() == 0 ? new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setProxy(Setting.getProxy()) : new OkHttpDataSource.Factory((Call.Factory) OkHttp.client()); |
|
|
|
|
private static synchronized HttpDataSource.Factory getHttpDataSourceFactory(boolean proxy) { |
|
|
|
|
if (httpDataSourceFactory == null) httpDataSourceFactory = Setting.getHttp() == 0 ? new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setProxy(proxy ? OkHttp.proxy() : null) : new OkHttpDataSource.Factory((Call.Factory) (proxy ? OkHttp.clientProxy() : OkHttp.client())); |
|
|
|
|
return httpDataSourceFactory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static synchronized DataSource.Factory getDataSourceFactory(Map<String, String> headers) { |
|
|
|
|
if (dataSourceFactory == null) dataSourceFactory = buildReadOnlyCacheDataSource(new DefaultDataSource.Factory(App.get(), getHttpDataSourceFactory()), getCache()); |
|
|
|
|
private static synchronized DataSource.Factory getDataSourceFactory(Map<String, String> headers, boolean proxy) { |
|
|
|
|
if (dataSourceFactory == null) dataSourceFactory = buildReadOnlyCacheDataSource(new DefaultDataSource.Factory(App.get(), getHttpDataSourceFactory(proxy)), getCache()); |
|
|
|
|
httpDataSourceFactory.setDefaultRequestProperties(Utils.checkUa(headers)); |
|
|
|
|
return dataSourceFactory; |
|
|
|
|
} |
|
|
|
|
|