Change domain name on page load in source code with javascript - javascript

I was playing around with urls the other day and i was wondering if there is a way to for example substitute the domain name for a video link on page load
in the source code, while having the original link still interpreted by the browser to play the video correctly.
So for example, if i host an .mp4 on my server with following link:
<source src="https://goofy.com/dogs.mp4" type="video/mp4" label="Low" res="360">
and i would like it to appear in the source code as:
<source src="https://snoopy.com/dogs.mp4" type="video/mp4" label="Low" res="360">
but still having the goofy one played in the player, it it possible ?
(maybe with javascript ?)
What i am trying to achieve here doesn't need to be that advanced, when i meant "scrape" i was just thinking about people opening the inspector manually and simply grabbing the link, in my example:
https://goofy.com/dogs.mp4
So i was rather thinking of some simple javascript letter substitution scheme on pageload that would display some random letters instead of "goofy". Maybe something like this:
var chars = {'a':'b','c':'z','i':'e'};
var enc;
var str = "goofy.com";
window.onload = function() {
enc = str.replace(/[abc]/g, m => chars[m]);
alert(enc);
};
but i think it won't work, as the player will end up playing the url with the wrong domain name. An i'm not that good at javascript, so i'm not sure of what i'm doing either... Feel free to correct me or maybe offer some solution ? thanks.

Per your comment reply, you want to obfuscate the source urls for a video file.
No, modifying the urls in the <source/> DOM elements won't do anything for you. A bot is getting the raw html from your site, so if the original source urls are embedded there you're not going to be able to hide anything.
Moving up the stack a bit, look at how Youtube handles structuring their urls. At its core, they have a js library that handles building out the video urls and video player dynamically at run time. While its highly obfuscated, its not a huge amount of work to discover what the actual video urls are and download them if you want. If someone really wants to get your videos, its not much work to either investigate the page with dev tools in the browser.
And going low-level, its arbitrary to run a packet sniffer like Charles proxy with a man in the middle local SSL proxy service (built in) to look at the requests being sent back and forth and to easily track down the source url that are delivering the video.
You could go back 10 years and try using Flash or some other embedded 3rd party plugin to "encrypt" the video stream but that's stupid and self defeating. If I really want your videos, I'll just play them full screen and record them on my computer.
Hopefully that more thoroughly answers your question.

Related

Not fully downloaded blob: videos

Hi developers i have some problems with blob videos for long time.So I think i finally got hierarchy of blob video that something like reads part of video from server and sends to client.But today i encounter some other problem.Firstly I searched from where comes this blob data to player and some articles gave me useful information for to refer to the links for blob that in inspect section of web page Network section on Chrome.
In this way i saw that the blob video downloads every few seconds with different urls but with little modification.The site was : https://www2.1movies.is/movie/xxxxxxxxxxxxx.html
Blob request refers to urls in a short time with only change of number like that:
s7--p.ex/ample--{seq-1}-xxxx.xxxxxxx
in this exapmle only seq 1 changes frequently and number increasing.
So i used python to download this video by parts in normal mode (without asyncio , or with another sophisticated ways).I did't know how many parts consists video and i checked manually untill it will give 404 error.I did't saved code i used cmd ,therefore i will give code with example.
import urllib as ur
def downloader(x):
"Imagine we will call downloader with given seed url
for example site.com/seq-{}-signature=xxxxxx
in there program will change number with format like that
site.com/seq-1-signature=xxxxxx
site.com/seq-2-signature=xxxxxx and so on.."
for i in range(1,2000):
try:
"video will created with given namber like -> : 1.ts , 2.ts"
ff=open("{}.ts".format(i),'wb')
"and part of video will be read with url and write to file"
ff.write(x.urlopen(x.format(i)).read())
ff.close()
except Exception:
continue
>>>downloader('examp.ple/seq-{}-ddadadaad')
so program worked , but when i attempt to combine all video in one then i saw all parts did't loaded fully , fr example in network section 215th part show 300kb but downloaded file is 298kb.Therefore video playing like interrupted..
So maybe there are have other ways to download this kind of videos but if site works with this way , why didn't I succeed?

Is it possible to cut part of video and upload it on server only with html5 & js

