
package com.hustunique.parsingplayer.parser.entity;

import android.support.annotation.NonNull;

import java.util.List;
import java.util.Map;

/**
 * Created by JianGuo on 1/16/17.
 * POJO for video information extracted from websites
 * A list of segs represents a steam
 */
public class VideoInfo {
    public static final int HD_0 = 0;
    public static final int HD_1 = 1;
    public static final int HD_2 = 2;
    public static final int HD_3 = 3;


    // the key is hd
    private Map<Integer, List<Seg>> segsMap;
    private String title;


    public List<Seg> getSegs(@Quality int hd) {
        if (!segsMap.containsKey(hd)) throw new RuntimeException("No such hd in this url");
        return segsMap.get(hd);
    }

    public VideoInfo(@NonNull Map<Integer, List<Seg>> segsMap, @NonNull String title) {
        if (segsMap == null) throw new IllegalArgumentException("SegsMap can't be null");
        if (title == null) throw new IllegalArgumentException("Title can't be null");
        this.segsMap = segsMap;
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    @Override
    public String toString() {
        return "VideoInfo{" +
                "segsMap=" + segsMap +
                ", title='" + title + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o instanceof VideoInfo){
            VideoInfo anotherInfo = (VideoInfo) o;
            return anotherInfo.segsMap.equals(segsMap) && anotherInfo.title.equals(title);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int result = segsMap != null ? segsMap.hashCode() : 0;
        result = 31 * result + title.hashCode();
        return result;
    }
}


@@ -599,18 +599,21 @@
         
-if
+while
  (!segsM
@@ -631,16 +631,75 @@
 Key(hd))
+%7B%0A            hd--;%0A            if (hd %3C 0)%0A               
  throw n
@@ -741,24 +741,34 @@
 this url%22);%0A
+        %7D%0A
         retu

refactor getSegs method