Advertisement
DanielFrank

Fetch info from PlayPilot

May 9th, 2024
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     function scrapePlayPilot() {
  3.         var PlayPilotURL = document.getElementById('<%= txtPlayPilotURL.ClientID %>').value;
  4.         console.log('PlayPilot URL entered:', PlayPilotURL);
  5.  
  6.         $.get(PlayPilotURL, function (data) {
  7.             // Create a temporary element to parse the HTML content
  8.             var tempElement = document.createElement('div');
  9.             tempElement.innerHTML = data;
  10.  
  11.             // Find the anchor tag with IMDb URL
  12.             var imdbAnchor = tempElement.querySelector('a.link[href*="imdb.com"]');
  13.             if (imdbAnchor) {
  14.                 var imdbURL = imdbAnchor.href;
  15.                 console.log('Scraped IMDb URL:', imdbURL);
  16.                 var txtIMDbURL = document.getElementById('<%= txtIMDbURL.ClientID %>');
  17.                 if (txtIMDbURL && !txtIMDbURL.value) {
  18.                     // Only set the IMDb URL if the field is empty
  19.                     txtIMDbURL.value = imdbURL;
  20.                 }
  21.             } else {
  22.                 console.log('IMDb URL not found in the PlayPilot page.');
  23.             }
  24.  
  25.             // Find YouTube URLs based on their context
  26.             var youtubeLinks = tempElement.querySelectorAll('a[href*="youtube.com"]');
  27.             youtubeLinks.forEach(function (youtubeLink) {
  28.                 var parentElement = youtubeLink.parentElement;
  29.                 if (parentElement && parentElement.classList.contains('video-block')) {
  30.                     var youtubeURL = youtubeLink.href;
  31.                     console.log('Scraped YouTube URL:', youtubeURL);
  32.                     var txtTrailerURL = document.getElementById('<%= txtTrailerURL.ClientID %>');
  33.                     if (txtTrailerURL && !txtTrailerURL.value) {
  34.                         // Only set the YouTube URL if the field is empty
  35.                         txtTrailerURL.value = youtubeURL;
  36.                     }
  37.                 }
  38.             });
  39.  
  40.             if (!txtTrailerURL.value) {
  41.                 console.log('YouTube URL not found on the PlayPilot page.');
  42.             }
  43.         });
  44.     }
  45. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement