Skip to content

Commit

Permalink
Add origin and referrer to pc platform url
Browse files Browse the repository at this point in the history
  • Loading branch information
typcn committed Feb 22, 2018
1 parent 207a826 commit e8e66c0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 43 deletions.
4 changes: 4 additions & 0 deletions bilibili/Browser/ToolBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "WebTabView.h"
#import "PlayerManager.h"

extern NSString *sharedURLFieldString;

@interface BLToolBar ()


Expand Down Expand Up @@ -69,6 +71,7 @@ - (void)updateToolbarURL:(NSNotification*) aNotification{
NSString *url = aNotification.object;
if(url && [url length] > 5){
[self.URLInputField setStringValue:[self replaceURL:url]];
sharedURLFieldString = url;
}
}else{
[NSTimer scheduledTimerWithTimeInterval:0.1
Expand All @@ -85,6 +88,7 @@ - (void)delayUpdateURL{
NSString *url = [[tc GetTWebView] getURL];
if(url && [url length] > 5) {
[self.URLInputField setStringValue:[self replaceURL:url]];
sharedURLFieldString = url;
}else{
[self.URLInputField setStringValue:@"Invalid URL"];
NSLog(@"[BUG] Browser seems freeze, isLastTab: %d",isLastTab);
Expand Down
10 changes: 8 additions & 2 deletions bilibili/Others/SimpleVideoFormatParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

#import "SimpleVideoFormatParser.h"

extern NSString *sharedURLFieldString;

NSData *SendRangeHTTPRequest(NSString *URL,int length){

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]];
request.HTTPMethod = @"GET";
request.timeoutInterval = 5;
[request setValue:@"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36" forHTTPHeaderField:@"User-Agent"];
if([URL containsString:@"platform=pc"] && [URL containsString:@"acgvideo.com"]){
[request setValue:sharedURLFieldString forHTTPHeaderField:@"Referer"];
[request setValue:@"https://www.bilibili.com" forHTTPHeaderField:@"Origin"];
}
[request setValue:[NSString stringWithFormat:@"bytes=0-%d",length] forHTTPHeaderField:@"Range"];

NSURLResponse * response = nil;
Expand Down Expand Up @@ -128,11 +134,11 @@ inline double get_double_from_BE_binary(uint64_t *be_bin){
NSData *d = SendRangeHTTPRequest(URL,1000);
return findMP4Resolution(d);
}else if([URL containsString:@".flv"]){
NSData *d = SendRangeHTTPRequest(URL,1000);
NSData *d = SendRangeHTTPRequest(URL,5000);
return findFLVResolution(d);
}else{
NSLog(@"[SimpleParser] Format not supported");
// Not supported
return NULL;
}
}
}
10 changes: 10 additions & 0 deletions bilibili/Player/PlayerView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#import "../CommentConvert/danmaku2ass.hpp"

extern NSString *sharedURLFieldString;

@interface PlayerView (){
__weak PlayerWindow *window;
__weak PlayerControlView *playerControlView;
Expand Down Expand Up @@ -237,6 +239,13 @@ - (void)playVideo:(NSString *)URL{
[self setMPVOption:"screenshot-directory" :"~/Desktop"];
[self setMPVOption:"screenshot-format" :"png"];

if([URL containsString:@"platform=pc"] && [URL containsString:@"acgvideo.com"]){
NSString *httpheader = [NSString stringWithFormat:
@"Origin: %@,Referer: %@",
@"https://www.bilibili.com",
sharedURLFieldString];
[self setMPVOption:"http-header-fields" :[httpheader cStringUsingEncoding:NSUTF8StringEncoding]];
}

[self setMPVOption:"input-media-keys" :"no"];

Expand Down Expand Up @@ -396,6 +405,7 @@ - (NSDictionary *) getVideoInfo:(NSString *)url{

MediaInfoDLL::MediaInfo *MI = new MediaInfoDLL::MediaInfo;
MI->Open([url cStringUsingEncoding:NSUTF8StringEncoding]);

MI->Option(__T("Inform"), __T("Video;%Width%"));
NSString *width = [NSString stringWithCString:MI->Inform().c_str() encoding:NSUTF8StringEncoding];
MI->Option(__T("Inform"), __T("Video;%Height%"));
Expand Down
4 changes: 0 additions & 4 deletions bilibili/VideoProvider/VP_Bilibili.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,15 @@ - (VideoAddress *) getVideoAddress: (NSDictionary *)params{

// Build-in parser's result(ws.acgvideo.com/path.flv?*&or=xxx the "or" param) have speed limit , so use dynamic parser by default

#ifndef DEBUG
VP_Plugin *plugin = [[PluginManager sharedInstance] Get:@"bilibili-resolveAddr"];
if(plugin){
NSLog(@"[VP_Bilibili] Using dynamic parser");
videoResult = [self dynamicPluginParser:params];
}else{
#endif
NSLog(@"[VP_Bilibili] Dynamic parser not installed ( or running in debug mode )");
NSLog(@"[VP_Bilibili] Using built-in parser");
videoResult = [self sendAPIRequest:URL :fakeIP];
#ifndef DEBUG
}
#endif


parseJSON: NSLog(@"[VP_Bilibili] Parsing result");
Expand Down
48 changes: 11 additions & 37 deletions bilibili/WebPages/inject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.bilimacVersion = 253;
window.bilimacVersion = 254;
window.injectHTML = 'INJ_HTML';
window.sendToView = function(data){
var rpcdata = 'action=' + encodeURIComponent(data.action) + '&data=' + encodeURIComponent(data.data);
Expand Down Expand Up @@ -57,20 +57,6 @@ function applyUI(){
console.log(e);
}

var haveCorrectFlashVar = (fv.indexOf('cid') > -1) && (fv.indexOf('aid') > -1);
if(isBangumiPage && !haveCorrectFlashVar && window.LoadTimes > 7){
window.LoadTimes = 999;
clearInterval(window.i);
// There is no browser UA short than 100 , right ?
if(navigator.userAgent.length < 90){
// Running in built in webview
window.sendToView({'action':'goURL','data':$('.v-av-link').attr('href')});
}else{
// Running in other browser
window.location = $('.v-av-link').attr('href');
}
}

console.log("fv:" + fv);
var re = /cid=(\d+)&/;
var m = re.exec(fv);
Expand All @@ -92,29 +78,17 @@ function applyUI(){
$('embed').parent().html(window.injectHTML);
}else{
window.sendToView({action:'preloadComment',data:TYPCN_PLAYER_CID});
if(isBangumiPage){
if(!window.capt_pid){
window.capt_pid = 0;
}
window.TYPCN_PLAYER_CID = window.TYPCN_PLAYER_CID + '|' + window.location.href + '&' + aid + '&' + window.capt_pid + '|' + document.title;
window.TYPCN_PLAYER_CID = window.TYPCN_PLAYER_CID + '|' + window.location.href + '|' + document.title;
if(window.location.href.indexOf('bilibili.com/video/av') > -1){
window.addEventListener("hashchange", function(){
setTimeout(function(){
window.location.reload();
},100);
}, false);
}else{
window.TYPCN_PLAYER_CID = window.TYPCN_PLAYER_CID + '|' + window.location.href + '|' + document.title;
if(window.location.href.indexOf('bilibili.com/video/av') > -1){
window.addEventListener("hashchange", function(){
setTimeout(function(){
var page = window.location.hash.replace('#page=','');
if(!page || !window.aid){
return;
}
window.location = location.origin + location.pathname.replace(/index.*/,'') + 'index_' + page + '.html';
},100);
}, false);
}
setTimeout(function(){
var page = window.location.hash.replace('#page=','');
if(!page || !window.aid){
return;
}
window.location = location.origin + location.pathname.replace(/index.*/,'') + 'index_' + page + '.html';
},100);
}, false);
}

console.log("inject player page");
Expand Down

0 comments on commit e8e66c0

Please sign in to comment.