Getting ID and Playback Function from Video Sites with PHP

Getting ID and Playback Function from Video Sites with PHP

  • 9,348 Kez Okundu
  • PHP & MySQL
  • 1 Yorum
  • 2020-04-30 09:22:24

Let's get the ID information required to play with video links from popular video sites (Youtube, Google Drive, Facebook, Vimeo, Dailymotion, Ok.ru, Twitch) and create an embed code so that you can use videos wherever you want.

Let's take a look at our getVideoID function, which I prepared directly, without further ado.


function getVideoID($link){
	$isVideo    = false;
	$videoID    = "";
	$videoType  = "";
	if (!empty($link)) {
		if (preg_match('%(?:youtube(?:-nocookie)?.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu.be/)([^"&?/ ]{11})%i', $link, $match)) {
			$isVideo   = true;
			$videoID   = $match[1];
			$videoType = 'youtube';

		} else if(preg_match('/(?:https?://)?(?:[w-]+.)*(?:drive|docs).google.com/(?:(?:folderview|open|uc)?(?:[w-%]+=[w-%]*&)*id=|(?:folder|file|document|presentation)/d/|spreadsheet/ccc?(?:[w-%]+=[w-%]*&)*key=)([w-]{28,})/i', $link , $match)){
			$isVideo   = true;
			$videoID   = $match[1];
			$videoType = 'google';

		} else if (preg_match("#https?://vimeo.com/([0-9]+)#i", $link, $match)) {
			$isVideo   = true;
			$videoID   = $match[1];
			$videoType = 'vimeo';

		} else if (preg_match('#https?:.*?.(mp4|mov)#s', $link, $match)) {
			$isVideo   = true;
			$videoType = 'mp4';
			$videoID   = $match[0];

		}else if (preg_match('#https://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $link, $match)) {
			$videoID   = $match[1];
			$videoType = 'daily';
			$isVideo   = true;

		} else if (preg_match('#(https://www.ok.ru/|https://ok.ru/)(video|live)/([A-Za-z0-9]+)#s', $link, $match)) {
			$videoID   = $match[3];
			$videoType = 'ok';
			$isVideo   = true;

		}else if (preg_match('@^(?:https?://)?(?:www.|go.)?twitch.tv(/videos/([A-Za-z0-9]+)|/([A-Za-z0-9]+)/clip/([A-Za-z0-9]+)|/(.*))($|?)@', $link, $match)) {
			$text = explode('/', $match[1]);
			if ($text[1] == 'videos') {
				$videoType      = 'twitch_videos';
				$videoID = $text[2];
				$isVideo  = true;
			}
			else if ($text[2] == 'clip') {
				$videoType      = 'twitch_clip';
				$videoID = $text[3];
				$isVideo  = true;
			}
			else if (!empty($text[1])){
				$videoType      = 'twitch_streams';
				$videoID = $text[1];
				$isVideo  = true;
			}
			
		}else if (preg_match('~([A-Za-z0-9]+)/videos/(?:t.d+/)?(d+)~i', $link, $match) ) {
			$videoID   = $match[0];
			$videoType = 'facebook';
			$isVideo   = true;

		}
	}
	return ["videoID"=>$videoID,"videoType"=>$videoType,"isVideo"=>$isVideo];
}

The function is very simple to use, we send the video link that we have assigned to our $link  variable into the getVideoID function, and it gives us the necessary ID information and which site it belongs to as array output.

For example

$link="https://www.youtube.com/watch?v=O8CCJKzj4BM";

$video=getVideoID($link);

print_r($video);

/*
Ekran çıktısı aşağıdaki gibidir

Array
(
    [videoID] => O8CCJKzj4BM
    [videoType] => youtube
    [isVideo] => 1
)
*/

You can use the videoID given by the function in your own player or embed code or save it for later use.

Now let's prepare a playerVideo function suitable for the output of our getVideoID function.

function playVideo($params=[]){
	$data=[];
	$videoID   = $params["videoID"];
	$videoType = $params["videoType"];
	$isVideo   = $params["isVideo"];
	if(!$isVideo){
		$data["error"]= "Not found video";
	}
	
	if(empty($videoID)){
		$data["error"]= "Not found video id";
	}
	
	if(!isset($data["error"])){
		switch($videoType){
			case "youtube":
			$data["ok"]='';
			break;
			
			case "google":
			$data["ok"]='';
			break;
			
			case "vimeo":
			$data["ok"]='';
			break;
			
			case "mp4":
			$data["ok"]='';
			break;
			
			case "daily":
			$data["ok"]='';
			break;
			
			case "ok":
			$data["ok"]='';
			break;
			
			case "twitch_videos":
			$link = 'https://player.twitch.tv/?video='.$videoID;
			$data["ok"]='';
			break;
			
			default:
			$data["error"]= "Not found video type";
			break;
		}
	}
	return $data;
}
 

 

Let's look at its use together again.

$link="https://www.youtube.com/watch?v=O8CCJKzj4BM";

$video=getVideoID($link);

$player=playVideo($video);

print_r($player);

/*
Ekran çıktısı aşağıdaki gibidir

Örnek başarılı çıktısı:

Array
(
    [ok] =>
)

Örnek hata çıktısı:

Array
(
    [error] => Not found video id
)
*/

 

If you get stuck, do not hesitate to ask. The sites that come to my mind are this for now, you can specify in the comments if you say anything on this site.

CLICK FOR DEMO

You can follow the developments on Github.

Hope it will be useful.

Stay With Love and Knowledge ...

Mücahit Gök
@Mücahit Gök demiş ki ;

Merhaba Mücahit kocam çalıştığım kurumda Youtube engelli https://tube.cadence.moe/watch?v=ci5aKNoPW5E bu sayfayı açıyor ancak videoyu oynatmıyor.

Videoya sağ tıklayıp video linkini kopyalayıp  başına http://cros9.yayin.com.tr/ eklediğimde videoları oynatabiliyorum.

Örnek:

http://cros9.yayin.com.tr/https://r5---sn-nv47lns6.googlevideo.com/videoplayback?expire=1607052482&ei=YljJX7THNIjf4-EP95qpeA&ip=45.77.232.172&id=o-AHfQEEEDY_VaZQGX9jhWCkiYex7L5bqrl8qPUbPtivYF&itag=18&source=youtube&requiressl=yes&vprv=1&mime=video%2Fmp4&ns=YAStfivXatTevB-CgbS-_rcF&gir=yes&clen=18591123&ratebypass=yes&dur=267.470&lmt=1540897789023305&fvip=5&c=WEB&txp=5531432&n=IPrf440w_P3_-a5Cf&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAPan0tJo5plZ64KEQUK3dCJytH8H_fyfd1bu1moYFLn1AiEA1yr4-euDmxVam84s17qFoa269EItWsvuObTqyf8KIgw=&redirect_counter=1&rm=sn-vgqell76&req_id=f4c1125c3cfaa3ee&cms_redirect=yes&ipbypass=yes&mh=16&mip=46.196.196.30&mm=31&mn=sn-nv47lns6&ms=au&mt=1607032598&mv=u&mvi=5&pl=22&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRAIgFYggy5MU6uCJPM1cff7ww4x7t4k9Can_5j6CWiDLGE0CIC02ss_88IiokAM2mZIqywXEC93k0xBCoJmOXUkmJOFQ

Vermiş  olduğum sitede arama yaptığımda bulduğum video linklerinin başına otomatik http://cros9.yayin.com.tr/  ekleyecek şekilde nasıl bir kod kullanabilirim

Yardımcı olabilirsen çok sevinirim. 

YORUM YAPMAK İSTER MİSİN?

    Sponsor Reklamlar
    Son Yorumlar
    Etiket Bulutu
    C#PopupFormOtomatikProgramBaşlatmaBaşlangıçBasitEkran Koruyucuc#ekran görüntüsümail göndermeexedllbirleştirmekIL MergePhpMSSQL BAĞLANTIGerçekIPRealTextBinaryConvertÇalışmaSüreHesaplamakBulmakCssjQueryHtmlScroll TopYukarı ÇıkOnMinimizeControlBoxSimge DurumunaKüçültInternetGetConnectedStateİnternetBağlantıKontrolŞifre MatikPassword GeneratorHash ŞifrelemeMD5SHA1SHA256SHA384SHA512Asimetrik ŞifrelemeRSASimetrik ŞifrelemeKriptoŞifrelemeAlgoritmaDESRC2RijndaelTripleDESKeyLogKlavye DinleTuş YakalamaGlobal HookDialogResultÇıkış MesajıUyarı MesajıFormClosingMySQLConnector/NetKullanımSoruCheckBoxListViewÇoklu SilmebiosdramexploitkontrolgüvenlikinteljavascriptrowhammerscriptPHPAdmin PanelResponsiveXtbadminFreeÜcretsizWifiWirelessKeysŞifreAnahtarPasswordKablosuz AğDepolamaŞifreler NeredeKablosuz ŞifreAndroidTelefonNasılYazılırProgramlama DiliHesap MakinesiSEONedirNasıl YapılırAnalizGoogleLinkÖzgünMobilKonuResim Robots.txtSite MapŞifreli GirişŞifreli FormŞifre KoymaŞifreli AçılışCompilingDebuggingDerlemeKarma ModMixed ModeApp.ConfigKurbanBayramMübarek OlsunBlogScriptYonetimAdminPanelText EditorMSHTMLEditorYazıDüzenleyiciEasyAppKolayUygulamaÇalıştırmaAkıllı TelefonKlavyeiOSKeyboardEl YazısıCalculatorMyScriptHand WritingDosya YöneticisiFile ExplorerFTPBluetoothRootTask ManagerGörev YöneticisiSystemTargetWeb Application PentestErrorShowHideHataGösterGizlePDOSelectInsertUpdateDeleteConnectSeçimEklemeSilmeGüncellemeMsSQLVeritabanıÇeviriçiDatabaseConverterDbConvertMaskeli IPGerçek IPTarayıcı Tespitİşletim Sistemi TespitTekil Ziyaretçi BilgileriAktif Ziyaretçi BilgileriZiyaretçi SayacıVirüsTemizlemeFirewallServiceSecurityServiceTimeServicePentestGüvenliksızma TestiuniscanwindowslinuxperlDosyaKlasörListelemekFileFolderListInternetDownloadUploadSpeedMonitorServisMsconfigStartupRunServiceIOSMatematikDenklemÇözümKameraKablosuzinternetHotspotPaylaşımAyarlarKaliLinuxSharedTerminalÖsymDuyuruTimeTimeZoneDateZamanTarihdate()time()FreelancerSerbestÇalışanJobsİşlerWebSiteVersionSürümGeçişUbuntuSunucuApachephpinfo()phpversion()FonksiyonHerseyiKopyalacopyallcopySızma TestiSQLMapWindowsPython810HotSpotWi-FiWlannetshhostednetworkAutoWlanJsGeri SayımTextAreaOtomatik KayıtSayacSaniyeCountDownXtbadminV2AjaxJavaScriptNumaraFormatPhoneNumberFormatTelefonNumarasıDebuggerDetectUnpackerDisassemblerSecurityReverseEngineeringAlgorithmMacDKHOSCTFCapture The FlagForensicTriviaIntelligenceCRC32CRYPTPASSWORD_HASHWin10StoreMağazaMicrosoftReInstallWSLPowerShellPOSTCyberSiberAdli BilişimHackerUSBCDLiveToolsBruterNmapMSSQL ServerMS SQL ExpressMS AccessOracleIBM DB2SybaseInterbaseInformixExceldBase DbfVisual FoxProMySQLConnectionŞifreleri BulCMDLaZagneEthernetTuxCutNetCutNetKillPerformansCronTabCronJobRestartStopStartBashShellWireSharkFlagUSOMBTKBase64QRÇözümlerWriteUpWrite-UpFinalReconOSINTToolScannerWebsiteSiber GüvenlikPhishingVPNWannacryMobileDeviceFunctionMobil AlgılaMobil TespitisMobilephp mobilJavascriptYazı EfektKayan YazıText EffectsearchBoxinputclassplaceholdersetIntervalsetTimeoutJSpreventBackwindowpushStatehistoryonloadblock browser back buttonVPN Nediranonimtorucuz ürünucuzurunum.commarket kıyaslaürün kıyaslakıyaslakarşılaştıra101şokhappy centermigroscarrefoursabizim marketkıyasürün fiyatıfiyat kıyaslaucuz fiyatfiyat sorVideoEmbedPlayerVideoIDgetVideoIDIframeCreditCardCard DetectKart AlgılaKart TespitKredi Kartı TespitVisaMastercardAIOpenAIChatGPTYapay Zekaquickchatkrispbeatovencleanvoicepodcastleflairillustrokepatternedstockimgcopymonkeyocoyaunbouncevidyotrymaverickquickchatpuzzlelabssounddrawcleanupresumewordedlookatheresanaiforthatsynthesiadescriptotterinkforall