Acquire the original Vine video source in .mp4 format on iOS

I've come across some helpful answers in PHP, but I'm wondering if there's a way to achieve the same results with JavaScript or iOS.

Here are the links I found:

  1. How to get Vine video url (not sure how this is implemented)
  2. Get .mp4 source and poster image from Vine Id (PHP) - although it's in PHP, which isn't what I'm looking for.

For example, when you inspect the element of the video, you should see this code (with different ids):

https://i.sstatic.net/r7JKN.png

If you type in the URL ("..... .mp4) and only stop at the .mp4, the video will play in your browser like so:

This is my goal; extracting the URL ("https://...."). I can trim down the URL to just get the .mp4 without the extra content afterwards like a .jpg. However, I'm struggling to retrieve the URL content using the link directly without relying on PHP.

Any assistance would be greatly appreciated.

I have both UIWebView and MPMoviePlayer at my disposal and can either utilize an HTML string in my urlRequest or simply play the .mp4 URL with MPMoviePlayer. I just need guidance on obtaining the .mp4 file.

Answer №1

My attempt to solve this issue using HTML/JS and creating a HTML string, then parsing a vine through iframe was unsuccessful in retrieving the .mp4 link I desired.

To overcome this challenge, I followed these steps:

  1. Refer to the tutorial on parsing HTML by Ray Wenderlich, and follow it until you reach the necessary point. Make sure to install the hpple files in your project (as mentioned in the tutorial) and reference libxml2.

  2. Utilize the following code for parsing to obtain the MP4 link:

    -(void)loadVine: (NSString *) vineLink {
        //create the string to store the result
        NSString * url = nil;
        // Create a URL from the String passed in
        NSURL *vineURL = [NSURL URLWithString:vineLink];
    
        NSData *vineHTMLdata = [NSData dataWithContentsOfURL:vineURL];
    
        TFHpple *vineParser = [TFHpple hppleWithHTMLData:vineHTMLdata];
    
        // This is the most important part of your query
        // The vine .mp4 path is in the `<meta>` tag as shown below
        NSString *vineXpathQueryString = @"//meta[@property='twitter:player:stream']";
        NSArray *vineNodes = [vineParser searchWithXPathQuery:vineXpathQueryString];
    
        for (TFHppleElement *element in vineNodes) {
            //this sets your `NSString * url` to be the result
            url = [element objectForKey:@"content"];
            //print it out in log to display your .mp4 link
            NSLog(@"What is the vine? %@", url);
            //now pass it to your player
            [self autoPlayVine:url];
        }
    }
    
  3. Here is my vine player code:

    -(void) autoPlayVine :(NSString *) link{
    
        NSURL * url = [NSURL URLWithString:link];
    
        self.moviePlayer =  [[MPMoviePlayerController alloc] initWithContentURL:url];
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:self.moviePlayer];
    
        self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
        self.moviePlayer.shouldAutoplay = YES;
        // set the frame to be full screen - needed otherwise you may only get the audio as there is no frame size set, but the movieplayer has been added to the view
        self.moviePlayer.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        // below enables either continuous loop or delete for one time play
        self.moviePlayer.repeatMode = YES;
        [self.view addSubview:self.moviePlayer.view];
        [self.moviePlayer setFullscreen:YES animated:YES];
    }
    
  4. Include this in your viewDidLoad or viewWillAppear based on your preference:

    NSString * yourVineLink = @"https://vine.co/v/.......";
    [self loadVine:yourVineLink];
    

Ensure you have added the correct files and import statements to your project by following the Ray Wenderlich tutorial. If done correctly, everything should function properly (unless Vine alters its meta tags/.mp4 link placement).

NOTE: While you could use URL in method names, I prefer NSString for stylistic reasons.

Enjoy.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you demonstrate how to incorporate a new line within a for loop?

I have an array of letters and I need to display them on the screen using a for loop. My goal is to make every sixth letter appear on a new line. Here is the code snippet: https://i.stack.imgur.com/lHFqq.jpg <script> export default { data() { ...

Improving the form fields and Stimulus JS by eliminating the need to repeat the :data-action attribute for each individual field

I'm working with the following form <%= form_for( model, html: { :'data-controller' => 'enable-submit-button-if-fields-changed' } ) do |form| %> <%= form.text_field(:title, :'data-action&ap ...

Implementing fullCalendar with eventAllow to limit events based on specific DateTime

I am facing a challenge with restricting events to be dropped only before a specific time within each event. When I drop an event before the date, everything works perfectly fine. However, if I try to drop it after the given date, the event disappears. Can ...

