Asked  7 Months ago    Answers:  5   Viewed   22 times

I have been trying for quite a while to check if submitted links are valid film-clips from youtube.com or vimeo.com but I didn't succeed.

Any ideas how to check url's like:

http://www.youtube.com/watch?v=jc0rnCBCX2c&feature=fvhl (valid)
http://www.youtube.com/watch?v=jc0FFCBCX2c&feature=fvhl (not valid)
http://www.youtube.com/v/jc0rnCBCX2c (valid)
http://www.youtube.com/v/ddjcddddX2c (not valid)
http://www.vimeo.com/463l522 (not valid)
http://www.vimeo.com/1483909 (valid)
http://www.vimeo.com/lumiblue (not valid)
http://www.youtube.com/user/dd181921 (not valid)

?

I use php.

 Answers

72

i see a answer in this site : www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23765374.html

and he said :

I would suggest using youtube's API since you are trying to validate if the video exists. or if you don't want to go into API stuff then you can do simple trick. check this link:

http://code.google.com/apis/youtube/developers_guide_php.html#RetrievingVideoEntry

to check for the existence of a video you will need to extract "v" value and send a request that contains the video id to :

http://gdata.youtube.com/feeds/api/videos/videoID

where videoID is the "v" value for example a video FLE2htv9oxc will be queried like this http://gdata.youtube.com/feeds/api/videos/FLE2htv9oxc if it does not exist then you will get a page with "Invalid id" if it exists, will return an XML feed having various info about the video. this way you can check that the video exists.

hope this will get you in the right direction.

the same thing with vimeo , try to look in api documentation in there site. http://www.vimeo.com/api

Wednesday, March 31, 2021
 
FWH
answered 7 Months ago
FWH
87

You can just use the built in array_filter

If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed.

So can do this in one simple line.

if(!array_filter($array)) {
    echo '<li>Please enter a value into at least one of the fields regarding the request you are searching for.</li>';
}
Wednesday, March 31, 2021
 
Owen
answered 7 Months ago
73

Try this:

$str = 'http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip';
$pos = strrpos($str, '/') + 1;
$result = substr($str, 0, $pos) . urlencode(substr($str, $pos));

You're looking for the last occurrence of the slash sign. The part before it is ok so just copy that. And urlencode the rest.

Wednesday, March 31, 2021
 
TheTechnicalPaladin
answered 7 Months ago
91

According to the PHP manual, you must specifically encode a URL if it contains special characters. This means the function itself should do no special encoding. Most likely your URL is being encoded before being passed to the function, so pass it through urldecode first and see what happens.

Edit: You're saying the encoding is being messed up. Again the PHP manual specifically states that you need to encode urls prior to passing them to file_get_contents. Try encoding the URL, then passing it to the function.

$url = urlencode($url);
file_get_contents($url);
Friday, May 28, 2021
 
rorymorris
answered 5 Months ago
17

You need to use the YouTube iFrame API. Keep in mind, I know just the bare basics of Javascript and so on so this could potentially be a lot more efficient.

You them embed your iframe as you normally would

<iframe id="player" width="640" height="360" src="http://www.youtube.com/embed/TJ2X4dFhAC0?enablejsapi" frameborder="0" allowfullscreen></iframe>

But with a couple changes. It needs to have an ID, 'player', and you need to append ?enablejsapi to the end of the source URI.

You'll then need to run the following script to load the API JS as well as creat the player

// 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  // 3. This function creates an <iframe> (and YouTube player)
  //    after the API code downloads.
  var player;
  function onYouTubePlayerAPIReady() {
    player = new YT.Player('player', {
      height: '390',
      width: '640',
      videoId: 'u1zgFlCw8Aw',
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }

Notice that new YT.Player('player' should match your iframe ID and that videoId: 'u1zgFlCw8Aw' should match the src URI.

After this you'll be able to run scripts like

var myPlayerState;
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          // DO THIS
        }
        myPlayerState = event.data;
      }

if (myPlayerState == 1){
  // PAUSE SLIDER
}
Sunday, June 13, 2021
 
mertak
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :