Ios解析乐视视频地址

        既上一篇解析爱奇艺的视频地址,解析乐视的视频也是需要视频的网页地址。然后一步一步的剥离出真正的视频地址。

大概流程:

-- 读取信息的API

-- 拼接完整的API

-- 获取伪装视频的url

-- 获取真正的视频地址

一:拼接读取伪装地址的API

   NSString * API_URL = @"http://player-pc.le.com/mms/out/video/playJson?        id=%@&platid=1&splatid=101&format=1&source=1000&tkey=%d&domain=www.le.com®ion=cn&accesyx=1";

         NSString * idkey = [[[[url componentsSeparatedByString:@"/"] lastObject] componentsSeparatedByString:@"."] firstObject];

        int loc = 185025305;

        NSInteger timeSch = (NSInteger)[NSDate date].timeIntervalSince1970;

        long tkey = [self rorpa:timeSchpb:loc%17] ^ loc;

        NSString* urlStr = [NSString stringWithFormat:API_URL,idkey,tkey];

-(long)rorpa:(NSInteger)pa pb:(NSInteger)pb{

    long  pc =0;

    while(pc

        pa = [self urshift:pan:1] + ((pa &1)<<31);

        pc+=1;

    }

    returnpa;

}

-(long)urshift:(long)val n:(long)n{

    return val >=0? val >> n : (val +0x100000000L) >> n;

二)获取伪装的视频地址

#define parames @"&m3v=1&format=1&expect=3&tss=ios";

-(void)getReultdata:(NSString*)urlStr{

    [self.videoArr removeAllObjects];

    AFHTTPSessionManager * afMn = [AFHTTPSessionManager manager];

    afMn.responseSerializer = [AFHTTPResponseSerializer serializer];

    [afMn GET:urlStr parameters:nil progress:^(NSProgress *_Nonnull downloadProgress) {

    } success:^(NSURLSessionDataTask * _Nonnull task,id  _Nullable responseObject) {

        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];

        NSDictionary * videoDic = [dic objectForKey:@"msgs"];

        NSDictionary * playUrl = [videoDic objectForKey:@"playurl"];

        if(playUrl && playUrl.count>0)        {

            NSString * domain = [[playUrl objectForKey:@"domain"] firstObject];

            NSDictionary * urlArr = [playUrl objectForKey:@"dispatch"];

            /*for (NSString * key in urlArr) //这个是获取所有的数据 {

            }*/

            //现在只需要获取第一个数据就可以了

            NSString * key = [[urlArr allKeys] firstObject];

            NSString * urlPg = [[urlArr objectForKey:key] firstObject];

            VideoModel * video = [VideoModel new];

            video.videoName = [playUrl objectForKey:@"title"];

            video.videoMilliseconds = [[playUrl objectForKey:@"duration"] integerValue];

            video.videopng = [playUrl objectForKey:@"pic"];

            video.srcUrl = urlStr;

            video.streamType = key;

            NSString * pg =parames;

            NSString * viurl = [[domain stringByAppendingString:urlPg] stringByAppendingString:pg];

            [selfgetVideoUrl:viurl video:video];

        }

        else  {

            self.anLyBlock([NSMutableArray array]);

        }

    } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {

        //失败

        if(self.anLyBlock)

            self.anLyBlock([NSMutableArray array]);

    }];

}

三)获取真正的视频地址

-(void)getVideoUrl:(NSString*)url video:(VideoModel*)video{

    AFHTTPSessionManager * afMn = [AFHTTPSessionManager manager];

    afMn.responseSerializer = [AFHTTPResponseSerializer serializer];

    [afMn GET:url parameters:nil progress:^(NSProgress *_Nonnull downloadProgress) {

    } success:^(NSURLSessionDataTask *_Nonnull task,id  _Nullable responseObject) {

        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];

        NSDictionary * videoDic = [[dic objectForKey:@"nodelist"] firstObject];

        video.videoUrl = [videoDic objectForKey:@"location"];

        [self.videoArr addObject:video];

        __weaktypeof(self) weakSelf =self;

        if(self.anLyBlock)

            self.anLyBlock(weakSelf.videoArr);

    } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {

        if(self.anLyBlock)

            self.anLyBlock([NSMutableArray array]);

    }];

}


如有不合理的地方,请斧正。

申明:这只是自己的一些研究而已,请不要用于商业用途。如果影响到你的利益,请联系我。

你可能感兴趣的:(Ios解析乐视视频地址)