Tips on retrieving a result from mongoose's findOne() function

I created a custom function using the findOne() method in Mongoose and now I need to use the result for another function. How can this be achieved? Thank you! module.exports.retrieveDeal = function(dealRequest){ Deal.findOne({name:dealRequest},functi ...

What could be preventing the checkbox from visually updating after programmatically unchecking it with jQuery following a click on 'No' within a modal dialog?

When I click the No button on a modal box, I want to uncheck an input checkbox in jQuery. If I click the Yes button, I want to check it. $('body').off('change', '[name="techOptions"][value="8"]').on('c ...

What are the methods to determine if vue-router is being utilized within the present Vue instance?

I am working on creating a library that includes a vue.js component with navigation elements. The goal is for this component to be flexible, able to function both with and without vue router. When used with the router, it will utilize <router-link> ...

Is there a way to create a Captcha image from text using JavaScript in an HTML document?

As I work on creating a registration web page, ensuring security is key. That's why I'm looking for a way to generate captcha images for added protection. Any suggestions on how I can transform text into captcha images? ...

Discover the visibility of an element through monitoring DOM manipulation with Selenium

Is it possible to monitor a webpage for events such as when an element becomes visible? Can this be achieved using Selenium? For instance, if I set a timeframe to watch a webpage from startTime to endTime, various page events could be recorded, including ...

Compiling with Gulp Browserify may have longer processing times after each save or change

I have been working on improving the speed of my Gulp workflow by using Browserify. The approach I am taking is heavily influenced by this informative blog post: Initially, everything seems to be functioning well with changes reflecting quickly (around 50 ...

Converting Python conditional statements to Javascript control flow

How can I achieve this task using JavaScript? I want it to output 'Found' when it finds the word words in the big_list big_list = ['this', 'is', 'a', 'long', 'list', 'of' 'words&ap ...

What is the process for isolating characters from a variable?

Is there a way to extract the first character up to 1 character after the decimal point? I am receiving data from an API {POWER : 1343.45} {POWER : 15623.34577} {POWER : 123.434} I only require 123.4 from 123.45, 15623.3 from 15623.34577, etc. How can I ...

What is the best way to showcase the outcomes of arithmetic calculations on my calculator?

In the midst of creating a calculator, I have encountered some issues in getting it to display the correct result. Despite successfully storing the numbers clicked into separate variables, I am struggling with showing the accurate calculation outcome. l ...

Retrieving the output from within an AJAX function

I am trying to access the return value of the "res" variable from the function but it returns undefined. How can I solve this issue? function getResult() { var url = "https://translate.yandex.net/api/v1.5/tr.json/translate", keyAPI = "abcdefgh" ...

Developing applications in AngularJS that utilize a remote REST API for data retrieval

Is there a way to make a remote REST API call within an angular js application without enabling CORS on the server? Currently, my setup includes bower for dependency management, grunt for server and build task running, and angular js as the front-end fram ...

What are some tips for leveraging aframe in order to achieve a captivating 360 video effect?

SCENARIO Inspired by the immersive effect showcased here, we aim to utilize a 360 video as the central feature of an extended webpage layout. ISSUE Exploring options, I experimented with Mozilla's aframe, demonstrated here. Yet, integrating an < ...

Tips for incorporating a smooth fade in and out effect into images within a Bootstrap 5 carousel

I'm currently working with a Bootstrap 5 carousel and trying to implement a transition effect where clicking the "next" arrow will smoothly fade out the current image before fading in the next one. This is necessary because the images in my carousel v ...

What is the best way to transfer information from a single card within a collection of cards to a dialog window?

I'm facing a challenge in my CRUD application where I want to incorporate a confirmation step using a Material-UI dialog, but I'm struggling to pass the necessary data to the dialog. Currently, I have a list/grid of cards generated using .map(), ...

Datalist not displaying options in Chrome browser

I sent a server request to retrieve street names, expecting them to appear as options in a datalist. However, in Google Chrome, they did not display correctly. On the other hand, Firefox and IE showed the correct street names. Here is the code snippet: He ...

"Automating the process of toggling the edit mode of a contenteditable element – how is

Is there a specific event I can use to programmatically start or stop editing a contenteditable element, similar to when the user focuses or blurs it? I have tried using .focus(), .click(), and even setting the selection to its content, but none of them se ...

How can I use JavaScript (specifically Reactjs/NextJs) to add a new contact to my phone from a web

I'm currently working on creating a new contact using JS. I've come across documentation for retrieving all contacts from the phone here. Are there any libraries available to assist with this task, or is it only achievable with React Native? ...