Skip to content

Latest commit

 

History

History
212 lines (170 loc) · 3.99 KB

File metadata and controls

212 lines (170 loc) · 3.99 KB

Documentation of api.py

constants

  • AUTH_COOKIE Authentification Cookie for LMU Cast, importet from keys.py
  • API_ROOT
  • HEADERS all api calls are sending this default headers, including the auth_cookie
  • PLAYLIST_ROOT root of public playlist URLs      

➡️ apicall( endpoint )

Arguments

endpoint Endpoint of API that is to be called, e.g. "/playlists"

Process

Method tries to call API and checks HTTP-Status-Code of response

Return

  • If HTTP-Status-Code is 200, method returns content of response
  • If HTTP-Status-Code is not 200, method prints out error message and quits      

➡️ clean_playlist_item( playlist_item )

Arguments

playlist_item JSON-object as returned by LMU-Cast-API, for example when calling /playlists/<playlist_id>. Note: this function takes a single item only, not a list of playlist-items like returned by /playlists.

Process

  • Method removes all unnecessary values from playlist item.
  • Method adds public url of playlist to item

Return

{
  'id': '', # LMU-Cast id of playlist
  'name': '', # public name of playlist
  'iTunes_author': '', 
  'iTunes_owner_name': '', 
  'export_format_ids': ['online', 'audio_only', 'high_quality'], # MAYBE supported playlist formats ?
  'allowed_format_ids': ['online', 'audio_only', 'high_quality'], # MAYBE formats published ?
  'updated_at': '', 
  'created_at': '', 
  'clips_count': '', # number of videos in playlist 
  'url': '' # public url to playlist
}

     

➡️ get_total_hits_online( total_hits_by_format )

Arguments

total_hits_by_format excerpt of json as returned by API-endpoint /playlist_statistics/<playlist_id>

# API is returning this
{
  'clip': {
    'title': <title_of_video>,
    'id': 0
  },
  
  'total_hits_by_format': [ # we need this element for method
    {
      'format': 'online',
      'total_hits': 215
    },
    {
      'format': 'audio_only',
      'total_hits': 12
    },
    {
      'format': 'high_quality',
      'total_hits': 102
    }
  ],
  
  'daily_hits_by_format': [
    {
      'format': 'online',
      'daily_hits': { ... }
    }
  ]
}

Process & Return

Method finds number of hits for requested format, e.g. online, and returns integer.      

➡️ get_playlist_total_hits( playlist_id )

Arguments

playlist_id Id of playlist in LMU-Cast

Return

{
  '<video_id>': {
      ‘title': '', # title of video in playlist
      ‘hits_online': 123,
      ‘hits_video': 12,
      ‘hits_audio': 3
  }
}

     

get_all_playlist( )

AB HIER ÜBERARBEITEN

Returns all playlists of user logged in.

Request

GET "https://cast.itunes.uni-muenchen.de/api/v1/playlists"

Response

{
  'status': <http_status_code>,
  'content': {
      0: { # = playlist of user
          'id': <playlist_id>,
          'name': <playlist_name>
      },
      ...
  }
}

     

getPlaylistAttributes( playlist_id )

Gets metadata of playlist by playlist id.

Arguments

  • playlist_id LMU-Cast playlist_id

Request

GET "https://cast.itunes.uni-muenchen.de/api/v1/playlists/<playlist_id>"

Response

{
  'status': <http_status_code>,
  'content': {
      'id': <playlist_id>,
      'name': <playlist_name>,
      ... (many more) # uncleaned response of LMU Cast
  }
}

     

getStatisticsByPlaylist( playlist_id )

Returns number of hits by format for each video in playlist.

Arguments

  • playlist_id LMU-Cast playlist_id

Request

GET "https://cast.itunes.uni-muenchen.de/api/v1/playlist_statistics/<playlist_id>"

Response

{
  'status': <http_status_code>,
  'content': {
      0: { # = video in playlist
          'id': <video_id>,
          'name': <video_name>,
          'hits_online': Int,
          'hits_video': Int,
          'hits_audio': Int
      },
      ...
  }
}