I use Filereader to read local video file (mp4), so I can display it in video tag.
I need to cut part of mp4 file (i.e. from 5 to 10 seconds) and upload it on server.
My current solution: I upload whole video file on server with "from" and "to" parameters, cut it with ffmpeg on server, upload to s3 and return the url video.
Maybe is it possible only with JS/HTML? I found Blob.slice method but i didn't know how to use it to cut video parts.
Thanks!
An mp4 video file is made up of 'atoms' which are like blocks of information or data within a file.
They contain header and metadata about the tracks in the movie (Audio, video, subtitles etc) and also the media data itself.
The concepts are straightforward but an mp4 file is quite involved when you look at one - there is a good example here from the apple developers site (https://developer.apple.com/library/content/documentation/QuickTime/RM/Fundamentals/QTOverview/QTOverview_Document/QuickTimeOverview.html):
If you take a 'slice' of the mp4 file by simply taking bytes from some point in the file to some other point, you can see that you will be missing header information etc depending where you start from, and will also most likely start in the middle of an 'atom'.
Tools like ffmpeg do the hard work to extract and restructure the file when you want to cut part of the video.
There are projects which run ffmpeg in the bowser, but I'm not sure how practical or adopted they are - the one seems pretty popular anyway:
https://github.com/bgrins/videoconverter.js

secondary source if resource is not accessible

here's the deal: I have a small onboard server on a project I'm working on, which is running kind of slow, so I thought moving images for the small website included, to external sources, like an external web server;
the problem is, I'm not sure I'll always be connected to the internet when I'll access it, maybe I'll only be in LAN.
So my question is: how can I specify a primary (external) and a secondary/backup (local) source for the images on the web page? so if the user is connected to the internet, this would take some load off the little server?
Thanks in advance, guys!
EDIT: I found the answer here:
jQuery/JavaScript to replace broken images
-it's the onerror, with an inline javascript function that reassigns the image directly!
(awesome stuff)
cheers, awesome guys from the internet that help people in need! ^^
You have the onerror that can be called when loading fails:
<img onerror="runSomeScriptThatReplacesThisImage()" ...
or:
<img onerror="this.src='yourOtherImage.jpg" ...
Just be carefull because if the onerror also fails you'll get a loop. So be sure to avoid that.
You're going to have two URL's for your images directory, e.g.
//www.remote.com/images/
~/images/
when a session starts, you could do a request to the remote server and if the request times out or you don't get a 200 response back, you can use the local URL base. I would suggest storing it in a session variable for easy access.
This can be done without using any JavaScript.
The object element can be used to display images. If the referenced image (in the data attribute) can’t be loaded, the object’s fallback content will be used. Now, if you include another object, this one will be tried. The last one should include an alternative fallback content, e.g. text describing the image (similar to the alt attribute on img).
<object type="image/png" data="http://foo.example.com/external-image.png">
<object type="image/png" data="/local-image.png">
<!-- alternative text for the image (if even the local one cannot be loaded; for accessibility; etc.) -->
</object>
</object>
I think that your best option is to retrieve the images using AJAX.
Then you can fallback to retrieving them from the slow server it the fast server fails.

Generate embed code given any url

My goal is to take user-submitted urls and generate video embed code. Any ideas on this could be done?
I've seen multiple sites do this including myvidster. Autoembed is a paid option written in php, however I"m using ruby/rails.
Have a look at oEmbed and its associated Ruby gem. It supports Youtube, Vimeo, Hulu, blip.tv out of the box.
If you are writing this yourself you will need to parse the URL for each site you are trying to accept video content from. For instance a Youtube link could be used something like this:
if url.match(/.*\.youtube\.com\/watch\?v=(.{11})/) || url.match(/youtu\.be\/(.{11})/)
%{<iframe width="440" height="275" src="https://www.youtube.com/embed/#{$1}?rel=0&wmode=transparent"></iframe>}.html_safe
else #other video site conditions here
end
Where url is the string passed in by the user and $1 is the the ID you parsed out and the iframe string code is specific to the site you are using.

URL masking in JavaScript

I currently have the following JavaScript function that will take current URL and concatenate it to another site URL to route it to the appropriate feedback group:
function sendFeedback() {
url = window.location.href;
newwin = window.open('http://www.anothersite.com/home/feedback/?s=' + url, 'Feedback');
}
Not sure if this is the proper terminology, but I want to mask the URL in the window.open statement to use the URL from the current window.
How would I be able to mask the window.open URL with the original in JavaScript?
Things you could do:
1- Mask the external site in a html frame inside a document from your site.
(for example www.mysite.com/shortUrl/)
2-Send a Location HTTP header (real url will eventually be displayed)
Keep in mind that browsers do their best to show the real address due to phishing concerns.
I wouldn't use javascript if I wanted to mask url even thought it would work with javascript. You wouldn't get much benefits in that scenario.
The reason is simple:
javascript/jQuery = functions belongs to client-side (browswer/your PC/DOM)
links, url, http, and headers = functions belongs to Apache.
Apache is always top level above client-side. Whenever link is fired to SampeLink.html, Apache wakes up and reads the file, but links/urls are already owned before javascript could claim them. So, it is kinda of pointless if you tried to manipulate links in your javascript scripts, even though it works but weak.
I'd point you to this awesome approach: .htaccess and you will be surprised how powerful it is. If .htaccess is presented in the parent folder of SampleLink.html, Apache denies the DOM engine (your browser) from reading files until Apache have finished reading .htaccess.
With your scenario, .htaccess can do some work for you by rewriting links and send "decoy" links to the DOM engine, meanwhile keeping the orginial links/urls behind the curtain; and visitors would reach to 404page if they tried to break the app or whatever you are concerned about.
This is a bit complicated, but it never ceased to fail me. I use this as my "bible" http://corz.org/serv/tricks/htaccess2.php.

Categories

Resources